summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-11-17 11:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-11-17 11:33:21 +0000
commit7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch)
tree5bdc2229f5198d516781f8d24eace62fc7e589e9 /db/post_migrate
parent185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff)
downloadgitlab-ce-7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0.tar.gz
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb2
-rw-r--r--db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb2
-rw-r--r--db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb2
-rw-r--r--db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb2
-rw-r--r--db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb2
-rw-r--r--db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb4
-rw-r--r--db/post_migrate/20210818185845_backfill_projects_with_coverage.rb23
-rw-r--r--db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb24
-rw-r--r--db/post_migrate/20220919080303_delete_migrate_shared_vulnerability_scanners.rb44
-rw-r--r--db/post_migrate/20220919080304_reschedule_migrate_shared_vulnerability_scanners.rb29
-rw-r--r--db/post_migrate/20220927171740_prepare_for_vulnerability_occurrences_uuid_type_transition.rb26
-rw-r--r--db/post_migrate/20221004074910_routing_table_prepare_constraint_for_builds_metadata.rb30
-rw-r--r--db/post_migrate/20221004074914_create_routing_table_for_builds_metadata.rb7
-rw-r--r--db/post_migrate/20221006070927_finalize_invalid_member_cleanup.rb22
-rw-r--r--db/post_migrate/20221006172302_adjust_task_note_rename_background_migration_values.rb2
-rw-r--r--db/post_migrate/20221010141500_add_index_author_id_target_project_id_on_merge_requests.rb15
-rw-r--r--db/post_migrate/20221010162137_add_index_author_id_and_id_on_merge_requests.rb15
-rw-r--r--db/post_migrate/20221011062254_sync_new_amount_used_for_ci_project_monthly_usages.rb19
-rw-r--r--db/post_migrate/20221013215832_cleanup_vulnerability_state_transitions_with_same_from_state_to_state.rb19
-rw-r--r--db/post_migrate/20221017084227_cleanup_rename_ci_pipeline_metadata_title.rb13
-rw-r--r--db/post_migrate/20221018062308_schedule_backfill_project_namespace_details.rb29
-rw-r--r--db/post_migrate/20221018193635_ensure_task_note_renaming_background_migration_finished.rb22
-rw-r--r--db/post_migrate/20221018193827_drop_tmp_index_system_note_metadata_on_id_where_task.rb15
-rw-r--r--db/post_migrate/20221018232820_add_temp_index_for_user_details_fields.rb22
-rw-r--r--db/post_migrate/20221019002459_queue_backfill_user_details_fields.rb16
-rw-r--r--db/post_migrate/20221019102426_remove_tmp_index_approval_merge_request_rules_on_report_type.rb18
-rw-r--r--db/post_migrate/20221019105041_queue_populate_projects_star_count.rb22
-rw-r--r--db/post_migrate/20221019141508_add_index_to_test_reports_issue_id_created_at_and_id.rb16
-rw-r--r--db/post_migrate/20221019194751_disable_fastupdate_on_issues_title_gin_index.rb23
-rw-r--r--db/post_migrate/20221019195754_disable_fastupdate_on_issues_description_gin_index.rb23
-rw-r--r--db/post_migrate/20221019200033_disable_fastupdate_on_merge_requests_title_gin_index.rb23
-rw-r--r--db/post_migrate/20221019200206_disable_fastupdate_on_merge_requests_description_gin_index.rb23
-rw-r--r--db/post_migrate/20221021082255_add_unique_index_on_ci_runners_token.rb20
-rw-r--r--db/post_migrate/20221021082312_add_unique_index_on_ci_runners_token_encrypted.rb20
-rw-r--r--db/post_migrate/20221021082720_drop_index_on_ci_runners_token.rb17
-rw-r--r--db/post_migrate/20221021082734_drop_index_on_ci_runners_token_encrypted.rb17
-rw-r--r--db/post_migrate/20221021145820_create_routing_table_for_builds_metadata_v2.rb41
-rw-r--r--db/post_migrate/20221021160735_add_index_for_common_finder_query_desc_with_namespace_id.rb18
-rw-r--r--db/post_migrate/20221024034228_remove_sprints_project_id_column.rb38
-rw-r--r--db/post_migrate/20221024121500_drop_fingerprint_from_sbom_sources.rb9
-rw-r--r--db/post_migrate/20221025115006_check_vulnerabilities_state_transition_from_state_not_equal_to_state.rb19
-rw-r--r--db/post_migrate/20221025220607_add_index_id_on_scan_finding_approval_merge_request_rules.rb17
-rw-r--r--db/post_migrate/20221027203556_delete_experiment_user_foreign_keys.rb20
-rw-r--r--db/post_migrate/20221027203951_drop_experiment_users_table.rb21
-rw-r--r--db/post_migrate/20221028000041_remove_invalid_partial_trigram_indexes_for_issues.rb15
-rw-r--r--db/post_migrate/20221028000603_prepare_partial_trigram_indexes_for_issues_attempt_3.rb25
-rw-r--r--db/post_migrate/20221028022627_add_index_on_password_last_changed_at_to_user_details.rb15
-rw-r--r--db/post_migrate/20221102090940_create_next_ci_partitions_record.rb29
-rw-r--r--db/post_migrate/20221102090943_create_second_partition_for_builds_metadata.rb62
-rw-r--r--db/post_migrate/20221103073328_change_member_namespace_id_not_null.rb16
-rw-r--r--db/post_migrate/20221103084213_remove_tmp_index_members_on_id_where_namespace_id_null.rb15
-rw-r--r--db/post_migrate/20221103150250_migrate_sidekiq_queued_jobs.rb11
-rw-r--r--db/post_migrate/20221104042137_add_partial_trigram_index_for_issue_title_attempt_2.rb19
-rw-r--r--db/post_migrate/20221104042159_add_partial_trigram_index_for_issue_description_attempt_2.rb19
-rw-r--r--db/post_migrate/20221104074652_add_temp_index_for_project_statistics_upload_size_migration.rb19
-rw-r--r--db/post_migrate/20221104100203_recreate_async_trigram_index_for_vulnerability_reads_container_images.rb21
-rw-r--r--db/post_migrate/20221104170500_add_vulnerability_reads_all_status_index.rb14
-rw-r--r--db/post_migrate/20221104190203_validate_environment_id_on_deployments.rb11
-rw-r--r--db/post_migrate/20221107094359_recount_epic_cache_counts.rb29
-rw-r--r--db/post_migrate/20221107184758_sync_new_amount_used_for_ci_namespace_monthly_usages.rb19
-rw-r--r--db/post_migrate/20221107220420_validate_not_null_constraint_on_member_namespace_id.rb15
-rw-r--r--db/post_migrate/20221107220526_validate_fk_member_namespace_id.rb13
-rw-r--r--db/post_migrate/20221107222213_remove_old_member_namespace_id_fk.rb28
-rw-r--r--db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb13
-rw-r--r--db/post_migrate/20221108121322_add_supporting_index_for_vulnerabilities_feedback_migration.rb24
-rw-r--r--db/post_migrate/20221108222015_remove_temp_index_on_project_features_where_releases_access_level_gt_repository.rb18
-rw-r--r--db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb31
-rw-r--r--db/post_migrate/20221111070314_prepare_removal_of_issue_trigram_indexes.rb16
68 files changed, 1256 insertions, 52 deletions
diff --git a/db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb b/db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb
index b9427f7cc93..5d31cdb05e6 100644
--- a/db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb
+++ b/db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb
@@ -19,7 +19,7 @@ class BackfillEventsIdForBigintConversion < ActiveRecord::Migration[6.0]
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'events', column_name: 'id')
- .where(job_arguments: %w[id id_convert_to_bigint].to_json)
+ .where(job_arguments: Gitlab::Json.dump(%w[id id_convert_to_bigint]))
.delete_all
end
diff --git a/db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb b/db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb
index 0d610f1dde1..b64282fe0d3 100644
--- a/db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb
+++ b/db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb
@@ -20,7 +20,7 @@ class BackfillPushEventPayloadEventIdForBigintConversion < ActiveRecord::Migrati
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'push_event_payloads', column_name: 'event_id')
- .where(job_arguments: %w[event_id event_id_convert_to_bigint].to_json)
+ .where(job_arguments: Gitlab::Json.dump(%w[event_id event_id_convert_to_bigint]))
.delete_all
end
diff --git a/db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb b/db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb
index 1ee67cd9dda..8fcaeb3fb04 100644
--- a/db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb
+++ b/db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb
@@ -20,7 +20,7 @@ class BackfillCiBuildNeedsForBigintConversion < ActiveRecord::Migration[6.0]
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'ci_build_needs', column_name: 'build_id')
- .where(job_arguments: %w[build_id build_id_convert_to_bigint].to_json)
+ .where(job_arguments: Gitlab::Json.dump(%w[build_id build_id_convert_to_bigint]))
.delete_all
end
diff --git a/db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb b/db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb
index 67076cc647a..0c68834f723 100644
--- a/db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb
+++ b/db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb
@@ -19,7 +19,7 @@ class BackfillConversionOfCiJobArtifacts < ActiveRecord::Migration[6.0]
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'ci_job_artifacts', column_name: 'id')
- .where(job_arguments: [%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]].to_json)
+ .where(job_arguments: Gitlab::Json.dump([%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]]))
.delete_all
end
diff --git a/db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb b/db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb
index bde91473ee3..3c6f2385f1d 100644
--- a/db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb
+++ b/db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb
@@ -18,7 +18,7 @@ class BackfillCiSourcesPipelinesSourceJobIdForBigintConversion < ActiveRecord::M
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'ci_sources_pipelines', column_name: 'id')
- .where(job_arguments: [%w[source_job_id], %w[source_job_id_convert_to_bigint]].to_json)
+ .where(job_arguments: Gitlab::Json.dump([%w[source_job_id], %w[source_job_id_convert_to_bigint]]))
.delete_all
end
diff --git a/db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb b/db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb
index 535f7426938..818aea39762 100644
--- a/db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb
+++ b/db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb
@@ -17,8 +17,8 @@ class FixBatchedMigrationsOldFormatJobArguments < ActiveRecord::Migration[6.1]
# rubocop:disable Rails/WhereEquals
base_scope
- .where('job_arguments = ?', legacy_job_arguments.to_json)
- .where('NOT EXISTS (?)', base_scope.select('1').where('job_arguments = ?', current_job_arguments.to_json))
+ .where('job_arguments = ?', Gitlab::Json.dump(legacy_job_arguments))
+ .where('NOT EXISTS (?)', base_scope.select('1').where('job_arguments = ?', Gitlab::Json.dump(current_job_arguments)))
.update_all(job_arguments: current_job_arguments)
# rubocop:enable Rails/WhereEquals
end
diff --git a/db/post_migrate/20210818185845_backfill_projects_with_coverage.rb b/db/post_migrate/20210818185845_backfill_projects_with_coverage.rb
index 003b7536767..d86d49f4393 100644
--- a/db/post_migrate/20210818185845_backfill_projects_with_coverage.rb
+++ b/db/post_migrate/20210818185845_backfill_projects_with_coverage.rb
@@ -1,29 +1,8 @@
# frozen_string_literal: true
class BackfillProjectsWithCoverage < ActiveRecord::Migration[6.1]
- include Gitlab::Database::MigrationHelpers
-
- MIGRATION = 'BackfillProjectsWithCoverage'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 10_000
- SUB_BATCH_SIZE = 1_000
-
- disable_ddl_transaction!
-
- class CiDailyBuildGroupReportResult < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'ci_daily_build_group_report_results'
- end
-
def up
- queue_background_migration_jobs_by_range_at_intervals(
- CiDailyBuildGroupReportResult,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- other_job_arguments: [SUB_BATCH_SIZE]
- )
+ # noop
end
def down
diff --git a/db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb b/db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb
index 92ca0998bae..724bd323169 100644
--- a/db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb
+++ b/db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb
@@ -1,34 +1,14 @@
# frozen_string_literal: true
class ScheduleMigrateSharedVulnerabilityScanners < Gitlab::Database::Migration[2.0]
- MIGRATION = "MigrateSharedVulnerabilityScanners"
- TABLE_NAME = :vulnerability_occurrences
- BATCH_COLUMN = :id
- DELAY_INTERVAL = 5.minutes
- BATCH_SIZE = 1000
- SUB_BATCH_SIZE = 100
-
- BATCH_MIN_VALUE = 23658505
- BATCH_MAX_VALUE = 204428752
-
disable_ddl_transaction!
restrict_gitlab_migration gitlab_schema: :gitlab_main
def up
- queue_batched_background_migration(
- MIGRATION,
- TABLE_NAME,
- BATCH_COLUMN,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- max_batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE,
- batch_min_value: BATCH_MIN_VALUE,
- batch_max_value: BATCH_MAX_VALUE
- )
+ # no-op
end
def down
- delete_batched_background_migration(MIGRATION, TABLE_NAME, BATCH_COLUMN, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20220919080303_delete_migrate_shared_vulnerability_scanners.rb b/db/post_migrate/20220919080303_delete_migrate_shared_vulnerability_scanners.rb
new file mode 100644
index 00000000000..4aedfcf1699
--- /dev/null
+++ b/db/post_migrate/20220919080303_delete_migrate_shared_vulnerability_scanners.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+class DeleteMigrateSharedVulnerabilityScanners < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = "MigrateSharedVulnerabilityScanners"
+ TABLE_NAME = :vulnerability_occurrences
+ BATCH_COLUMN = :id
+ BATCH_SIZE = 250
+
+ class BatchedBackgroundMigration < MigrationRecord
+ self.table_name = "batched_background_migrations"
+ end
+
+ class BatchedBackgroundMigrationJob < MigrationRecord
+ include ::EachBatch
+
+ self.table_name = "batched_background_migration_jobs"
+
+ belongs_to :batched_background_migration
+ end
+
+ def up
+ return unless migration_id = BatchedBackgroundMigration.find_by(job_class_name: MIGRATION)&.id
+
+ # rubocop:disable Style/SymbolProc
+ BatchedBackgroundMigrationJob
+ .where(batched_background_migration_id: migration_id)
+ .each_batch(of: BATCH_SIZE) do |relation|
+ relation.delete_all
+ end
+ # rubocop:enable Style/SymbolProc
+
+ delete_batched_background_migration(MIGRATION,
+ TABLE_NAME,
+ BATCH_COLUMN,
+ [])
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20220919080304_reschedule_migrate_shared_vulnerability_scanners.rb b/db/post_migrate/20220919080304_reschedule_migrate_shared_vulnerability_scanners.rb
new file mode 100644
index 00000000000..69757085587
--- /dev/null
+++ b/db/post_migrate/20220919080304_reschedule_migrate_shared_vulnerability_scanners.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class RescheduleMigrateSharedVulnerabilityScanners < Gitlab::Database::Migration[2.0]
+ MIGRATION = "MigrateSharedVulnerabilityScanners"
+ TABLE_NAME = :vulnerability_occurrences
+ BATCH_COLUMN = :id
+ DELAY_INTERVAL = 5.minutes
+ BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 100
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ TABLE_NAME,
+ BATCH_COLUMN,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ max_batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, TABLE_NAME, BATCH_COLUMN, [])
+ end
+end
diff --git a/db/post_migrate/20220927171740_prepare_for_vulnerability_occurrences_uuid_type_transition.rb b/db/post_migrate/20220927171740_prepare_for_vulnerability_occurrences_uuid_type_transition.rb
new file mode 100644
index 00000000000..e6f3384514d
--- /dev/null
+++ b/db/post_migrate/20220927171740_prepare_for_vulnerability_occurrences_uuid_type_transition.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class PrepareForVulnerabilityOccurrencesUuidTypeTransition < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ TABLE = :vulnerability_occurrences
+ MAPPINGS = {
+ uuid: {
+ from_type: :string,
+ to_type: :uuid,
+ default_value: '00000000-0000-0000-0000-000000000000'
+ }
+ }
+
+ def up
+ create_temporary_columns_and_triggers(TABLE, MAPPINGS)
+ end
+
+ def down
+ columns = MAPPINGS.keys
+ temporary_columns = columns.map { |column| convert_to_type_column(column, :string, :uuid) }
+ trigger_name = rename_trigger_name(TABLE, columns, temporary_columns)
+ remove_rename_triggers(TABLE, trigger_name)
+ temporary_columns.each { |column| remove_column(TABLE, column) }
+ end
+end
diff --git a/db/post_migrate/20221004074910_routing_table_prepare_constraint_for_builds_metadata.rb b/db/post_migrate/20221004074910_routing_table_prepare_constraint_for_builds_metadata.rb
new file mode 100644
index 00000000000..013984154ae
--- /dev/null
+++ b/db/post_migrate/20221004074910_routing_table_prepare_constraint_for_builds_metadata.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class RoutingTablePrepareConstraintForBuildsMetadata < Gitlab::Database::Migration[2.0]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_builds_metadata
+ PARENT_TABLE_NAME = :p_ci_builds_metadata
+ FIRST_PARTITION = 100
+ PARTITION_COLUMN = :partition_id
+
+ def up
+ prepare_constraint_for_list_partitioning(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION
+ )
+ end
+
+ def down
+ revert_preparing_constraint_for_list_partitioning(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION
+ )
+ end
+end
diff --git a/db/post_migrate/20221004074914_create_routing_table_for_builds_metadata.rb b/db/post_migrate/20221004074914_create_routing_table_for_builds_metadata.rb
new file mode 100644
index 00000000000..a792fc91d3d
--- /dev/null
+++ b/db/post_migrate/20221004074914_create_routing_table_for_builds_metadata.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class CreateRoutingTableForBuildsMetadata < Gitlab::Database::Migration[2.0]
+ def up; end
+
+ def down; end
+end
diff --git a/db/post_migrate/20221006070927_finalize_invalid_member_cleanup.rb b/db/post_migrate/20221006070927_finalize_invalid_member_cleanup.rb
new file mode 100644
index 00000000000..78786e46f5c
--- /dev/null
+++ b/db/post_migrate/20221006070927_finalize_invalid_member_cleanup.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class FinalizeInvalidMemberCleanup < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'DestroyInvalidMembers'
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :members,
+ column_name: :id,
+ job_arguments: []
+ )
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20221006172302_adjust_task_note_rename_background_migration_values.rb b/db/post_migrate/20221006172302_adjust_task_note_rename_background_migration_values.rb
index 2af16fb6d3c..b582b163e2d 100644
--- a/db/post_migrate/20221006172302_adjust_task_note_rename_background_migration_values.rb
+++ b/db/post_migrate/20221006172302_adjust_task_note_rename_background_migration_values.rb
@@ -20,7 +20,7 @@ class AdjustTaskNoteRenameBackgroundMigrationValues < Gitlab::Database::Migratio
scope :for_configuration, ->(job_class_name, table_name, column_name, job_arguments) do
where(job_class_name: job_class_name, table_name: table_name, column_name: column_name)
- .where("job_arguments = ?", job_arguments.to_json) # rubocop:disable Rails/WhereEquals
+ .where("job_arguments = ?", Gitlab::Json.dump(job_arguments)) # rubocop:disable Rails/WhereEquals
end
end
diff --git a/db/post_migrate/20221010141500_add_index_author_id_target_project_id_on_merge_requests.rb b/db/post_migrate/20221010141500_add_index_author_id_target_project_id_on_merge_requests.rb
new file mode 100644
index 00000000000..5b9d5be2b3f
--- /dev/null
+++ b/db/post_migrate/20221010141500_add_index_author_id_target_project_id_on_merge_requests.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexAuthorIdTargetProjectIdOnMergeRequests < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_merge_requests_on_author_id_and_target_project_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :merge_requests, %i[author_id target_project_id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :merge_requests, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221010162137_add_index_author_id_and_id_on_merge_requests.rb b/db/post_migrate/20221010162137_add_index_author_id_and_id_on_merge_requests.rb
new file mode 100644
index 00000000000..36184b5f573
--- /dev/null
+++ b/db/post_migrate/20221010162137_add_index_author_id_and_id_on_merge_requests.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexAuthorIdAndIdOnMergeRequests < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_merge_requests_on_author_id_and_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :merge_requests, %i[author_id id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :merge_requests, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221011062254_sync_new_amount_used_for_ci_project_monthly_usages.rb b/db/post_migrate/20221011062254_sync_new_amount_used_for_ci_project_monthly_usages.rb
new file mode 100644
index 00000000000..32943f10fcf
--- /dev/null
+++ b/db/post_migrate/20221011062254_sync_new_amount_used_for_ci_project_monthly_usages.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class SyncNewAmountUsedForCiProjectMonthlyUsages < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ def up
+ project_usages = define_batchable_model('ci_project_monthly_usages')
+
+ project_usages.each_batch(of: 500) do |batch|
+ batch.where('amount_used > 0').update_all('new_amount_used = amount_used')
+ end
+ end
+
+ def down
+ # Non reversible migration.
+ # This data migration keeps `new_amount_used` in sync with the old `amount_used`.
+ # In case of failure or interruption the migration can be retried.
+ end
+end
diff --git a/db/post_migrate/20221013215832_cleanup_vulnerability_state_transitions_with_same_from_state_to_state.rb b/db/post_migrate/20221013215832_cleanup_vulnerability_state_transitions_with_same_from_state_to_state.rb
new file mode 100644
index 00000000000..a81a80deb25
--- /dev/null
+++ b/db/post_migrate/20221013215832_cleanup_vulnerability_state_transitions_with_same_from_state_to_state.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class CleanupVulnerabilityStateTransitionsWithSameFromStateToState < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ class VulnerabilityStateTransition < MigrationRecord
+ self.table_name = 'vulnerability_state_transitions'
+ end
+
+ def up
+ VulnerabilityStateTransition.where('from_state = to_state').delete_all
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221017084227_cleanup_rename_ci_pipeline_metadata_title.rb b/db/post_migrate/20221017084227_cleanup_rename_ci_pipeline_metadata_title.rb
new file mode 100644
index 00000000000..0829f3d8734
--- /dev/null
+++ b/db/post_migrate/20221017084227_cleanup_rename_ci_pipeline_metadata_title.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class CleanupRenameCiPipelineMetadataTitle < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ cleanup_concurrent_column_rename :ci_pipeline_metadata, :title, :name
+ end
+
+ def down
+ undo_cleanup_concurrent_column_rename :ci_pipeline_metadata, :title, :name, batch_column_name: :pipeline_id
+ end
+end
diff --git a/db/post_migrate/20221018062308_schedule_backfill_project_namespace_details.rb b/db/post_migrate/20221018062308_schedule_backfill_project_namespace_details.rb
new file mode 100644
index 00000000000..74c8ef37ac2
--- /dev/null
+++ b/db/post_migrate/20221018062308_schedule_backfill_project_namespace_details.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class ScheduleBackfillProjectNamespaceDetails < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'BackfillProjectNamespaceDetails'
+ INTERVAL = 2.minutes
+ BATCH_SIZE = 1_000
+ MAX_BATCH_SIZE = 10_000
+ SUB_BATCH_SIZE = 200
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :projects,
+ :id,
+ job_interval: INTERVAL,
+ batch_size: BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :projects, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221018193635_ensure_task_note_renaming_background_migration_finished.rb b/db/post_migrate/20221018193635_ensure_task_note_renaming_background_migration_finished.rb
new file mode 100644
index 00000000000..c6ae0f185d8
--- /dev/null
+++ b/db/post_migrate/20221018193635_ensure_task_note_renaming_background_migration_finished.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class EnsureTaskNoteRenamingBackgroundMigrationFinished < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'RenameTaskSystemNoteToChecklistItem'
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :system_note_metadata,
+ column_name: :id,
+ job_arguments: []
+ )
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20221018193827_drop_tmp_index_system_note_metadata_on_id_where_task.rb b/db/post_migrate/20221018193827_drop_tmp_index_system_note_metadata_on_id_where_task.rb
new file mode 100644
index 00000000000..5cc70c530c6
--- /dev/null
+++ b/db/post_migrate/20221018193827_drop_tmp_index_system_note_metadata_on_id_where_task.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DropTmpIndexSystemNoteMetadataOnIdWhereTask < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'tmp_index_system_note_metadata_on_id_where_task'
+
+ def up
+ remove_concurrent_index_by_name :system_note_metadata, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :system_note_metadata, [:id, :action], where: "action = 'task'", name: INDEX_NAME
+ end
+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
new file mode 100644
index 00000000000..b46b316981d
--- /dev/null
+++ b/db/post_migrate/20221018232820_add_temp_index_for_user_details_fields.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddTempIndexForUserDetailsFields < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'tmp_idx_where_user_details_fields_filled'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :users, :id, name: INDEX_NAME, where: <<~QUERY
+ (COALESCE(linkedin, '') IS DISTINCT FROM '')
+ OR (COALESCE(twitter, '') IS DISTINCT FROM '')
+ OR (COALESCE(skype, '') IS DISTINCT FROM '')
+ OR (COALESCE(website_url, '') IS DISTINCT FROM '')
+ OR (COALESCE(location, '') IS DISTINCT FROM '')
+ OR (COALESCE(organization, '') IS DISTINCT FROM '')
+ QUERY
+ end
+
+ def down
+ remove_concurrent_index_by_name :users, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221019002459_queue_backfill_user_details_fields.rb b/db/post_migrate/20221019002459_queue_backfill_user_details_fields.rb
new file mode 100644
index 00000000000..8ed4416a98d
--- /dev/null
+++ b/db/post_migrate/20221019002459_queue_backfill_user_details_fields.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class QueueBackfillUserDetailsFields < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'BackfillUserDetailsFields'
+ INTERVAL = 2.minutes
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(MIGRATION, :users, :id, job_interval: INTERVAL)
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :users, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221019102426_remove_tmp_index_approval_merge_request_rules_on_report_type.rb b/db/post_migrate/20221019102426_remove_tmp_index_approval_merge_request_rules_on_report_type.rb
new file mode 100644
index 00000000000..7203d35de92
--- /dev/null
+++ b/db/post_migrate/20221019102426_remove_tmp_index_approval_merge_request_rules_on_report_type.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveTmpIndexApprovalMergeRequestRulesOnReportType < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'tmp_index_approval_merge_request_rules_on_report_type_equal_one'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :approval_merge_request_rules, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :approval_merge_request_rules,
+ [:id, :report_type],
+ name: INDEX_NAME,
+ where: "report_type = 1"
+ end
+end
diff --git a/db/post_migrate/20221019105041_queue_populate_projects_star_count.rb b/db/post_migrate/20221019105041_queue_populate_projects_star_count.rb
new file mode 100644
index 00000000000..768e0c7826f
--- /dev/null
+++ b/db/post_migrate/20221019105041_queue_populate_projects_star_count.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class QueuePopulateProjectsStarCount < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'PopulateProjectsStarCount'
+ DELAY_INTERVAL = 2.minutes
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :projects,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ sub_batch_size: 50
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :projects, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221019141508_add_index_to_test_reports_issue_id_created_at_and_id.rb b/db/post_migrate/20221019141508_add_index_to_test_reports_issue_id_created_at_and_id.rb
new file mode 100644
index 00000000000..054512adf2e
--- /dev/null
+++ b/db/post_migrate/20221019141508_add_index_to_test_reports_issue_id_created_at_and_id.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddIndexToTestReportsIssueIdCreatedAtAndId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'requirements_management_test_reports'
+ INDEX_NAME = 'idx_test_reports_on_issue_id_created_at_and_id'
+
+ def up
+ add_concurrent_index TABLE_NAME, [:issue_id, :created_at, :id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221019194751_disable_fastupdate_on_issues_title_gin_index.rb b/db/post_migrate/20221019194751_disable_fastupdate_on_issues_title_gin_index.rb
new file mode 100644
index 00000000000..6ad846dda1c
--- /dev/null
+++ b/db/post_migrate/20221019194751_disable_fastupdate_on_issues_title_gin_index.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class DisableFastupdateOnIssuesTitleGinIndex < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_issues_on_title_trigram'
+
+ def up
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} SET ( fastupdate = false ) ;
+ SQL
+ end
+ end
+
+ def down
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} RESET ( fastupdate ) ;
+ SQL
+ end
+ end
+end
diff --git a/db/post_migrate/20221019195754_disable_fastupdate_on_issues_description_gin_index.rb b/db/post_migrate/20221019195754_disable_fastupdate_on_issues_description_gin_index.rb
new file mode 100644
index 00000000000..ce09a48833f
--- /dev/null
+++ b/db/post_migrate/20221019195754_disable_fastupdate_on_issues_description_gin_index.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class DisableFastupdateOnIssuesDescriptionGinIndex < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_issues_on_description_trigram'
+
+ def up
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} SET ( fastupdate = false ) ;
+ SQL
+ end
+ end
+
+ def down
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} RESET ( fastupdate ) ;
+ SQL
+ end
+ end
+end
diff --git a/db/post_migrate/20221019200033_disable_fastupdate_on_merge_requests_title_gin_index.rb b/db/post_migrate/20221019200033_disable_fastupdate_on_merge_requests_title_gin_index.rb
new file mode 100644
index 00000000000..eb4c413a5a9
--- /dev/null
+++ b/db/post_migrate/20221019200033_disable_fastupdate_on_merge_requests_title_gin_index.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class DisableFastupdateOnMergeRequestsTitleGinIndex < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_merge_requests_on_title_trigram'
+
+ def up
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} SET ( fastupdate = false ) ;
+ SQL
+ end
+ end
+
+ def down
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} RESET ( fastupdate ) ;
+ SQL
+ end
+ end
+end
diff --git a/db/post_migrate/20221019200206_disable_fastupdate_on_merge_requests_description_gin_index.rb b/db/post_migrate/20221019200206_disable_fastupdate_on_merge_requests_description_gin_index.rb
new file mode 100644
index 00000000000..2e55937db36
--- /dev/null
+++ b/db/post_migrate/20221019200206_disable_fastupdate_on_merge_requests_description_gin_index.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class DisableFastupdateOnMergeRequestsDescriptionGinIndex < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_merge_requests_on_description_trigram'
+
+ def up
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} SET ( fastupdate = false ) ;
+ SQL
+ end
+ end
+
+ def down
+ with_lock_retries do
+ execute <<~SQL
+ ALTER INDEX #{INDEX_NAME} RESET ( fastupdate ) ;
+ SQL
+ end
+ end
+end
diff --git a/db/post_migrate/20221021082255_add_unique_index_on_ci_runners_token.rb b/db/post_migrate/20221021082255_add_unique_index_on_ci_runners_token.rb
new file mode 100644
index 00000000000..3dfa44f9615
--- /dev/null
+++ b/db/post_migrate/20221021082255_add_unique_index_on_ci_runners_token.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexOnCiRunnersToken < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_uniq_ci_runners_on_token'
+
+ def up
+ finalize_background_migration 'ResetDuplicateCiRunnersTokenValues'
+
+ add_concurrent_index :ci_runners,
+ :token,
+ name: INDEX_NAME,
+ unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name :ci_runners, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221021082312_add_unique_index_on_ci_runners_token_encrypted.rb b/db/post_migrate/20221021082312_add_unique_index_on_ci_runners_token_encrypted.rb
new file mode 100644
index 00000000000..8728c0ff20e
--- /dev/null
+++ b/db/post_migrate/20221021082312_add_unique_index_on_ci_runners_token_encrypted.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexOnCiRunnersTokenEncrypted < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_uniq_ci_runners_on_token_encrypted'
+
+ def up
+ finalize_background_migration 'ResetDuplicateCiRunnersTokenEncryptedValues'
+
+ add_concurrent_index :ci_runners,
+ :token_encrypted,
+ name: INDEX_NAME,
+ unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name :ci_runners, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221021082720_drop_index_on_ci_runners_token.rb b/db/post_migrate/20221021082720_drop_index_on_ci_runners_token.rb
new file mode 100644
index 00000000000..9125831fbf3
--- /dev/null
+++ b/db/post_migrate/20221021082720_drop_index_on_ci_runners_token.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropIndexOnCiRunnersToken < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_runners_on_token'
+
+ def up
+ remove_concurrent_index_by_name :ci_runners, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :ci_runners,
+ :token,
+ name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221021082734_drop_index_on_ci_runners_token_encrypted.rb b/db/post_migrate/20221021082734_drop_index_on_ci_runners_token_encrypted.rb
new file mode 100644
index 00000000000..39771fb5f85
--- /dev/null
+++ b/db/post_migrate/20221021082734_drop_index_on_ci_runners_token_encrypted.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropIndexOnCiRunnersTokenEncrypted < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_runners_on_token_encrypted'
+
+ def up
+ remove_concurrent_index_by_name :ci_runners, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :ci_runners,
+ :token_encrypted,
+ name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221021145820_create_routing_table_for_builds_metadata_v2.rb b/db/post_migrate/20221021145820_create_routing_table_for_builds_metadata_v2.rb
new file mode 100644
index 00000000000..e5f1ba5cb87
--- /dev/null
+++ b/db/post_migrate/20221021145820_create_routing_table_for_builds_metadata_v2.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class CreateRoutingTableForBuildsMetadataV2 < Gitlab::Database::Migration[2.0]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_builds_metadata
+ PARENT_TABLE_NAME = :p_ci_builds_metadata
+ FIRST_PARTITION = 100
+ PARTITION_COLUMN = :partition_id
+
+ def up
+ return if connection.table_exists?(PARENT_TABLE_NAME) && partition_attached?
+
+ convert_table_to_first_list_partition(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION,
+ lock_tables: [:ci_builds, :ci_builds_metadata]
+ )
+ end
+
+ def down
+ revert_converting_table_to_first_list_partition(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION
+ )
+ end
+
+ private
+
+ def partition_attached?
+ connection.select_value(<<~SQL)
+ SELECT true FROM postgres_partitions WHERE name = '#{TABLE_NAME}';
+ SQL
+ end
+end
diff --git a/db/post_migrate/20221021160735_add_index_for_common_finder_query_desc_with_namespace_id.rb b/db/post_migrate/20221021160735_add_index_for_common_finder_query_desc_with_namespace_id.rb
new file mode 100644
index 00000000000..d7c50010b72
--- /dev/null
+++ b/db/post_migrate/20221021160735_add_index_for_common_finder_query_desc_with_namespace_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexForCommonFinderQueryDescWithNamespaceId < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_group_vulnerability_reads_common_finder_query_desc'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerability_reads,
+ [:namespace_id, :state, :report_type, :severity, :vulnerability_id],
+ name: INDEX_NAME,
+ order: { severity: :desc, vulnerability_id: :desc }
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerability_reads, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221024034228_remove_sprints_project_id_column.rb b/db/post_migrate/20221024034228_remove_sprints_project_id_column.rb
new file mode 100644
index 00000000000..e30d6dce497
--- /dev/null
+++ b/db/post_migrate/20221024034228_remove_sprints_project_id_column.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class RemoveSprintsProjectIdColumn < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ DATERANGE_CONSTRAINT_NAME = 'iteration_start_and_due_daterange_project_id_constraint'
+
+ def up
+ with_lock_retries do
+ remove_column :sprints, :project_id, :bigint if column_exists?(:sprints, :project_id)
+ end
+ end
+
+ def down
+ with_lock_retries do
+ add_column :sprints, :project_id, :bigint unless column_exists?(:sprints, :project_id)
+ end
+
+ with_lock_retries do
+ next if check_constraint_exists?(:sprints, DATERANGE_CONSTRAINT_NAME)
+
+ execute(<<~SQL)
+ ALTER TABLE sprints
+ ADD CONSTRAINT #{DATERANGE_CONSTRAINT_NAME}
+ EXCLUDE USING gist (project_id WITH =, daterange(start_date, due_date, '[]'::text) WITH &&)
+ WHERE (project_id IS NOT NULL)
+ SQL
+ end
+
+ add_check_constraint(:sprints,
+ 'project_id <> NULL::bigint AND group_id IS NULL OR group_id <> NULL::bigint AND project_id IS NULL',
+ 'sprints_must_belong_to_project_or_group')
+
+ add_concurrent_index :sprints, [:project_id, :iid], unique: true, name: 'index_sprints_on_project_id_and_iid'
+
+ add_concurrent_foreign_key :sprints, :projects, column: :project_id, on_delete: :cascade
+ end
+end
diff --git a/db/post_migrate/20221024121500_drop_fingerprint_from_sbom_sources.rb b/db/post_migrate/20221024121500_drop_fingerprint_from_sbom_sources.rb
new file mode 100644
index 00000000000..83856cbe5dd
--- /dev/null
+++ b/db/post_migrate/20221024121500_drop_fingerprint_from_sbom_sources.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class DropFingerprintFromSbomSources < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ remove_column :sbom_sources, :fingerprint, :bytea
+ end
+end
diff --git a/db/post_migrate/20221025115006_check_vulnerabilities_state_transition_from_state_not_equal_to_state.rb b/db/post_migrate/20221025115006_check_vulnerabilities_state_transition_from_state_not_equal_to_state.rb
new file mode 100644
index 00000000000..2ab7f8a9c04
--- /dev/null
+++ b/db/post_migrate/20221025115006_check_vulnerabilities_state_transition_from_state_not_equal_to_state.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class CheckVulnerabilitiesStateTransitionFromStateNotEqualToState < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_check_constraint(:vulnerability_state_transitions, '(from_state != to_state)', constraint_name)
+ end
+
+ def down
+ remove_check_constraint(:vulnerability_state_transitions, constraint_name)
+ end
+
+ private
+
+ def constraint_name
+ check_constraint_name('vulnerability_state_transitions', 'fully_qualified_table_name', 'state_not_equal')
+ end
+end
diff --git a/db/post_migrate/20221025220607_add_index_id_on_scan_finding_approval_merge_request_rules.rb b/db/post_migrate/20221025220607_add_index_id_on_scan_finding_approval_merge_request_rules.rb
new file mode 100644
index 00000000000..4e72e7f95ec
--- /dev/null
+++ b/db/post_migrate/20221025220607_add_index_id_on_scan_finding_approval_merge_request_rules.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexIdOnScanFindingApprovalMergeRequestRules < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'scan_finding_approval_mr_rule_index_id'
+ SCAN_FINDING_REPORT_TYPE = 4
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :approval_merge_request_rules, :id,
+ where: "report_type = #{SCAN_FINDING_REPORT_TYPE}", name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :approval_merge_request_rules, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221027203556_delete_experiment_user_foreign_keys.rb b/db/post_migrate/20221027203556_delete_experiment_user_foreign_keys.rb
new file mode 100644
index 00000000000..564dc3d4899
--- /dev/null
+++ b/db/post_migrate/20221027203556_delete_experiment_user_foreign_keys.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class DeleteExperimentUserForeignKeys < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists :experiment_users, :experiments, name: 'fk_rails_56d4708b4a'
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :experiment_users, :users, name: 'fk_rails_fd805f771a'
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :experiment_users, :experiments, column: :experiment_id, name: 'fk_rails_56d4708b4a'
+ add_concurrent_foreign_key :experiment_users, :users, column: :user_id, name: 'fk_rails_fd805f771a'
+ end
+end
diff --git a/db/post_migrate/20221027203951_drop_experiment_users_table.rb b/db/post_migrate/20221027203951_drop_experiment_users_table.rb
new file mode 100644
index 00000000000..95455db98e5
--- /dev/null
+++ b/db/post_migrate/20221027203951_drop_experiment_users_table.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class DropExperimentUsersTable < Gitlab::Database::Migration[2.0]
+ def up
+ drop_table :experiment_users
+ end
+
+ def down
+ create_table :experiment_users do |t| # rubocop:disable Migration/SchemaAdditionMethodsNoPost
+ t.bigint :experiment_id, null: false
+ t.bigint :user_id, null: false
+ t.integer :group_type, limit: 2, null: false, default: 0
+ t.timestamps_with_timezone null: false
+ t.datetime_with_timezone :converted_at
+ t.jsonb :context, null: false, default: {}
+ end
+
+ add_index :experiment_users, :experiment_id
+ add_index :experiment_users, :user_id
+ end
+end
diff --git a/db/post_migrate/20221028000041_remove_invalid_partial_trigram_indexes_for_issues.rb b/db/post_migrate/20221028000041_remove_invalid_partial_trigram_indexes_for_issues.rb
new file mode 100644
index 00000000000..9b46647047a
--- /dev/null
+++ b/db/post_migrate/20221028000041_remove_invalid_partial_trigram_indexes_for_issues.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveInvalidPartialTrigramIndexesForIssues < Gitlab::Database::Migration[2.0]
+ TITLE_INDEX_NAME = 'index_issues_on_title_trigram_non_latin'
+ DESCRIPTION_INDEX_NAME = 'index_issues_on_description_trigram_non_latin'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :issues, TITLE_INDEX_NAME
+ remove_concurrent_index_by_name :issues, DESCRIPTION_INDEX_NAME
+ end
+
+ def down; end
+end
diff --git a/db/post_migrate/20221028000603_prepare_partial_trigram_indexes_for_issues_attempt_3.rb b/db/post_migrate/20221028000603_prepare_partial_trigram_indexes_for_issues_attempt_3.rb
new file mode 100644
index 00000000000..199a7a22d5b
--- /dev/null
+++ b/db/post_migrate/20221028000603_prepare_partial_trigram_indexes_for_issues_attempt_3.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class PreparePartialTrigramIndexesForIssuesAttempt3 < Gitlab::Database::Migration[2.0]
+ TITLE_INDEX_NAME = 'index_issues_on_title_trigram_non_latin'
+ DESCRIPTION_INDEX_NAME = 'index_issues_on_description_trigram_non_latin'
+
+ def up
+ prepare_async_index :issues, :title,
+ name: TITLE_INDEX_NAME,
+ using: :gin, opclass: { description: :gin_trgm_ops },
+ where: "title NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*' " \
+ "OR description NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*'"
+
+ prepare_async_index :issues, :description,
+ name: DESCRIPTION_INDEX_NAME,
+ using: :gin, opclass: { description: :gin_trgm_ops },
+ where: "title NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*' " \
+ "OR description NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*'"
+ end
+
+ def down
+ unprepare_async_index_by_name :issues, DESCRIPTION_INDEX_NAME
+ unprepare_async_index_by_name :issues, TITLE_INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221028022627_add_index_on_password_last_changed_at_to_user_details.rb b/db/post_migrate/20221028022627_add_index_on_password_last_changed_at_to_user_details.rb
new file mode 100644
index 00000000000..8314767ade1
--- /dev/null
+++ b/db/post_migrate/20221028022627_add_index_on_password_last_changed_at_to_user_details.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexOnPasswordLastChangedAtToUserDetails < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_user_details_on_password_last_changed_at'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :user_details, :password_last_changed_at, name: INDEX_NAME, comment: 'JiHu-specific index'
+ end
+
+ def down
+ remove_concurrent_index_by_name :user_details, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221102090940_create_next_ci_partitions_record.rb b/db/post_migrate/20221102090940_create_next_ci_partitions_record.rb
new file mode 100644
index 00000000000..4bd89a70daa
--- /dev/null
+++ b/db/post_migrate/20221102090940_create_next_ci_partitions_record.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class CreateNextCiPartitionsRecord < Gitlab::Database::Migration[2.0]
+ NEXT_PARTITION_ID = 101
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ def up
+ return unless Gitlab.com?
+
+ execute(<<~SQL)
+ INSERT INTO "ci_partitions" ("id", "created_at", "updated_at")
+ VALUES (#{NEXT_PARTITION_ID}, now(), now())
+ ON CONFLICT DO NOTHING;
+ SQL
+
+ reset_pk_sequence!('ci_partitions')
+ end
+
+ def down
+ return unless Gitlab.com?
+
+ execute(<<~SQL)
+ DELETE FROM "ci_partitions"
+ WHERE "ci_partitions"."id" = #{NEXT_PARTITION_ID};
+ SQL
+ end
+end
diff --git a/db/post_migrate/20221102090943_create_second_partition_for_builds_metadata.rb b/db/post_migrate/20221102090943_create_second_partition_for_builds_metadata.rb
new file mode 100644
index 00000000000..6923e6f6cba
--- /dev/null
+++ b/db/post_migrate/20221102090943_create_second_partition_for_builds_metadata.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+class CreateSecondPartitionForBuildsMetadata < Gitlab::Database::Migration[2.0]
+ TABLE_NAME = 'p_ci_builds_metadata'
+ BUILDS_TABLE = 'ci_builds'
+ NEXT_PARTITION_ID = 101
+ PARTITION_NAME = 'gitlab_partitions_dynamic.ci_builds_metadata_101'
+
+ disable_ddl_transaction!
+
+ def up
+ return unless Gitlab.com?
+
+ with_lock_retries(**lock_args) do
+ connection.execute(<<~SQL)
+ LOCK TABLE #{BUILDS_TABLE} IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK TABLE ONLY #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE;
+ SQL
+
+ connection.execute(<<~SQL)
+ CREATE TABLE IF NOT EXISTS #{PARTITION_NAME}
+ PARTITION OF #{TABLE_NAME}
+ FOR VALUES IN (#{NEXT_PARTITION_ID});
+ SQL
+ end
+ end
+
+ def down
+ return unless Gitlab.com?
+ return unless table_exists?(PARTITION_NAME)
+
+ with_lock_retries(**lock_args) do
+ connection.execute(<<~SQL)
+ LOCK TABLE #{BUILDS_TABLE}, #{TABLE_NAME}, #{PARTITION_NAME} IN ACCESS EXCLUSIVE MODE;
+ SQL
+
+ connection.execute(<<~SQL)
+ ALTER TABLE #{TABLE_NAME} DETACH PARTITION #{PARTITION_NAME};
+ SQL
+
+ connection.execute(<<~SQL)
+ DROP TABLE IF EXISTS #{PARTITION_NAME} CASCADE;
+ SQL
+ end
+ end
+
+ private
+
+ def lock_args
+ {
+ raise_on_exhaustion: true,
+ timing_configuration: lock_timing_configuration
+ }
+ end
+
+ def lock_timing_configuration
+ iterations = Gitlab::Database::WithLockRetries::DEFAULT_TIMING_CONFIGURATION
+ aggressive_iterations = Array.new(5) { [10.seconds, 1.minute] }
+
+ iterations + aggressive_iterations
+ end
+end
diff --git a/db/post_migrate/20221103073328_change_member_namespace_id_not_null.rb b/db/post_migrate/20221103073328_change_member_namespace_id_not_null.rb
new file mode 100644
index 00000000000..19f6732d297
--- /dev/null
+++ b/db/post_migrate/20221103073328_change_member_namespace_id_not_null.rb
@@ -0,0 +1,16 @@
+# 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 ChangeMemberNamespaceIdNotNull < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_not_null_constraint :members, :member_namespace_id, validate: false
+ end
+
+ def down
+ remove_not_null_constraint :members, :member_namespace_id
+ end
+end
diff --git a/db/post_migrate/20221103084213_remove_tmp_index_members_on_id_where_namespace_id_null.rb b/db/post_migrate/20221103084213_remove_tmp_index_members_on_id_where_namespace_id_null.rb
new file mode 100644
index 00000000000..07908e697f5
--- /dev/null
+++ b/db/post_migrate/20221103084213_remove_tmp_index_members_on_id_where_namespace_id_null.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveTmpIndexMembersOnIdWhereNamespaceIdNull < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'tmp_index_members_on_id_where_namespace_id_null'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :members, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :members, :id, name: INDEX_NAME, where: 'member_namespace_id IS NULL'
+ end
+end
diff --git a/db/post_migrate/20221103150250_migrate_sidekiq_queued_jobs.rb b/db/post_migrate/20221103150250_migrate_sidekiq_queued_jobs.rb
new file mode 100644
index 00000000000..1934711f9ef
--- /dev/null
+++ b/db/post_migrate/20221103150250_migrate_sidekiq_queued_jobs.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class MigrateSidekiqQueuedJobs < Gitlab::Database::Migration[2.0]
+ def up
+ # no-op because of https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/1991
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221104042137_add_partial_trigram_index_for_issue_title_attempt_2.rb b/db/post_migrate/20221104042137_add_partial_trigram_index_for_issue_title_attempt_2.rb
new file mode 100644
index 00000000000..24204577959
--- /dev/null
+++ b/db/post_migrate/20221104042137_add_partial_trigram_index_for_issue_title_attempt_2.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddPartialTrigramIndexForIssueTitleAttempt2 < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_issues_on_title_trigram_non_latin'
+
+ def up
+ add_concurrent_index :issues, :title,
+ name: INDEX_NAME,
+ using: :gin, opclass: { description: :gin_trgm_ops },
+ where: "title NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*' " \
+ "OR description NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*'"
+ end
+
+ def down
+ remove_concurrent_index_by_name :issues, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221104042159_add_partial_trigram_index_for_issue_description_attempt_2.rb b/db/post_migrate/20221104042159_add_partial_trigram_index_for_issue_description_attempt_2.rb
new file mode 100644
index 00000000000..36b595d1067
--- /dev/null
+++ b/db/post_migrate/20221104042159_add_partial_trigram_index_for_issue_description_attempt_2.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddPartialTrigramIndexForIssueDescriptionAttempt2 < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_issues_on_description_trigram_non_latin'
+
+ def up
+ add_concurrent_index :issues, :description,
+ name: INDEX_NAME,
+ using: :gin, opclass: { description: :gin_trgm_ops },
+ where: "title NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*' " \
+ "OR description NOT SIMILAR TO '[\\u0000-\\u02FF\\u1E00-\\u1EFF\\u2070-\\u218F]*'"
+ end
+
+ def down
+ remove_concurrent_index_by_name :issues, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221104074652_add_temp_index_for_project_statistics_upload_size_migration.rb b/db/post_migrate/20221104074652_add_temp_index_for_project_statistics_upload_size_migration.rb
new file mode 100644
index 00000000000..b6ee636fa9b
--- /dev/null
+++ b/db/post_migrate/20221104074652_add_temp_index_for_project_statistics_upload_size_migration.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddTempIndexForProjectStatisticsUploadSizeMigration < Gitlab::Database::Migration[2.0]
+ INDEX_PROJECT_STATSISTICS_UPLOADS_SIZE = 'tmp_index_project_statistics_uploads_size'
+
+ disable_ddl_transaction!
+
+ def up
+ # Temporary index is to be used to trigger refresh for all project_statistics with
+ # upload_size <> 0
+ add_concurrent_index :project_statistics, [:project_id],
+ name: INDEX_PROJECT_STATSISTICS_UPLOADS_SIZE,
+ where: "uploads_size <> 0"
+ end
+
+ def down
+ remove_concurrent_index_by_name :project_statistics, INDEX_PROJECT_STATSISTICS_UPLOADS_SIZE
+ end
+end
diff --git a/db/post_migrate/20221104100203_recreate_async_trigram_index_for_vulnerability_reads_container_images.rb b/db/post_migrate/20221104100203_recreate_async_trigram_index_for_vulnerability_reads_container_images.rb
new file mode 100644
index 00000000000..ea2914f4dc4
--- /dev/null
+++ b/db/post_migrate/20221104100203_recreate_async_trigram_index_for_vulnerability_reads_container_images.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class RecreateAsyncTrigramIndexForVulnerabilityReadsContainerImages < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_vulnerability_reads_on_location_image_trigram'
+ REPORT_TYPES = { container_scanning: 2, cluster_image_scanning: 7 }.freeze
+
+ def up
+ remove_concurrent_index_by_name :vulnerability_reads, INDEX_NAME
+
+ prepare_async_index :vulnerability_reads, :location_image,
+ name: INDEX_NAME,
+ using: :gin, opclass: { location_image: :gin_trgm_ops },
+ where: "report_type = ANY (ARRAY[#{REPORT_TYPES.values.join(', ')}]) AND location_image IS NOT NULL"
+ end
+
+ def down
+ unprepare_async_index :vulnerability_reads, :location_image, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221104170500_add_vulnerability_reads_all_status_index.rb b/db/post_migrate/20221104170500_add_vulnerability_reads_all_status_index.rb
new file mode 100644
index 00000000000..1dc1921ebaa
--- /dev/null
+++ b/db/post_migrate/20221104170500_add_vulnerability_reads_all_status_index.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+class AddVulnerabilityReadsAllStatusIndex < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_vulnerability_reads_on_namespace_type_severity_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerability_reads, %i[namespace_id report_type severity vulnerability_id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerability_reads, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221104190203_validate_environment_id_on_deployments.rb b/db/post_migrate/20221104190203_validate_environment_id_on_deployments.rb
new file mode 100644
index 00000000000..9546daa3975
--- /dev/null
+++ b/db/post_migrate/20221104190203_validate_environment_id_on_deployments.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateEnvironmentIdOnDeployments < Gitlab::Database::Migration[2.0]
+ def up
+ validate_foreign_key :deployments, :environment_id
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221107094359_recount_epic_cache_counts.rb b/db/post_migrate/20221107094359_recount_epic_cache_counts.rb
new file mode 100644
index 00000000000..37ab952edba
--- /dev/null
+++ b/db/post_migrate/20221107094359_recount_epic_cache_counts.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class RecountEpicCacheCounts < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'RecountEpicCacheCounts'
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 200
+ MAX_BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 20
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :epics,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE,
+ gitlab_schema: :gitlab_main
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :epics, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221107184758_sync_new_amount_used_for_ci_namespace_monthly_usages.rb b/db/post_migrate/20221107184758_sync_new_amount_used_for_ci_namespace_monthly_usages.rb
new file mode 100644
index 00000000000..9a6014b5c94
--- /dev/null
+++ b/db/post_migrate/20221107184758_sync_new_amount_used_for_ci_namespace_monthly_usages.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class SyncNewAmountUsedForCiNamespaceMonthlyUsages < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ def up
+ namespace_usages = define_batchable_model('ci_namespace_monthly_usages')
+
+ namespace_usages.each_batch(of: 500) do |batch|
+ batch.where('amount_used > 0').update_all('new_amount_used = amount_used')
+ end
+ end
+
+ def down
+ # Non reversible migration.
+ # This data migration keeps `new_amount_used` in sync with the old `amount_used`.
+ # In case of failure or interruption the migration can be retried.
+ end
+end
diff --git a/db/post_migrate/20221107220420_validate_not_null_constraint_on_member_namespace_id.rb b/db/post_migrate/20221107220420_validate_not_null_constraint_on_member_namespace_id.rb
new file mode 100644
index 00000000000..48da0c1fd09
--- /dev/null
+++ b/db/post_migrate/20221107220420_validate_not_null_constraint_on_member_namespace_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class ValidateNotNullConstraintOnMemberNamespaceId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'check_508774aac0'
+
+ def up
+ validate_not_null_constraint :members, :member_namespace_id, constraint_name: CONSTRAINT_NAME
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221107220526_validate_fk_member_namespace_id.rb b/db/post_migrate/20221107220526_validate_fk_member_namespace_id.rb
new file mode 100644
index 00000000000..f78dc5a36fd
--- /dev/null
+++ b/db/post_migrate/20221107220526_validate_fk_member_namespace_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ValidateFkMemberNamespaceId < Gitlab::Database::Migration[2.0]
+ CONSTRAINT_NAME = 'fk_2f85abf8f1'
+
+ def up
+ validate_foreign_key :members, :member_namespace_id, name: CONSTRAINT_NAME
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221107222213_remove_old_member_namespace_id_fk.rb b/db/post_migrate/20221107222213_remove_old_member_namespace_id_fk.rb
new file mode 100644
index 00000000000..d46fa80336e
--- /dev/null
+++ b/db/post_migrate/20221107222213_remove_old_member_namespace_id_fk.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class RemoveOldMemberNamespaceIdFk < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ TARGET_COLUMN = :member_namespace_id
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:members, column: TARGET_COLUMN, name: fk_name(TARGET_COLUMN))
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(
+ :members,
+ :namespaces,
+ column: TARGET_COLUMN,
+ name: fk_name(TARGET_COLUMN),
+ on_delete: :nullify
+ )
+ end
+
+ def fk_name(column_name)
+ # generate a FK name
+ concurrent_foreign_key_name(:members, column_name)
+ end
+end
diff --git a/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb b/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb
new file mode 100644
index 00000000000..37e6a21abed
--- /dev/null
+++ b/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class TruncateTimelineEventTagsTable < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ execute('TRUNCATE TABLE incident_management_timeline_event_tags, incident_management_timeline_event_tag_links')
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221108121322_add_supporting_index_for_vulnerabilities_feedback_migration.rb b/db/post_migrate/20221108121322_add_supporting_index_for_vulnerabilities_feedback_migration.rb
new file mode 100644
index 00000000000..c77930512d2
--- /dev/null
+++ b/db/post_migrate/20221108121322_add_supporting_index_for_vulnerabilities_feedback_migration.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class AddSupportingIndexForVulnerabilitiesFeedbackMigration < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = "tmp_idx_for_vulnerability_feedback_migration"
+ WHERE_CLAUSE = "migrated_to_state_transition = false AND feedback_type = 0"
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(
+ :vulnerability_feedback,
+ %i[migrated_to_state_transition feedback_type],
+ where: WHERE_CLAUSE,
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name(
+ :vulnerability_feedback,
+ INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20221108222015_remove_temp_index_on_project_features_where_releases_access_level_gt_repository.rb b/db/post_migrate/20221108222015_remove_temp_index_on_project_features_where_releases_access_level_gt_repository.rb
new file mode 100644
index 00000000000..e7cc6786b4b
--- /dev/null
+++ b/db/post_migrate/20221108222015_remove_temp_index_on_project_features_where_releases_access_level_gt_repository.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveTempIndexOnProjectFeaturesWhereReleasesAccessLevelGtRepository < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'tmp_idx_project_features_on_releases_al_and_repo_al_partial'
+
+ def up
+ remove_concurrent_index_by_name :project_features, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :project_features,
+ [:releases_access_level, :repository_access_level],
+ name: INDEX_NAME,
+ where: 'releases_access_level > repository_access_level'
+ end
+end
diff --git a/db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb b/db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb
new file mode 100644
index 00000000000..f98be3f036f
--- /dev/null
+++ b/db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class SanitizeConfidentialNoteTodos < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'SanitizeConfidentialTodos'
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 200
+ MAX_BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 20
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :notes,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE,
+ gitlab_schema: :gitlab_main
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :notes, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221111070314_prepare_removal_of_issue_trigram_indexes.rb b/db/post_migrate/20221111070314_prepare_removal_of_issue_trigram_indexes.rb
new file mode 100644
index 00000000000..c4cae19497e
--- /dev/null
+++ b/db/post_migrate/20221111070314_prepare_removal_of_issue_trigram_indexes.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class PrepareRemovalOfIssueTrigramIndexes < Gitlab::Database::Migration[2.0]
+ TITLE_INDEX_NAME = 'index_issues_on_title_trigram'
+ DESCRIPTION_INDEX_NAME = 'index_issues_on_description_trigram'
+
+ def up
+ prepare_async_index_removal :issues, :title, name: TITLE_INDEX_NAME
+ prepare_async_index_removal :issues, :description, name: DESCRIPTION_INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index_by_name :issues, DESCRIPTION_INDEX_NAME
+ unprepare_async_index_by_name :issues, TITLE_INDEX_NAME
+ end
+end