diff options
Diffstat (limited to 'db/post_migrate')
68 files changed, 1269 insertions, 10 deletions
diff --git a/db/post_migrate/20220531233600_remove_sse_usage_data_from_redis.rb b/db/post_migrate/20220531233600_remove_sse_usage_data_from_redis.rb index b7b02e483df..26ae9aed5cc 100644 --- a/db/post_migrate/20220531233600_remove_sse_usage_data_from_redis.rb +++ b/db/post_migrate/20220531233600_remove_sse_usage_data_from_redis.rb @@ -3,6 +3,8 @@ class RemoveSseUsageDataFromRedis < Gitlab::Database::Migration[2.0] disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + def up Gitlab::Redis::SharedState.with { |r| r.del("USAGE_STATIC_SITE_EDITOR_VIEWS") } Gitlab::Redis::SharedState.with { |r| r.del("USAGE_STATIC_SITE_EDITOR_COMMITS") } diff --git a/db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb b/db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb index 1e0409b16ea..abd730685d7 100644 --- a/db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb +++ b/db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb @@ -6,10 +6,12 @@ class AddUniqueIndexOnProjectsOnRunnersToken < Gitlab::Database::Migration[2.0] INDEX_NAME = 'index_uniq_projects_on_runners_token' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :projects, :runners_token, name: INDEX_NAME, unique: true + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb b/db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb index b9ba570606e..51b630397dc 100644 --- a/db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb +++ b/db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb @@ -6,10 +6,12 @@ class AddUniqueIndexOnProjectsOnRunnersTokenEncrypted < Gitlab::Database::Migrat INDEX_NAME = 'index_uniq_projects_on_runners_token_encrypted' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :projects, :runners_token_encrypted, name: INDEX_NAME, unique: true + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20220902204048_move_security_findings_table_to_gitlab_partitions_dynamic_schema.rb b/db/post_migrate/20220902204048_move_security_findings_table_to_gitlab_partitions_dynamic_schema.rb index 7b80b6a15bd..62511e0e616 100644 --- a/db/post_migrate/20220902204048_move_security_findings_table_to_gitlab_partitions_dynamic_schema.rb +++ b/db/post_migrate/20220902204048_move_security_findings_table_to_gitlab_partitions_dynamic_schema.rb @@ -147,7 +147,6 @@ class MoveSecurityFindingsTableToGitlabPartitionsDynamicSchema < Gitlab::Databas latest_partition.match(/security_findings_(\d+)/).captures.first end - # rubocop:disable Migration/DropTable (These methods are called from the `down` method) def create_non_partitioned_security_findings_with_data with_lock_retries do lock_tables @@ -227,6 +226,5 @@ class MoveSecurityFindingsTableToGitlabPartitionsDynamicSchema < Gitlab::Databas SQL end end - # rubocop:enable Migration/DropTable end # rubocop:enable Migration/WithLockRetriesDisallowedMethod diff --git a/db/post_migrate/20220920135356_tiebreak_user_type_index.rb b/db/post_migrate/20220920135356_tiebreak_user_type_index.rb index 778a957086f..489196c8eab 100644 --- a/db/post_migrate/20220920135356_tiebreak_user_type_index.rb +++ b/db/post_migrate/20220920135356_tiebreak_user_type_index.rb @@ -7,7 +7,9 @@ class TiebreakUserTypeIndex < Gitlab::Database::Migration[2.0] OLD_INDEX_NAME = 'index_users_on_user_type' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :users, [:user_type, :id], name: NEW_INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation remove_concurrent_index_by_name :users, OLD_INDEX_NAME end diff --git a/db/post_migrate/20221018232820_add_temp_index_for_user_details_fields.rb b/db/post_migrate/20221018232820_add_temp_index_for_user_details_fields.rb index b46b316981d..1cb93886ca3 100644 --- a/db/post_migrate/20221018232820_add_temp_index_for_user_details_fields.rb +++ b/db/post_migrate/20221018232820_add_temp_index_for_user_details_fields.rb @@ -6,6 +6,7 @@ class AddTempIndexForUserDetailsFields < Gitlab::Database::Migration[2.0] disable_ddl_transaction! def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :users, :id, name: INDEX_NAME, where: <<~QUERY (COALESCE(linkedin, '') IS DISTINCT FROM '') OR (COALESCE(twitter, '') IS DISTINCT FROM '') @@ -14,6 +15,7 @@ class AddTempIndexForUserDetailsFields < Gitlab::Database::Migration[2.0] OR (COALESCE(location, '') IS DISTINCT FROM '') OR (COALESCE(organization, '') IS DISTINCT FROM '') QUERY + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20221221150123_update_billable_users_index.rb b/db/post_migrate/20221221150123_update_billable_users_index.rb index d2f55e06b0b..d77669f6a69 100644 --- a/db/post_migrate/20221221150123_update_billable_users_index.rb +++ b/db/post_migrate/20221221150123_update_billable_users_index.rb @@ -16,7 +16,9 @@ class UpdateBillableUsersIndex < Gitlab::Database::Migration[2.1] QUERY def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index(:users, :id, where: NEW_INDEX_CONDITION, name: NEW_INDEX) + # rubocop:enable Migration/PreventIndexCreation remove_concurrent_index_by_name(:users, OLD_INDEX) end diff --git a/db/post_migrate/20230131184319_update_billable_users_index_for_service_accounts.rb b/db/post_migrate/20230131184319_update_billable_users_index_for_service_accounts.rb index e86a2476156..842c7295fcb 100644 --- a/db/post_migrate/20230131184319_update_billable_users_index_for_service_accounts.rb +++ b/db/post_migrate/20230131184319_update_billable_users_index_for_service_accounts.rb @@ -16,7 +16,9 @@ class UpdateBillableUsersIndexForServiceAccounts < Gitlab::Database::Migration[2 QUERY def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index(:users, :id, where: NEW_INDEX_CONDITION, name: NEW_INDEX) + # rubocop:enable Migration/PreventIndexCreation remove_concurrent_index_by_name(:users, OLD_INDEX) end diff --git a/db/post_migrate/20230303154314_add_user_type_migration_indexes.rb b/db/post_migrate/20230303154314_add_user_type_migration_indexes.rb index 8f9e193f0eb..d4f48c1c977 100644 --- a/db/post_migrate/20230303154314_add_user_type_migration_indexes.rb +++ b/db/post_migrate/20230303154314_add_user_type_migration_indexes.rb @@ -6,6 +6,7 @@ class AddUserTypeMigrationIndexes < Gitlab::Database::Migration[2.1] BILLABLE_INDEX = 'index_users_for_active_billable_users_migration' LAST_ACTIVITY_INDEX = 'i_users_on_last_activity_for_active_human_service_migration' + # rubocop:disable Migration/PreventIndexCreation def up # Temporary indexes to migrate human user_type. See https://gitlab.com/gitlab-org/gitlab/-/issues/386474 add_concurrent_index :users, :id, name: BILLABLE_INDEX, @@ -14,6 +15,7 @@ class AddUserTypeMigrationIndexes < Gitlab::Database::Migration[2.1] add_concurrent_index :users, [:id, :last_activity_on], name: LAST_ACTIVITY_INDEX, where: "((state)::text = 'active'::text) AND ((user_type IS NULL OR user_type = 0) OR (user_type = 4))" end + # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name :users, BILLABLE_INDEX diff --git a/db/post_migrate/20230310111859_recreate_user_type_migration_indexes.rb b/db/post_migrate/20230310111859_recreate_user_type_migration_indexes.rb index 539ce99a319..147409bf5f0 100644 --- a/db/post_migrate/20230310111859_recreate_user_type_migration_indexes.rb +++ b/db/post_migrate/20230310111859_recreate_user_type_migration_indexes.rb @@ -8,9 +8,11 @@ class RecreateUserTypeMigrationIndexes < Gitlab::Database::Migration[2.1] def up # Temporary index to migrate human user_type. See https://gitlab.com/gitlab-org/gitlab/-/issues/386474 + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :users, :id, name: BILLABLE_INDEX, where: "state = 'active' AND ((user_type IS NULL OR user_type = 0) OR (user_type = ANY (ARRAY[0, 6, 4, 13]))) " \ "AND ((user_type IS NULL OR user_type = 0) OR (user_type = ANY (ARRAY[0, 4, 5])))" + # rubocop:enable Migration/PreventIndexCreation remove_concurrent_index_by_name :users, INCORRECT_BILLABLE_INDEX end diff --git a/db/post_migrate/20230313150531_reschedule_migration_for_remediation.rb b/db/post_migrate/20230313150531_reschedule_migration_for_remediation.rb index ebb6e53341f..01d5c3a79b0 100644 --- a/db/post_migrate/20230313150531_reschedule_migration_for_remediation.rb +++ b/db/post_migrate/20230313150531_reschedule_migration_for_remediation.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop: disable BackgroundMigration/MissingDictionaryFile +# rubocop: disable BackgroundMigration/DictionaryFile class RescheduleMigrationForRemediation < Gitlab::Database::Migration[2.1] MIGRATION = 'MigrateRemediationsForVulnerabilityFindings' @@ -29,4 +29,4 @@ class RescheduleMigrationForRemediation < Gitlab::Database::Migration[2.1] delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, []) end end -# rubocop: enable BackgroundMigration/MissingDictionaryFile +# rubocop: enable BackgroundMigration/DictionaryFile diff --git a/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb b/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb index 59bff26f964..22ef3381c17 100644 --- a/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb +++ b/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb @@ -3,6 +3,8 @@ class MigrateDailyRedisHllEventsToWeeklyAggregation < Gitlab::Database::Migration[2.1] disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + DAILY_EVENTS = %w[g_edit_by_web_ide g_edit_by_sfe diff --git a/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb b/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb index 17776d8e42e..a4061c3c7c6 100644 --- a/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb +++ b/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb @@ -3,6 +3,8 @@ class ReMigrateRedisSlotKeys < Gitlab::Database::Migration[2.1] disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + KEY_EXPIRY_LENGTH = 6.weeks DAILY_EVENTS = diff --git a/db/post_migrate/20230405200858_requeue_backfill_project_wiki_repositories.rb b/db/post_migrate/20230405200858_requeue_backfill_project_wiki_repositories.rb index 363a3099064..6c4792d0d6c 100644 --- a/db/post_migrate/20230405200858_requeue_backfill_project_wiki_repositories.rb +++ b/db/post_migrate/20230405200858_requeue_backfill_project_wiki_repositories.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop:disable BackgroundMigration/MissingDictionaryFile +# rubocop:disable BackgroundMigration/DictionaryFile class RequeueBackfillProjectWikiRepositories < Gitlab::Database::Migration[2.1] MIGRATION = "BackfillProjectWikiRepositories" DELAY_INTERVAL = 2.minutes @@ -26,4 +26,4 @@ class RequeueBackfillProjectWikiRepositories < Gitlab::Database::Migration[2.1] delete_batched_background_migration(MIGRATION, :projects, :id, []) end end -# rubocop:enable BackgroundMigration/MissingDictionaryFile +# rubocop:enable BackgroundMigration/DictionaryFile diff --git a/db/post_migrate/20230508150219_reschedule_evidences_handling_unicode.rb b/db/post_migrate/20230508150219_reschedule_evidences_handling_unicode.rb index 804db553f6f..ed23df4405e 100644 --- a/db/post_migrate/20230508150219_reschedule_evidences_handling_unicode.rb +++ b/db/post_migrate/20230508150219_reschedule_evidences_handling_unicode.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop:disable BackgroundMigration/MissingDictionaryFile +# rubocop:disable BackgroundMigration/DictionaryFile class RescheduleEvidencesHandlingUnicode < Gitlab::Database::Migration[2.1] restrict_gitlab_migration gitlab_schema: :gitlab_main @@ -29,4 +29,4 @@ class RescheduleEvidencesHandlingUnicode < Gitlab::Database::Migration[2.1] delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, []) end end -# rubocop:enable BackgroundMigration/MissingDictionaryFile +# rubocop:enable BackgroundMigration/DictionaryFile diff --git a/db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb b/db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb index d351d795ddf..f49b158593f 100644 --- a/db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb +++ b/db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop: disable BackgroundMigration/MissingDictionaryFile +# rubocop: disable BackgroundMigration/DictionaryFile class RescheduleMigrationForLinksFromMetadata < Gitlab::Database::Migration[2.1] MIGRATION = 'MigrateLinksForVulnerabilityFindings' @@ -29,4 +29,4 @@ class RescheduleMigrationForLinksFromMetadata < Gitlab::Database::Migration[2.1] delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, []) end end -# rubocop: enable BackgroundMigration/MissingDictionaryFile +# rubocop: enable BackgroundMigration/DictionaryFile diff --git a/db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb b/db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb index 5b9b4e36512..e299ce394a3 100644 --- a/db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb +++ b/db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb @@ -7,9 +7,11 @@ class ChangeUnconfirmedCreatedAtIndexOnUsers < Gitlab::Database::Migration[2.1] NEW_INDEX_NAME = 'index_users_on_unconfirmed_created_at_active_type_sign_in_count' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :users, [:created_at, :id], name: NEW_INDEX_NAME, where: "confirmed_at IS NULL AND state = 'active' AND user_type IN (0) AND sign_in_count = 0" + # rubocop:enable Migration/PreventIndexCreation remove_concurrent_index_by_name :users, OLD_INDEX_NAME end diff --git a/db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb b/db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb index b066cb248fb..fd2387e2bc4 100644 --- a/db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb +++ b/db/post_migrate/20230724150939_index_projects_on_namespace_id_and_repository_size_limit.rb @@ -9,7 +9,9 @@ class IndexProjectsOnNamespaceIdAndRepositorySizeLimit < Gitlab::Database::Migra disable_ddl_transaction! def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :projects, [:namespace_id, :repository_size_limit], name: INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20230728151058_add_auditor_index_to_users_table.rb b/db/post_migrate/20230728151058_add_auditor_index_to_users_table.rb index 1a849e7b728..055174b9e32 100644 --- a/db/post_migrate/20230728151058_add_auditor_index_to_users_table.rb +++ b/db/post_migrate/20230728151058_add_auditor_index_to_users_table.rb @@ -5,7 +5,9 @@ class AddAuditorIndexToUsersTable < Gitlab::Database::Migration[2.1] disable_ddl_transaction! def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :users, :id, where: 'auditor IS true', name: INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20230913130629_index_org_id_on_projects.rb b/db/post_migrate/20230913130629_index_org_id_on_projects.rb index 45186b900c6..c4d3de6c172 100644 --- a/db/post_migrate/20230913130629_index_org_id_on_projects.rb +++ b/db/post_migrate/20230913130629_index_org_id_on_projects.rb @@ -6,7 +6,9 @@ class IndexOrgIdOnProjects < Gitlab::Database::Migration[2.1] INDEX_NAME = 'index_projects_on_organization_id' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :projects, :organization_id, name: INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20231003045342_migrate_sidekiq_namespaced_jobs.rb b/db/post_migrate/20231003045342_migrate_sidekiq_namespaced_jobs.rb new file mode 100644 index 00000000000..7d4d6876848 --- /dev/null +++ b/db/post_migrate/20231003045342_migrate_sidekiq_namespaced_jobs.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +class MigrateSidekiqNamespacedJobs < Gitlab::Database::Migration[2.1] + BATCH_SIZE = 1000 + SORTED_SET_NAMES = %w[schedule retry dead] + + def up + SORTED_SET_NAMES.each do |set_name| + sorted_set_migrate("resque:gitlab:#{set_name}", set_name) + end + + Sidekiq::Queue.all.each do |queue| + name = queue.name + sidekiq_queue_migrate("resque:gitlab:queue:#{name}", to: "queue:#{name}") + end + end + + def down + SORTED_SET_NAMES.each do |set_name| + sorted_set_migrate(set_name, "resque:gitlab:#{set_name}") + end + + Sidekiq::Queue.all.each do |queue| + name = queue.name + sidekiq_queue_migrate("queue:#{name}", to: "resque:gitlab:queue:#{name}") + end + end + + private + + def sidekiq_queue_migrate(queue_from, to:) + Gitlab::Redis::Queues.with do |conn| # rubocop:disable Cop/RedisQueueUsage + conn.rpoplpush(queue_from, to) while conn.llen(queue_from) > 0 + end + end + + def sorted_set_migrate(from, to) + cursor = '0' + + loop do + result = [] + + Gitlab::Redis::Queues.with do |redis| # rubocop:disable Cop/RedisQueueUsage + cursor, result = redis.zscan(from, cursor, count: BATCH_SIZE) + + next if result.empty? + + redis.multi do |multi| + multi.zadd(to, result.map { |k, v| [v, k] }) + multi.zrem(from, result.map { |k, _v| k }) + end + end + + sleep(0.01) + + break if cursor == '0' + end + end +end diff --git a/db/post_migrate/20231003142534_add_build_timeout_index.rb b/db/post_migrate/20231003142534_add_build_timeout_index.rb index 3a95c7cf748..5820a35eb8d 100644 --- a/db/post_migrate/20231003142534_add_build_timeout_index.rb +++ b/db/post_migrate/20231003142534_add_build_timeout_index.rb @@ -6,7 +6,9 @@ class AddBuildTimeoutIndex < Gitlab::Database::Migration[2.1] INDEX_NAME = 'index_projects_on_id_where_build_timeout_geq_than_2629746' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :projects, :id, where: 'build_timeout >= 2629746', name: INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20231009105056_index_users_on_email_domain_and_id.rb b/db/post_migrate/20231009105056_index_users_on_email_domain_and_id.rb index e6b750ca38b..61aab7cc2c4 100644 --- a/db/post_migrate/20231009105056_index_users_on_email_domain_and_id.rb +++ b/db/post_migrate/20231009105056_index_users_on_email_domain_and_id.rb @@ -6,7 +6,9 @@ class IndexUsersOnEmailDomainAndId < Gitlab::Database::Migration[2.1] INDEX_NAME = 'index_users_on_email_domain_and_id' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index(:users, "lower(split_part(email, '@', 2)), id", name: INDEX_NAME) + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20231016001000_fix_design_user_mentions_design_id_note_id_index_for_self_managed.rb b/db/post_migrate/20231016001000_fix_design_user_mentions_design_id_note_id_index_for_self_managed.rb new file mode 100644 index 00000000000..454158ecbee --- /dev/null +++ b/db/post_migrate/20231016001000_fix_design_user_mentions_design_id_note_id_index_for_self_managed.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class FixDesignUserMentionsDesignIdNoteIdIndexForSelfManaged < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::ConvertToBigint + + disable_ddl_transaction! + + TABLE_NAME = 'design_user_mentions' + INDEX_NAME = 'design_user_mentions_on_design_id_and_note_id_unique_index' + + def up + return if com_or_dev_or_test_but_not_jh? + return if index_exists?(TABLE_NAME, [:design_id, :note_id], unique: true, name: INDEX_NAME) + + add_concurrent_index TABLE_NAME, [:design_id, :note_id], unique: true, name: "#{INDEX_NAME}_int8" + + with_lock_retries(raise_on_exhaustion: true) do + execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" + + execute "DROP INDEX IF EXISTS #{INDEX_NAME}" + rename_index TABLE_NAME, "#{INDEX_NAME}_int8", INDEX_NAME + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20231016173128_add_temporary_index_to_merge_access_levels.rb b/db/post_migrate/20231016173128_add_temporary_index_to_merge_access_levels.rb new file mode 100644 index 00000000000..0d8fbdfea00 --- /dev/null +++ b/db/post_migrate/20231016173128_add_temporary_index_to_merge_access_levels.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddTemporaryIndexToMergeAccessLevels < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.6' + + INDEX_NAME = 'tmp_idx_protected_branch_merge_access_levels_on_id_with_group' + + def up + # Temporary index to be removed in 16.7 https://gitlab.com/gitlab-org/gitlab/-/issues/430843 + add_concurrent_index( + :protected_branch_merge_access_levels, + %i[id], + where: 'group_id IS NOT NULL', + name: INDEX_NAME + ) + end + + def down + remove_concurrent_index_by_name( + :protected_branch_merge_access_levels, + INDEX_NAME + ) + end +end diff --git a/db/post_migrate/20231016173129_queue_delete_invalid_protected_branch_merge_access_levels.rb b/db/post_migrate/20231016173129_queue_delete_invalid_protected_branch_merge_access_levels.rb new file mode 100644 index 00000000000..3f4009d783c --- /dev/null +++ b/db/post_migrate/20231016173129_queue_delete_invalid_protected_branch_merge_access_levels.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class QueueDeleteInvalidProtectedBranchMergeAccessLevels < Gitlab::Database::Migration[2.1] + MIGRATION = "DeleteInvalidProtectedBranchMergeAccessLevels" + DELAY_INTERVAL = 2.minutes + MAX_BATCH_SIZE = 10_000 + BATCH_SIZE = 5_000 + SUB_BATCH_SIZE = 500 + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + queue_batched_background_migration( + MIGRATION, + :protected_branch_merge_access_levels, + :id, + job_interval: DELAY_INTERVAL, + queued_migration_version: '20231016173129', + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :protected_branch_merge_access_levels, :id, []) + end +end diff --git a/db/post_migrate/20231016194926_add_temporary_index_to_push_access_levels.rb b/db/post_migrate/20231016194926_add_temporary_index_to_push_access_levels.rb new file mode 100644 index 00000000000..91599051fd4 --- /dev/null +++ b/db/post_migrate/20231016194926_add_temporary_index_to_push_access_levels.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddTemporaryIndexToPushAccessLevels < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.6' + INDEX_NAME = 'tmp_idx_protected_branch_push_access_levels_on_id_with_group' + + def up + # Temporary index to be removed in 16.7 https://gitlab.com/gitlab-org/gitlab/-/issues/430843 + add_concurrent_index( + :protected_branch_push_access_levels, + %i[id], + where: 'group_id IS NOT NULL', + name: INDEX_NAME + ) + end + + def down + remove_concurrent_index_by_name( + :protected_branch_push_access_levels, + INDEX_NAME + ) + end +end diff --git a/db/post_migrate/20231016194927_queue_delete_invalid_protected_branch_push_access_levels.rb b/db/post_migrate/20231016194927_queue_delete_invalid_protected_branch_push_access_levels.rb new file mode 100644 index 00000000000..6accaa3296b --- /dev/null +++ b/db/post_migrate/20231016194927_queue_delete_invalid_protected_branch_push_access_levels.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class QueueDeleteInvalidProtectedBranchPushAccessLevels < Gitlab::Database::Migration[2.1] + MIGRATION = "DeleteInvalidProtectedBranchPushAccessLevels" + DELAY_INTERVAL = 2.minutes + MAX_BATCH_SIZE = 10_000 + BATCH_SIZE = 5_000 + SUB_BATCH_SIZE = 500 + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + queue_batched_background_migration( + MIGRATION, + :protected_branch_push_access_levels, + :id, + job_interval: DELAY_INTERVAL, + queued_migration_version: '20231016194927', + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :protected_branch_push_access_levels, :id, []) + end +end diff --git a/db/post_migrate/20231016194942_add_temporary_index_to_create_access_levels.rb b/db/post_migrate/20231016194942_add_temporary_index_to_create_access_levels.rb new file mode 100644 index 00000000000..d28b664c517 --- /dev/null +++ b/db/post_migrate/20231016194942_add_temporary_index_to_create_access_levels.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddTemporaryIndexToCreateAccessLevels < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.6' + + INDEX_NAME = 'tmp_idx_protected_tag_create_access_levels_on_id_with_group' + + def up + # Temporary index to be removed in 16.7 https://gitlab.com/gitlab-org/gitlab/-/issues/430843 + add_concurrent_index( + :protected_tag_create_access_levels, + %i[id], + where: 'group_id IS NOT NULL', + name: INDEX_NAME + ) + end + + def down + remove_concurrent_index_by_name( + :protected_tag_create_access_levels, + INDEX_NAME + ) + end +end diff --git a/db/post_migrate/20231016194943_queue_delete_invalid_protected_tag_create_access_levels.rb b/db/post_migrate/20231016194943_queue_delete_invalid_protected_tag_create_access_levels.rb new file mode 100644 index 00000000000..5880124d0a6 --- /dev/null +++ b/db/post_migrate/20231016194943_queue_delete_invalid_protected_tag_create_access_levels.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class QueueDeleteInvalidProtectedTagCreateAccessLevels < Gitlab::Database::Migration[2.1] + MIGRATION = "DeleteInvalidProtectedTagCreateAccessLevels" + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 10_000 + SUB_BATCH_SIZE = 500 + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + queue_batched_background_migration( + MIGRATION, + :protected_tag_create_access_levels, + :id, + job_interval: DELAY_INTERVAL, + queued_migration_version: '20231016194943', + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :protected_tag_create_access_levels, :id, []) + end +end diff --git a/db/post_migrate/20231017172156_add_index_on_projects_for_adjourned_deletion.rb b/db/post_migrate/20231017172156_add_index_on_projects_for_adjourned_deletion.rb index 6a689a5e11a..9b73035471e 100644 --- a/db/post_migrate/20231017172156_add_index_on_projects_for_adjourned_deletion.rb +++ b/db/post_migrate/20231017172156_add_index_on_projects_for_adjourned_deletion.rb @@ -6,10 +6,12 @@ class AddIndexOnProjectsForAdjournedDeletion < Gitlab::Database::Migration[2.1] INDEX_NAME = 'index_projects_id_for_aimed_for_deletion' def up + # rubocop:disable Migration/PreventIndexCreation add_concurrent_index :projects, [:id, :marked_for_deletion_at], where: 'marked_for_deletion_at IS NOT NULL AND pending_delete = false', name: INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20231018083247_remove_users_email_opted_in_columns.rb b/db/post_migrate/20231018083247_remove_users_email_opted_in_columns.rb new file mode 100644 index 00000000000..a77ccb599df --- /dev/null +++ b/db/post_migrate/20231018083247_remove_users_email_opted_in_columns.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class RemoveUsersEmailOptedInColumns < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def up + remove_column :users, :email_opted_in + remove_column :users, :email_opted_in_ip + remove_column :users, :email_opted_in_source_id + remove_column :users, :email_opted_in_at + end + + # This migration removes columns. Disabling rule only for rollback action + # rubocop:disable Migration/AddColumnsToWideTables + def down + add_column :users, :email_opted_in, :boolean + add_column :users, :email_opted_in_ip, :string + add_column :users, :email_opted_in_source_id, :integer + add_column :users, :email_opted_in_at, :datetime_with_timezone + end + # rubocop:enable Migration/AddColumnsToWideTables +end diff --git a/db/post_migrate/20231018093625_drop_index_namespaces_on_shared_and_extra_runners_minutes_limit.rb b/db/post_migrate/20231018093625_drop_index_namespaces_on_shared_and_extra_runners_minutes_limit.rb new file mode 100644 index 00000000000..9b293b066d6 --- /dev/null +++ b/db/post_migrate/20231018093625_drop_index_namespaces_on_shared_and_extra_runners_minutes_limit.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropIndexNamespacesOnSharedAndExtraRunnersMinutesLimit < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLE_NAME = :namespaces + INDEX_NAME = :index_namespaces_on_shared_and_extra_runners_minutes_limit + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + # no-op + # Since adding the same index will be time consuming, + # we have to create it asynchronously using 'prepare_async_index' helper (if needed). + end +end diff --git a/db/post_migrate/20231018105749_remove_application_settings_marketing_emails_enabled_column.rb b/db/post_migrate/20231018105749_remove_application_settings_marketing_emails_enabled_column.rb new file mode 100644 index 00000000000..ea7ef21f110 --- /dev/null +++ b/db/post_migrate/20231018105749_remove_application_settings_marketing_emails_enabled_column.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemoveApplicationSettingsMarketingEmailsEnabledColumn < Gitlab::Database::Migration[2.1] + def up + remove_column :application_settings, :in_product_marketing_emails_enabled + end + + def down + add_column :application_settings, :in_product_marketing_emails_enabled, :boolean, default: true, null: false + end +end diff --git a/db/post_migrate/20231019003052_swap_columns_for_ci_pipelines_pipeline_id_bigint_v2.rb b/db/post_migrate/20231019003052_swap_columns_for_ci_pipelines_pipeline_id_bigint_v2.rb new file mode 100644 index 00000000000..4065bad5fb5 --- /dev/null +++ b/db/post_migrate/20231019003052_swap_columns_for_ci_pipelines_pipeline_id_bigint_v2.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +class SwapColumnsForCiPipelinesPipelineIdBigintV2 < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum + include Gitlab::Database::MigrationHelpers::Swapping + + disable_ddl_transaction! + + TABLE_NAME = :ci_pipelines + TRIGGER_FUNCTION_NAME = :trigger_1bd97da9c1a4 + COLUMN_NAME = :auto_canceled_by_id + BIGINT_COLUMN_NAME = :auto_canceled_by_id_convert_to_bigint + FK_NAME = :fk_262d4c2d19 + BIGINT_FK_NAME = :fk_67e4288f3a + INDEX_NAME = :index_ci_pipelines_on_auto_canceled_by_id + BIGINT_INDEX_NAME = :index_ci_pipelines_on_auto_canceled_by_id_bigint + + def up + return if should_skip? || column_type_of?(:bigint) + + swap + end + + def down + return if should_skip? || column_type_of?(:integer) + + swap + end + + private + + def should_skip? + !can_execute_on?(TABLE_NAME) + end + + def column_type_of?(type) + column_for(TABLE_NAME, COLUMN_NAME).sql_type.to_s == type.to_s + end + + def swap + # rubocop:disable Migration/WithLockRetriesDisallowedMethod + with_lock_retries(raise_on_exhaustion: true) do + # Lock the tables involved. + lock_tables(TABLE_NAME) + + # Rename the columns to swap names + swap_columns(TABLE_NAME, COLUMN_NAME, BIGINT_COLUMN_NAME) + + # Reset the trigger function + reset_trigger_function(TRIGGER_FUNCTION_NAME) + + # Swap fkey constraint + swap_foreign_keys(TABLE_NAME, FK_NAME, BIGINT_FK_NAME) + + # Swap index + swap_indexes(TABLE_NAME, INDEX_NAME, BIGINT_INDEX_NAME) + end + # rubocop:enable Migration/WithLockRetriesDisallowedMethod + end +end diff --git a/db/post_migrate/20231019084731_swap_columns_for_ci_stages_pipeline_id_bigint_v2.rb b/db/post_migrate/20231019084731_swap_columns_for_ci_stages_pipeline_id_bigint_v2.rb new file mode 100644 index 00000000000..d64d2ea737d --- /dev/null +++ b/db/post_migrate/20231019084731_swap_columns_for_ci_stages_pipeline_id_bigint_v2.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +class SwapColumnsForCiStagesPipelineIdBigintV2 < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum + include Gitlab::Database::MigrationHelpers::Swapping + + disable_ddl_transaction! + + TABLE_NAME = :ci_stages + TRIGGER_FUNCTION_NAME = :trigger_07bc3c48f407 + COLUMN_NAME = :pipeline_id + BIGINT_COLUMN_NAME = :pipeline_id_convert_to_bigint + FK_NAME = :fk_fb57e6cc56 + BIGINT_FK_NAME = :fk_c5ddde695f + INDEX_NAMES = %i[ + index_ci_stages_on_pipeline_id + index_ci_stages_on_pipeline_id_and_id + index_ci_stages_on_pipeline_id_and_name + index_ci_stages_on_pipeline_id_and_position + ] + BIGINT_INDEX_NAMES = %i[ + index_ci_stages_on_pipeline_id_convert_to_bigint + index_ci_stages_on_pipeline_id_convert_to_bigint_and_id + index_ci_stages_on_pipeline_id_convert_to_bigint_and_name + index_ci_stages_on_pipeline_id_convert_to_bigint_and_position + ] + + def up + return if should_skip? || column_type_of?(:bigint) + + swap + end + + def down + return if should_skip? || column_type_of?(:integer) + + swap + end + + private + + def should_skip? + !can_execute_on?(:ci_pipelines, :ci_stages) + end + + def column_type_of?(type) + column_for(TABLE_NAME, COLUMN_NAME).sql_type.to_s == type.to_s + end + + def swap + # rubocop:disable Migration/WithLockRetriesDisallowedMethod + with_lock_retries(raise_on_exhaustion: true) do + # Lock the tables involved. + lock_tables(:ci_pipelines, :ci_stages) + + # Rename the columns to swap names + swap_columns(TABLE_NAME, COLUMN_NAME, BIGINT_COLUMN_NAME) + + # Reset the trigger function + reset_trigger_function(TRIGGER_FUNCTION_NAME) + + # Swap fkey constraint + swap_foreign_keys(TABLE_NAME, FK_NAME, BIGINT_FK_NAME) + + # Swap index + INDEX_NAMES.each_with_index do |index_name, i| + swap_indexes(TABLE_NAME, index_name, BIGINT_INDEX_NAMES[i]) + end + end + # rubocop:enable Migration/WithLockRetriesDisallowedMethod + end +end diff --git a/db/post_migrate/20231019223224_backfill_catalog_resources_name_and_description.rb b/db/post_migrate/20231019223224_backfill_catalog_resources_name_and_description.rb new file mode 100644 index 00000000000..fd5db7621e3 --- /dev/null +++ b/db/post_migrate/20231019223224_backfill_catalog_resources_name_and_description.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class BackfillCatalogResourcesNameAndDescription < Gitlab::Database::Migration[2.1] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + sql = <<-SQL + UPDATE catalog_resources + SET name = projects.name, + description = projects.description + FROM projects + WHERE catalog_resources.project_id = projects.id + SQL + + execute(sql) + end + + def down + # no-op + + # The `name` and `description` columns in `catalog_resources` are denormalized; + # they should always stay in sync with the corresponding data in `projects`. + end +end diff --git a/db/post_migrate/20231020082425_remove_force_full_reconciliation_from_workspaces.rb b/db/post_migrate/20231020082425_remove_force_full_reconciliation_from_workspaces.rb new file mode 100644 index 00000000000..85283183323 --- /dev/null +++ b/db/post_migrate/20231020082425_remove_force_full_reconciliation_from_workspaces.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class RemoveForceFullReconciliationFromWorkspaces < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def change + remove_column :workspaces, :force_full_reconciliation, :boolean, default: false, null: false + end +end diff --git a/db/post_migrate/20231020150211_delete_duplicated_index_scan_result_policies_on_policy_configuration_id.rb b/db/post_migrate/20231020150211_delete_duplicated_index_scan_result_policies_on_policy_configuration_id.rb new file mode 100644 index 00000000000..8df7a7d5194 --- /dev/null +++ b/db/post_migrate/20231020150211_delete_duplicated_index_scan_result_policies_on_policy_configuration_id.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class DeleteDuplicatedIndexScanResultPoliciesOnPolicyConfigurationId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = 'index_scan_result_policies_on_policy_configuration_id' + COLUMNS = %i[security_orchestration_policy_configuration_id] + + def up + remove_concurrent_index_by_name :scan_result_policies, INDEX_NAME + end + + def down + add_concurrent_index :scan_result_policies, COLUMNS, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20231023083349_init_conversion_for_p_ci_builds.rb b/db/post_migrate/20231023083349_init_conversion_for_p_ci_builds.rb new file mode 100644 index 00000000000..886e8c85599 --- /dev/null +++ b/db/post_migrate/20231023083349_init_conversion_for_p_ci_builds.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class InitConversionForPCiBuilds < Gitlab::Database::Migration[2.1] + include ::Gitlab::Database::MigrationHelpers::WraparoundAutovacuum + + disable_ddl_transaction! + + TABLE_NAME = :p_ci_builds + COLUMN_NAMES = %i[ + auto_canceled_by_id + commit_id + erased_by_id + project_id + runner_id + trigger_request_id + upstream_pipeline_id + user_id + ] + + def up + return if should_skip? + + initialize_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES) + end + + def down + return if should_skip? + + revert_initialize_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES) + end + + private + + def should_skip? + !can_execute_on?(TABLE_NAME) + end +end diff --git a/db/post_migrate/20231023113908_add_index_stopping_environments_on_updated_at.rb b/db/post_migrate/20231023113908_add_index_stopping_environments_on_updated_at.rb new file mode 100644 index 00000000000..01fe32d6bd7 --- /dev/null +++ b/db/post_migrate/20231023113908_add_index_stopping_environments_on_updated_at.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddIndexStoppingEnvironmentsOnUpdatedAt < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'index_environments_on_updated_at_for_stopping_state' + + disable_ddl_transaction! + + def up + add_concurrent_index :environments, :updated_at, where: "state = 'stopping'", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :environments, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20231023164908_async_drop_index_users_on_accepted_term_id.rb b/db/post_migrate/20231023164908_async_drop_index_users_on_accepted_term_id.rb new file mode 100644 index 00000000000..a5688a9b196 --- /dev/null +++ b/db/post_migrate/20231023164908_async_drop_index_users_on_accepted_term_id.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AsyncDropIndexUsersOnAcceptedTermId < Gitlab::Database::Migration[2.2] + milestone '16.6' + disable_ddl_transaction! + + TABLE_NAME = 'users' + INDEX_NAME = 'index_users_on_accepted_term_id' + COLUMN = 'accepted_term_id' + + # TODO: Index to be destroyed synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/135293 + def up + prepare_async_index_removal TABLE_NAME, COLUMN, name: INDEX_NAME + end + + def down + prepare_async_index_removal TABLE_NAME, COLUMN, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20231024015915_drop_index_namespaces_on_created_at_for_gitlab_com.rb b/db/post_migrate/20231024015915_drop_index_namespaces_on_created_at_for_gitlab_com.rb new file mode 100644 index 00000000000..8f2f8a4064c --- /dev/null +++ b/db/post_migrate/20231024015915_drop_index_namespaces_on_created_at_for_gitlab_com.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class DropIndexNamespacesOnCreatedAtForGitlabCom < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLE_NAME = :namespaces + INDEX_NAME = :index_namespaces_on_created_at + + def up + return unless should_run? + + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + return unless should_run? + + add_concurrent_index TABLE_NAME, :created_at, name: INDEX_NAME + end + + def should_run? + Gitlab.com_except_jh? + end +end diff --git a/db/post_migrate/20231024025457_cleanup_bigint_conversion_for_ci_project_monthly_usages_shared_runners_duration.rb b/db/post_migrate/20231024025457_cleanup_bigint_conversion_for_ci_project_monthly_usages_shared_runners_duration.rb new file mode 100644 index 00000000000..9528c00a1fd --- /dev/null +++ b/db/post_migrate/20231024025457_cleanup_bigint_conversion_for_ci_project_monthly_usages_shared_runners_duration.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class CleanupBigintConversionForCiProjectMonthlyUsagesSharedRunnersDuration < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + TABLE = :ci_project_monthly_usages + COLUMNS = [:shared_runners_duration] + + def up + cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + restore_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20231024025533_cleanup_bigint_conversion_for_ci_namespace_monthly_usages_shared_runners_duration.rb b/db/post_migrate/20231024025533_cleanup_bigint_conversion_for_ci_namespace_monthly_usages_shared_runners_duration.rb new file mode 100644 index 00000000000..792650130cd --- /dev/null +++ b/db/post_migrate/20231024025533_cleanup_bigint_conversion_for_ci_namespace_monthly_usages_shared_runners_duration.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class CleanupBigintConversionForCiNamespaceMonthlyUsagesSharedRunnersDuration < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + TABLE = :ci_namespace_monthly_usages + COLUMNS = [:shared_runners_duration] + + def up + cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + restore_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20231024025629_cleanup_ci_pipeline_chat_data_pipeline_id_bigint.rb b/db/post_migrate/20231024025629_cleanup_ci_pipeline_chat_data_pipeline_id_bigint.rb new file mode 100644 index 00000000000..e79f4eb43b7 --- /dev/null +++ b/db/post_migrate/20231024025629_cleanup_ci_pipeline_chat_data_pipeline_id_bigint.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class CleanupCiPipelineChatDataPipelineIdBigint < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLE = :ci_pipeline_chat_data + COLUMNS = [:pipeline_id] + + def up + with_lock_retries(raise_on_exhaustion: true) do + cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) # rubocop:disable Migration/WithLockRetriesDisallowedMethod + end + end + + def down + restore_conversion_of_integer_to_bigint(TABLE, COLUMNS) + + add_concurrent_index( + TABLE, :pipeline_id_convert_to_bigint, + name: :index_ci_pipeline_chat_data_on_pipeline_id_convert_to_bigint, + unique: true + ) + add_concurrent_foreign_key( + TABLE, :ci_pipelines, + column: :pipeline_id_convert_to_bigint, + on_delete: :cascade, validate: true, reverse_lock_order: true + ) + end +end diff --git a/db/post_migrate/20231024080150_cleanup_ci_sources_pipelines_pipeline_id_bigint.rb b/db/post_migrate/20231024080150_cleanup_ci_sources_pipelines_pipeline_id_bigint.rb new file mode 100644 index 00000000000..6aa8019a182 --- /dev/null +++ b/db/post_migrate/20231024080150_cleanup_ci_sources_pipelines_pipeline_id_bigint.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class CleanupCiSourcesPipelinesPipelineIdBigint < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLE = :ci_sources_pipelines + REFERENCING_TABLE = :ci_pipelines + COLUMNS = [:pipeline_id, :source_pipeline_id] + + def up + with_lock_retries(raise_on_exhaustion: true) do + lock_tables(:ci_pipelines, TABLE) + cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) # rubocop:disable Migration/WithLockRetriesDisallowedMethod + end + end + + def down + restore_conversion_of_integer_to_bigint(TABLE, COLUMNS) + + add_concurrent_index(TABLE, :pipeline_id_convert_to_bigint, + name: :index_ci_sources_pipelines_on_pipeline_id_bigint) + add_concurrent_index(TABLE, :source_pipeline_id_convert_to_bigint, + name: :index_ci_sources_pipelines_on_source_pipeline_id_bigint) + add_concurrent_foreign_key( + TABLE, REFERENCING_TABLE, + column: :pipeline_id_convert_to_bigint, + on_delete: :cascade, validate: true, reverse_lock_order: true + ) + add_concurrent_foreign_key( + TABLE, REFERENCING_TABLE, + column: :source_pipeline_id_convert_to_bigint, + on_delete: :cascade, validate: true, reverse_lock_order: true + ) + end +end diff --git a/db/post_migrate/20231024124856_remove_redundant_group_stages_index.rb b/db/post_migrate/20231024124856_remove_redundant_group_stages_index.rb new file mode 100644 index 00000000000..d9546597bd9 --- /dev/null +++ b/db/post_migrate/20231024124856_remove_redundant_group_stages_index.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveRedundantGroupStagesIndex < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.6' + + INDEX_NAME = 'index_analytics_ca_group_stages_on_group_id' + + def up + remove_concurrent_index_by_name(:analytics_cycle_analytics_group_stages, INDEX_NAME) + end + + def down + add_concurrent_index(:analytics_cycle_analytics_group_stages, :group_id, name: INDEX_NAME) + end +end diff --git a/db/post_migrate/20231024125551_remove_redundant_mr_metrics_index_on_target_project_id.rb b/db/post_migrate/20231024125551_remove_redundant_mr_metrics_index_on_target_project_id.rb new file mode 100644 index 00000000000..2186402828d --- /dev/null +++ b/db/post_migrate/20231024125551_remove_redundant_mr_metrics_index_on_target_project_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveRedundantMrMetricsIndexOnTargetProjectId < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.6' + + INDEX_NAME = 'index_merge_request_metrics_on_target_project_id' + + def up + remove_concurrent_index_by_name(:merge_request_metrics, INDEX_NAME) + end + + def down + add_concurrent_index(:merge_request_metrics, :target_project_id, name: INDEX_NAME) + end +end diff --git a/db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb b/db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb new file mode 100644 index 00000000000..a960258ff3d --- /dev/null +++ b/db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +class SwapColumnsForCiPipelinesPipelineIdBigintForSelfHost < Gitlab::Database::Migration[2.2] + include Gitlab::Database::MigrationHelpers::Swapping + + milestone '16.6' + disable_ddl_transaction! + + TABLE_NAME = :ci_pipelines + TRIGGER_FUNCTION_NAME = :trigger_1bd97da9c1a4 + COLUMN_NAME = :auto_canceled_by_id + BIGINT_COLUMN_NAME = :auto_canceled_by_id_convert_to_bigint + FK_NAME = :fk_262d4c2d19 + BIGINT_FK_NAME = :fk_67e4288f3a + INDEX_NAME = :index_ci_pipelines_on_auto_canceled_by_id + BIGINT_INDEX_NAME = :index_ci_pipelines_on_auto_canceled_by_id_bigint + + def up + return if column_type_of?(:bigint) + + swap + end + + def down + return if column_type_of?(:integer) + + swap + end + + private + + def column_type_of?(type) + column_for(TABLE_NAME, COLUMN_NAME).sql_type.to_s == type.to_s + end + + def swap + with_lock_retries(raise_on_exhaustion: true) do + # Lock the tables involved. + lock_tables(TABLE_NAME) + + # Rename the columns to swap names + swap_columns(TABLE_NAME, COLUMN_NAME, BIGINT_COLUMN_NAME) + + # Reset the trigger function + reset_trigger_function(TRIGGER_FUNCTION_NAME) + + # Swap fkey constraint + swap_foreign_keys(TABLE_NAME, FK_NAME, BIGINT_FK_NAME) + + # Swap index + swap_indexes(TABLE_NAME, INDEX_NAME, BIGINT_INDEX_NAME) + end + end +end diff --git a/db/post_migrate/20231025031337_cleanup_ci_pipeline_messages_pipeline_id_bigint.rb b/db/post_migrate/20231025031337_cleanup_ci_pipeline_messages_pipeline_id_bigint.rb new file mode 100644 index 00000000000..b9e44f8f2d0 --- /dev/null +++ b/db/post_migrate/20231025031337_cleanup_ci_pipeline_messages_pipeline_id_bigint.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class CleanupCiPipelineMessagesPipelineIdBigint < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLE = :ci_pipeline_messages + COLUMNS = [:pipeline_id] + + def up + with_lock_retries(raise_on_exhaustion: true) do + lock_tables(:ci_pipelines, TABLE) + cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) # rubocop:disable Migration/WithLockRetriesDisallowedMethod + end + end + + def down + restore_conversion_of_integer_to_bigint(TABLE, COLUMNS) + + add_concurrent_index( + TABLE, :pipeline_id_convert_to_bigint, + name: :index_ci_pipeline_messages_on_pipeline_id_convert_to_bigint + ) + add_concurrent_foreign_key( + TABLE, :ci_pipelines, + column: :pipeline_id_convert_to_bigint, + on_delete: :cascade, validate: true, reverse_lock_order: true + ) + end +end diff --git a/db/post_migrate/20231025031539_swap_columns_for_ci_stages_pipeline_id_bigint_for_self_host.rb b/db/post_migrate/20231025031539_swap_columns_for_ci_stages_pipeline_id_bigint_for_self_host.rb new file mode 100644 index 00000000000..c28f49899b6 --- /dev/null +++ b/db/post_migrate/20231025031539_swap_columns_for_ci_stages_pipeline_id_bigint_for_self_host.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +class SwapColumnsForCiStagesPipelineIdBigintForSelfHost < Gitlab::Database::Migration[2.2] + include Gitlab::Database::MigrationHelpers::Swapping + + milestone '16.6' + disable_ddl_transaction! + + TABLE_NAME = :ci_stages + TRIGGER_FUNCTION_NAME = :trigger_07bc3c48f407 + COLUMN_NAME = :pipeline_id + BIGINT_COLUMN_NAME = :pipeline_id_convert_to_bigint + FK_NAME = :fk_fb57e6cc56 + BIGINT_FK_NAME = :fk_c5ddde695f + INDEX_NAMES = %i[ + index_ci_stages_on_pipeline_id + index_ci_stages_on_pipeline_id_and_id + index_ci_stages_on_pipeline_id_and_name + index_ci_stages_on_pipeline_id_and_position + ] + BIGINT_INDEX_NAMES = %i[ + index_ci_stages_on_pipeline_id_convert_to_bigint + index_ci_stages_on_pipeline_id_convert_to_bigint_and_id + index_ci_stages_on_pipeline_id_convert_to_bigint_and_name + index_ci_stages_on_pipeline_id_convert_to_bigint_and_position + ] + + def up + return if column_type_of?(:bigint) + + swap + end + + def down + return if column_type_of?(:integer) + + swap + end + + private + + def column_type_of?(type) + column_for(TABLE_NAME, COLUMN_NAME).sql_type.to_s == type.to_s + end + + def swap + with_lock_retries(raise_on_exhaustion: true) do + # Lock the tables involved. + lock_tables(:ci_pipelines, :ci_stages) + + # Rename the columns to swap names + swap_columns(TABLE_NAME, COLUMN_NAME, BIGINT_COLUMN_NAME) + + # Reset the trigger function + reset_trigger_function(TRIGGER_FUNCTION_NAME) + + # Swap fkey constraint + swap_foreign_keys(TABLE_NAME, FK_NAME, BIGINT_FK_NAME) + + # Swap index + INDEX_NAMES.each_with_index do |index_name, i| + swap_indexes(TABLE_NAME, index_name, BIGINT_INDEX_NAMES[i]) + end + end + end +end diff --git a/db/post_migrate/20231026103346_drop_project_settings_jitsu_key.rb b/db/post_migrate/20231026103346_drop_project_settings_jitsu_key.rb new file mode 100644 index 00000000000..606648ca7fa --- /dev/null +++ b/db/post_migrate/20231026103346_drop_project_settings_jitsu_key.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class DropProjectSettingsJitsuKey < Gitlab::Database::Migration[2.2] + milestone '16.6' + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_column :project_settings, :jitsu_key, if_exists: true + end + end + + def down + with_lock_retries do + add_column :project_settings, :jitsu_key, :text, if_not_exists: true + end + + add_text_limit :project_settings, :jitsu_key, 100 + end +end diff --git a/db/post_migrate/20231027013210_remove_partial_index_deployments_for_legacy_successful_deployments.rb b/db/post_migrate/20231027013210_remove_partial_index_deployments_for_legacy_successful_deployments.rb new file mode 100644 index 00000000000..2bd52fdc10a --- /dev/null +++ b/db/post_migrate/20231027013210_remove_partial_index_deployments_for_legacy_successful_deployments.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemovePartialIndexDeploymentsForLegacySuccessfulDeployments < Gitlab::Database::Migration[2.2] + INDEX_NAME = 'partial_index_deployments_for_legacy_successful_deployments' + + milestone '16.6' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :deployments, name: INDEX_NAME + end + + def down + # This is based on the following `CREATE INDEX` command in db/init_structure.sql: + # CREATE INDEX partial_index_deployments_for_legacy_successful_deployments ON deployments + # USING btree (id) WHERE ((finished_at IS NULL) AND (status = 2)); + add_concurrent_index :deployments, :id, name: INDEX_NAME, where: '((finished_at IS NULL) AND (status = 2))' + end +end diff --git a/db/post_migrate/20231027060443_backfill_system_note_metadata_id_for_bigint_conversion.rb b/db/post_migrate/20231027060443_backfill_system_note_metadata_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..d3c90134102 --- /dev/null +++ b/db/post_migrate/20231027060443_backfill_system_note_metadata_id_for_bigint_conversion.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class BackfillSystemNoteMetadataIdForBigintConversion < Gitlab::Database::Migration[2.2] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + TABLE = :system_note_metadata + COLUMNS = %i[id] + + milestone '16.6' + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, sub_batch_size: 100) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20231027083355_remove_projects_duplicated_indexes.rb b/db/post_migrate/20231027083355_remove_projects_duplicated_indexes.rb new file mode 100644 index 00000000000..7911a60df3f --- /dev/null +++ b/db/post_migrate/20231027083355_remove_projects_duplicated_indexes.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveProjectsDuplicatedIndexes < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.6' + + INDEX_NAME = :index_on_projects_path + TABLE_NAME = :projects + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, :path, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20231030051840_add_not_null_to_packages_tags_project_id.rb b/db/post_migrate/20231030051840_add_not_null_to_packages_tags_project_id.rb new file mode 100644 index 00000000000..6541861cd45 --- /dev/null +++ b/db/post_migrate/20231030051840_add_not_null_to_packages_tags_project_id.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddNotNullToPackagesTagsProjectId < Gitlab::Database::Migration[2.2] + milestone '16.6' + disable_ddl_transaction! + + def up + add_not_null_constraint :packages_tags, :project_id, validate: false + end + + def down + remove_not_null_constraint :packages_tags, :project_id + end +end diff --git a/db/post_migrate/20231030071209_queue_backfill_packages_tags_project_id.rb b/db/post_migrate/20231030071209_queue_backfill_packages_tags_project_id.rb new file mode 100644 index 00000000000..4984eb83263 --- /dev/null +++ b/db/post_migrate/20231030071209_queue_backfill_packages_tags_project_id.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class QueueBackfillPackagesTagsProjectId < Gitlab::Database::Migration[2.2] + milestone '16.6' + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + MIGRATION = "BackfillPackagesTagsProjectId" + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 100 + + def up + queue_batched_background_migration( + MIGRATION, + :packages_tags, + :id, + job_interval: DELAY_INTERVAL, + queued_migration_version: '20231030071209', + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :packages_tags, :id, []) + end +end diff --git a/db/post_migrate/20231030094755_add_index_to_catalog_resources_on_state.rb b/db/post_migrate/20231030094755_add_index_to_catalog_resources_on_state.rb new file mode 100644 index 00000000000..b7c6c8affdb --- /dev/null +++ b/db/post_migrate/20231030094755_add_index_to_catalog_resources_on_state.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToCatalogResourcesOnState < Gitlab::Database::Migration[2.2] + milestone '16.6' + + disable_ddl_transaction! + + INDEX_NAME = 'index_catalog_resources_on_state' + + def up + add_concurrent_index :catalog_resources, :state, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :catalog_resources, INDEX_NAME + end +end diff --git a/db/post_migrate/20231030095419_remove_temp_index_to_packages_on_project_id_when_npm_and_not_pending_destruction.rb b/db/post_migrate/20231030095419_remove_temp_index_to_packages_on_project_id_when_npm_and_not_pending_destruction.rb new file mode 100644 index 00000000000..cd3fccf5f4d --- /dev/null +++ b/db/post_migrate/20231030095419_remove_temp_index_to_packages_on_project_id_when_npm_and_not_pending_destruction.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class RemoveTempIndexToPackagesOnProjectIdWhenNpmAndNotPendingDestruction < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.7' + + INDEX_NAME = 'tmp_idx_packages_on_project_id_when_npm_not_pending_destruction' + NPM_PACKAGE_TYPE = 2 + PENDING_DESTRUCTION_STATUS = 4 + + def up + remove_concurrent_index_by_name :packages_packages, INDEX_NAME + end + + def down + add_concurrent_index( + :packages_packages, + :project_id, + name: INDEX_NAME, + where: "package_type = #{NPM_PACKAGE_TYPE} AND status <> #{PENDING_DESTRUCTION_STATUS}" + ) + end +end diff --git a/db/post_migrate/20231030154117_insert_new_ultimate_trial_plan_into_plans.rb b/db/post_migrate/20231030154117_insert_new_ultimate_trial_plan_into_plans.rb new file mode 100644 index 00000000000..af589f6337a --- /dev/null +++ b/db/post_migrate/20231030154117_insert_new_ultimate_trial_plan_into_plans.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class InsertNewUltimateTrialPlanIntoPlans < Gitlab::Database::Migration[2.2] + milestone '16.6' + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + execute <<~SQL + INSERT INTO plans (name, title, created_at, updated_at) + VALUES ('ultimate_trial_paid_customer', 'Ultimate Trial for Paid Customer', current_timestamp, current_timestamp) + SQL + end + + def down + # NOTE: We have a uniqueness constraint for the 'name' column in 'plans' + execute <<~SQL + DELETE FROM plans + WHERE name = 'ultimate_trial_paid_customer' + SQL + end +end diff --git a/db/post_migrate/20231031134320_init_conversion_for_p_ci_builds_for_self_host.rb b/db/post_migrate/20231031134320_init_conversion_for_p_ci_builds_for_self_host.rb new file mode 100644 index 00000000000..d70ce00e9df --- /dev/null +++ b/db/post_migrate/20231031134320_init_conversion_for_p_ci_builds_for_self_host.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class InitConversionForPCiBuildsForSelfHost < Gitlab::Database::Migration[2.2] + include ::Gitlab::Database::SchemaHelpers + + milestone '16.6' + disable_ddl_transaction! + + TABLE_NAME = :p_ci_builds + COLUMN_NAMES = %i[ + auto_canceled_by_id + commit_id + erased_by_id + project_id + runner_id + trigger_request_id + upstream_pipeline_id + user_id + ] + TRIGGER_NAME = :trigger_10ee1357e825 + + def up + return if should_skip? + + initialize_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES) + end + + def down + return unless should_skip? + + revert_initialize_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES) + end + + private + + def should_skip? + trigger_exists?(TABLE_NAME, TRIGGER_NAME) + end +end diff --git a/db/post_migrate/20231101130230_remove_in_product_marketing_emails_campaign_column.rb b/db/post_migrate/20231101130230_remove_in_product_marketing_emails_campaign_column.rb new file mode 100644 index 00000000000..8916a1e9729 --- /dev/null +++ b/db/post_migrate/20231101130230_remove_in_product_marketing_emails_campaign_column.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class RemoveInProductMarketingEmailsCampaignColumn < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.6' + + TARGET_TABLE = :in_product_marketing_emails + UNIQUE_INDEX_NAME = :index_in_product_marketing_emails_on_user_campaign + CONSTRAINT_NAME = :in_product_marketing_emails_track_and_series_or_campaign + TRACK_AND_SERIES_NOT_NULL_CONSTRAINT = 'track IS NOT NULL AND series IS NOT NULL AND campaign IS NULL' + CAMPAIGN_NOT_NULL_CONSTRAINT = 'track IS NULL AND series IS NULL AND campaign IS NOT NULL' + + def up + with_lock_retries do + remove_column :in_product_marketing_emails, :campaign, if_exists: true + end + end + + def down + with_lock_retries do + add_column :in_product_marketing_emails, :campaign, :text, if_not_exists: true + end + + add_text_limit :in_product_marketing_emails, :campaign, 255 + + add_concurrent_index TARGET_TABLE, [:user_id, :campaign], unique: true, name: UNIQUE_INDEX_NAME + add_check_constraint TARGET_TABLE, + "(#{TRACK_AND_SERIES_NOT_NULL_CONSTRAINT}) OR (#{CAMPAIGN_NOT_NULL_CONSTRAINT})", + CONSTRAINT_NAME + end +end diff --git a/db/post_migrate/20231102083539_backfill_p_ci_builds_pipeline_id.rb b/db/post_migrate/20231102083539_backfill_p_ci_builds_pipeline_id.rb new file mode 100644 index 00000000000..feada383fe4 --- /dev/null +++ b/db/post_migrate/20231102083539_backfill_p_ci_builds_pipeline_id.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class BackfillPCiBuildsPipelineId < Gitlab::Database::Migration[2.2] + restrict_gitlab_migration gitlab_schema: :gitlab_ci + milestone '16.6' + + TABLE_NAME = :ci_builds + COLUMN_NAMES = %i[ + auto_canceled_by_id + commit_id + erased_by_id + project_id + runner_id + trigger_request_id + upstream_pipeline_id + user_id + ] + SUB_BATCH_SIZE = 750 + BATCH_SIZE = 75_000 + PAUSE_MS = 0 + + def up + backfill_conversion_of_integer_to_bigint( + TABLE_NAME, COLUMN_NAMES, + sub_batch_size: SUB_BATCH_SIZE, + batch_size: BATCH_SIZE, + pause_ms: PAUSE_MS + ) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES) + end +end diff --git a/db/post_migrate/20231102142557_remove_zoekt_shard_null_constraint_from_indexed_namespaces.rb b/db/post_migrate/20231102142557_remove_zoekt_shard_null_constraint_from_indexed_namespaces.rb new file mode 100644 index 00000000000..08e76c749c7 --- /dev/null +++ b/db/post_migrate/20231102142557_remove_zoekt_shard_null_constraint_from_indexed_namespaces.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class RemoveZoektShardNullConstraintFromIndexedNamespaces < Gitlab::Database::Migration[2.2] + milestone '16.6' + disable_ddl_transaction! + + def up + change_column_null :zoekt_indexed_namespaces, :zoekt_shard_id, true + end + + def down + change_column_null :zoekt_indexed_namespaces, :zoekt_shard_id, false + end +end diff --git a/db/post_migrate/20231103132849_add_state_index_for_snippet_repository_storage_move.rb b/db/post_migrate/20231103132849_add_state_index_for_snippet_repository_storage_move.rb new file mode 100644 index 00000000000..3270a60acd8 --- /dev/null +++ b/db/post_migrate/20231103132849_add_state_index_for_snippet_repository_storage_move.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddStateIndexForSnippetRepositoryStorageMove < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.6' + + INDEX_NAME = 'index_snippet_repository_storage_moves_on_state' + + def up + # State 2 = scheduled and 3 = started + add_concurrent_index :snippet_repository_storage_moves, :state, where: 'state IN (2, 3)', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :snippet_repository_storage_moves, INDEX_NAME + end +end diff --git a/db/post_migrate/20231105165706_drop_repositories_columns_from_geo_node_status_table.rb b/db/post_migrate/20231105165706_drop_repositories_columns_from_geo_node_status_table.rb new file mode 100644 index 00000000000..69c9b54dc68 --- /dev/null +++ b/db/post_migrate/20231105165706_drop_repositories_columns_from_geo_node_status_table.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class DropRepositoriesColumnsFromGeoNodeStatusTable < Gitlab::Database::Migration[2.2] + enable_lock_retries! + milestone '16.6' + + def up + [ + :repositories_synced_count, + :repositories_failed_count, + :repositories_verified_count, + :repositories_verification_failed_count, + :repositories_checksummed_count, + :repositories_checksum_failed_count, + :repositories_checksum_mismatch_count, + :repositories_retrying_verification_count + ].each do |column_name| + remove_column :geo_node_statuses, column_name, if_exists: true + end + end + + def down + change_table(:geo_node_statuses) do |t| + t.integer :repositories_synced_count + t.integer :repositories_failed_count + t.integer :repositories_verified_count + t.integer :repositories_verification_failed_count + t.integer :repositories_checksummed_count + t.integer :repositories_checksum_failed_count + t.integer :repositories_checksum_mismatch_count + t.integer :repositories_retrying_verification_count + end + end +end diff --git a/db/post_migrate/20231109183438_drop_merge_request_assignees_on_merge_request_id_index.rb b/db/post_migrate/20231109183438_drop_merge_request_assignees_on_merge_request_id_index.rb new file mode 100644 index 00000000000..e1f96393031 --- /dev/null +++ b/db/post_migrate/20231109183438_drop_merge_request_assignees_on_merge_request_id_index.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class DropMergeRequestAssigneesOnMergeRequestIdIndex < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.6' + + INDEX_NAME = 'index_merge_request_assignees_on_merge_request_id' + TABLE_NAME = :merge_request_assignees + + def up + # Duplicated index. This index is covered by +index_merge_request_assignees_on_merge_request_id_and_user_id+ + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, :merge_request_id, name: INDEX_NAME + end +end |