diff options
Diffstat (limited to 'db/post_migrate')
72 files changed, 992 insertions, 202 deletions
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 bb444f5b407..0d610f1dde1 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 @@ -11,7 +11,7 @@ class BackfillPushEventPayloadEventIdForBigintConversion < ActiveRecord::Migrati return unless should_run? backfill_conversion_of_integer_to_bigint :push_event_payloads, :event_id, primary_key: :event_id, - batch_size: 15000, sub_batch_size: 100 + batch_size: 15000, sub_batch_size: 100 end def down diff --git a/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb b/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb index 7d4d97acf58..0f6cf970778 100644 --- a/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb +++ b/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb @@ -1,23 +1,12 @@ # frozen_string_literal: true class ScheduleUpdateJiraTrackerDataDeploymentTypeBasedOnUrl < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'UpdateJiraTrackerDataDeploymentTypeBasedOnUrl' - DELAY_INTERVAL = 2.minutes.to_i - BATCH_SIZE = 2_500 - - disable_ddl_transaction! - def up - say "Scheduling #{MIGRATION} jobs" - queue_background_migration_jobs_by_range_at_intervals( - define_batchable_model('jira_tracker_data'), - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) + # no-op (being re-run in 20220324152945_update_jira_tracker_data_deployment_type_based_on_url.rb) + # due to this migration causing this issue: https://gitlab.com/gitlab-org/gitlab/-/issues/336849 + # The migration is rescheduled in + # db/post_migrate/20220725150127_update_jira_tracker_data_deployment_type_based_on_url.rb + # Related discussion: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82103#note_862401816 end def down diff --git a/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb b/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb index 715bc392c68..1f0bdfc5012 100644 --- a/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb +++ b/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb @@ -31,7 +31,7 @@ class FinalizeEventsBigintConversion < ActiveRecord::Migration[6.1] add_concurrent_index TABLE_NAME, [:project_id, :id_convert_to_bigint], name: 'index_events_on_project_id_and_id_convert_to_bigint' # This is to replace the existing "index_events_on_project_id_and_id_desc_on_merged_action" btree (project_id, id DESC) WHERE action = 7 add_concurrent_index TABLE_NAME, [:project_id, :id_convert_to_bigint], order: { id_convert_to_bigint: :desc }, - where: "action = 7", name: 'index_events_on_project_id_and_id_bigint_desc_on_merged_action' + where: "action = 7", name: 'index_events_on_project_id_and_id_bigint_desc_on_merged_action' # Add a FK on `push_event_payloads(event_id)` to `id_convert_to_bigint`, the old FK (fk_36c74129da) # will be removed when events_pkey constraint is droppped. diff --git a/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb b/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb index 161366590be..776f1ad545d 100644 --- a/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb +++ b/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb @@ -30,7 +30,7 @@ class FinalizeCiBuildsStageIdBigintConversion < ActiveRecord::Migration[6.1] # Create a copy of the original column's FK on the new column add_concurrent_foreign_key TABLE_NAME, :ci_stages, column: :stage_id_convert_to_bigint, on_delete: :cascade, - reverse_lock_order: true + reverse_lock_order: true with_lock_retries(raise_on_exhaustion: true) do quoted_table_name = quote_table_name(TABLE_NAME) diff --git a/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb b/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb index dbefbeb26cb..f3ce32ad9c8 100644 --- a/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb +++ b/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb @@ -37,10 +37,10 @@ class FinalizeCiStagesBigintConversion < ActiveRecord::Migration[6.1] fk_stage_id = concurrent_foreign_key_name(:ci_builds, :stage_id) fk_stage_id_tmp = "#{fk_stage_id}_tmp" add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, - target_column: :id_convert_to_bigint, - name: fk_stage_id_tmp, - on_delete: :cascade, - reverse_lock_order: true + target_column: :id_convert_to_bigint, + name: fk_stage_id_tmp, + on_delete: :cascade, + reverse_lock_order: true # Now it's time to do things in a transaction with_lock_retries(raise_on_exhaustion: true) do @@ -58,7 +58,7 @@ class FinalizeCiStagesBigintConversion < ActiveRecord::Migration[6.1] # Swap defaults execute "ALTER SEQUENCE ci_stages_id_seq OWNED BY #{TABLE_NAME}.id" - change_column_default TABLE_NAME, :id, -> { "nextval('ci_stages_id_seq'::regclass)"} + change_column_default TABLE_NAME, :id, -> { "nextval('ci_stages_id_seq'::regclass)" } change_column_default TABLE_NAME, :id_convert_to_bigint, 0 # Swap pkey constraint diff --git a/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb b/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb index c2444ccbc6c..3879c3c368a 100644 --- a/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb +++ b/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb @@ -40,7 +40,7 @@ class FinalizeCiBuildsMetadataBigintConversion < Gitlab::Database::Migration[1.0 # rubocop:enable Migration/PreventIndexCreation add_concurrent_foreign_key TABLE_NAME, :ci_builds, column: :build_id_convert_to_bigint, on_delete: :cascade, - reverse_lock_order: true + reverse_lock_order: true with_lock_retries(raise_on_exhaustion: true) do execute "LOCK TABLE ci_builds, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" diff --git a/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb b/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb index 6dab29e10d4..289b77f0a5c 100644 --- a/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb +++ b/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb @@ -29,8 +29,8 @@ class FinalizePushEventPayloadsBigintConversion3 < ActiveRecord::Migration[6.1] def already_swapped? push_event_payloads_columns = columns(TABLE_NAME) - event_id = push_event_payloads_columns.find {|c| c.name == 'event_id'} - event_id_convert_to_bigint = push_event_payloads_columns.find {|c| c.name == 'event_id_convert_to_bigint'} + event_id = push_event_payloads_columns.find { |c| c.name == 'event_id' } + event_id_convert_to_bigint = push_event_payloads_columns.find { |c| c.name == 'event_id_convert_to_bigint' } event_id.sql_type == 'bigint' && event_id_convert_to_bigint.sql_type == 'integer' end @@ -40,7 +40,7 @@ class FinalizePushEventPayloadsBigintConversion3 < ActiveRecord::Migration[6.1] # Add a foreign key on `event_id_convert_to_bigint` before we swap the columns and drop the old FK (fk_36c74129da) add_concurrent_foreign_key TABLE_NAME, :events, column: :event_id_convert_to_bigint, - on_delete: :cascade, reverse_lock_order: true + on_delete: :cascade, reverse_lock_order: true with_lock_retries(raise_on_exhaustion: true) do # We'll need ACCESS EXCLUSIVE lock on the related tables, diff --git a/db/post_migrate/20210804151444_prepare_indexes_for_ci_job_artifact_bigint_conversion.rb b/db/post_migrate/20210804151444_prepare_indexes_for_ci_job_artifact_bigint_conversion.rb index 8115465e311..81e73effe7b 100644 --- a/db/post_migrate/20210804151444_prepare_indexes_for_ci_job_artifact_bigint_conversion.rb +++ b/db/post_migrate/20210804151444_prepare_indexes_for_ci_job_artifact_bigint_conversion.rb @@ -5,19 +5,23 @@ class PrepareIndexesForCiJobArtifactBigintConversion < ActiveRecord::Migration[6 def up prepare_async_index :ci_job_artifacts, :id_convert_to_bigint, unique: true, - name: :index_ci_job_artifact_on_id_convert_to_bigint + name: :index_ci_job_artifact_on_id_convert_to_bigint - prepare_async_index :ci_job_artifacts, [:project_id, :id_convert_to_bigint], where: 'file_type = 18', - name: :index_ci_job_artifacts_for_terraform_reports_bigint + prepare_async_index :ci_job_artifacts, + [:project_id, :id_convert_to_bigint], + where: 'file_type = 18', name: :index_ci_job_artifacts_for_terraform_reports_bigint - prepare_async_index :ci_job_artifacts, :id_convert_to_bigint, where: 'file_type = 18', - name: :index_ci_job_artifacts_id_for_terraform_reports_bigint + prepare_async_index :ci_job_artifacts, :id_convert_to_bigint, + where: 'file_type = 18', + name: :index_ci_job_artifacts_id_for_terraform_reports_bigint - prepare_async_index :ci_job_artifacts, [:expire_at, :job_id_convert_to_bigint], - name: :index_ci_job_artifacts_on_expire_at_and_job_id_bigint + prepare_async_index :ci_job_artifacts, + [:expire_at, :job_id_convert_to_bigint], + name: :index_ci_job_artifacts_on_expire_at_and_job_id_bigint - prepare_async_index :ci_job_artifacts, [:job_id_convert_to_bigint, :file_type], unique: true, - name: :index_ci_job_artifacts_on_job_id_and_file_type_bigint + prepare_async_index :ci_job_artifacts, + [:job_id_convert_to_bigint, :file_type], + unique: true, name: :index_ci_job_artifacts_on_job_id_and_file_type_bigint end def down diff --git a/db/post_migrate/20210804153307_prepare_indexes_for_tagging_bigint_conversion.rb b/db/post_migrate/20210804153307_prepare_indexes_for_tagging_bigint_conversion.rb index 98f90bafce3..ab6691dea1f 100644 --- a/db/post_migrate/20210804153307_prepare_indexes_for_tagging_bigint_conversion.rb +++ b/db/post_migrate/20210804153307_prepare_indexes_for_tagging_bigint_conversion.rb @@ -5,7 +5,7 @@ class PrepareIndexesForTaggingBigintConversion < ActiveRecord::Migration[6.1] def up prepare_async_index :taggings, :id_convert_to_bigint, unique: true, - name: :index_taggings_on_id_convert_to_bigint + name: :index_taggings_on_id_convert_to_bigint prepare_async_index :taggings, [:taggable_id_convert_to_bigint, :taggable_type], name: :i_taggings_on_taggable_id_convert_to_bigint_and_taggable_type diff --git a/db/post_migrate/20210804154407_prepare_indexes_for_ci_stage_bigint_conversion.rb b/db/post_migrate/20210804154407_prepare_indexes_for_ci_stage_bigint_conversion.rb index 82af595b2d3..16f3e87000c 100644 --- a/db/post_migrate/20210804154407_prepare_indexes_for_ci_stage_bigint_conversion.rb +++ b/db/post_migrate/20210804154407_prepare_indexes_for_ci_stage_bigint_conversion.rb @@ -5,14 +5,16 @@ class PrepareIndexesForCiStageBigintConversion < ActiveRecord::Migration[6.1] def up prepare_async_index :ci_stages, :id_convert_to_bigint, unique: true, - name: :index_ci_stages_on_id_convert_to_bigint + name: :index_ci_stages_on_id_convert_to_bigint - prepare_async_index :ci_stages, [:pipeline_id, :id_convert_to_bigint], where: 'status in (0, 1, 2, 8, 9, 10)', - name: :index_ci_stages_on_pipeline_id_and_id_convert_to_bigint + prepare_async_index :ci_stages, [:pipeline_id, :id_convert_to_bigint], + where: 'status in (0, 1, 2, 8, 9, 10)', + name: :index_ci_stages_on_pipeline_id_and_id_convert_to_bigint end def down - unprepare_async_index_by_name :ci_stages, :index_ci_stages_on_pipeline_id_and_id_convert_to_bigint + unprepare_async_index_by_name :ci_stages, + :index_ci_stages_on_pipeline_id_and_id_convert_to_bigint unprepare_async_index_by_name :ci_stages, :index_ci_stages_on_id_convert_to_bigint end diff --git a/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb b/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb index b8f843fdd50..074ba97da65 100644 --- a/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb +++ b/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb @@ -1,32 +1,8 @@ # frozen_string_literal: true class ScheduleCopyCiBuildsColumnsToSecurityScans2 < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - INTERVAL = 2.minutes.to_i - BATCH_SIZE = 5_000 - MIGRATION = 'CopyCiBuildsColumnsToSecurityScans' - - disable_ddl_transaction! - - class SecurityScan < ActiveRecord::Base - include EachBatch - - self.table_name = 'security_scans' - end - def up - SecurityScan.reset_column_information - - delete_job_tracking(MIGRATION, status: %w[pending succeeded]) - - queue_background_migration_jobs_by_range_at_intervals( - SecurityScan, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE, - track_jobs: true - ) + # no-op: Must have run before %"15.X" as it is not compatible with decomposed CI database end def down diff --git a/db/post_migrate/20210817024335_prepare_indexes_for_events_bigint_conversion.rb b/db/post_migrate/20210817024335_prepare_indexes_for_events_bigint_conversion.rb index 1d102d6216c..e1ed28f6826 100644 --- a/db/post_migrate/20210817024335_prepare_indexes_for_events_bigint_conversion.rb +++ b/db/post_migrate/20210817024335_prepare_indexes_for_events_bigint_conversion.rb @@ -7,13 +7,14 @@ class PrepareIndexesForEventsBigintConversion < ActiveRecord::Migration[6.1] def up prepare_async_index TABLE_NAME, :id_convert_to_bigint, unique: true, - name: :index_events_on_id_convert_to_bigint + name: :index_events_on_id_convert_to_bigint prepare_async_index TABLE_NAME, [:project_id, :id_convert_to_bigint], name: :index_events_on_project_id_and_id_convert_to_bigint - prepare_async_index TABLE_NAME, [:project_id, :id_convert_to_bigint], order: { id_convert_to_bigint: :desc }, - where: 'action = 7', name: :index_events_on_project_id_and_id_bigint_desc_on_merged_action + prepare_async_index TABLE_NAME, [:project_id, :id_convert_to_bigint], + order: { id_convert_to_bigint: :desc }, + where: 'action = 7', name: :index_events_on_project_id_and_id_bigint_desc_on_merged_action end def down diff --git a/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb b/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb index f63645b4ffa..bf95aa98295 100644 --- a/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb +++ b/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb @@ -5,13 +5,13 @@ class PrepareCiBuildsMetadataAndCiBuildAsyncIndexes < ActiveRecord::Migration[6. def up prepare_async_index :ci_builds_metadata, :id_convert_to_bigint, unique: true, - name: :index_ci_builds_metadata_on_id_convert_to_bigint + name: :index_ci_builds_metadata_on_id_convert_to_bigint prepare_async_index :ci_builds_metadata, :build_id_convert_to_bigint, unique: true, - name: :index_ci_builds_metadata_on_build_id_convert_to_bigint + name: :index_ci_builds_metadata_on_build_id_convert_to_bigint prepare_async_index :ci_builds_metadata, :build_id_convert_to_bigint, where: 'has_exposed_artifacts IS TRUE', - name: :index_ci_builds_metadata_on_build_id_int8_and_exposed_artifacts + name: :index_ci_builds_metadata_on_build_id_int8_and_exposed_artifacts prepare_async_index_from_sql(:ci_builds_metadata, :index_ci_builds_metadata_on_build_id_int8_where_interruptible, <<~SQL.squish) CREATE INDEX CONCURRENTLY "index_ci_builds_metadata_on_build_id_int8_where_interruptible" @@ -20,7 +20,7 @@ class PrepareCiBuildsMetadataAndCiBuildAsyncIndexes < ActiveRecord::Migration[6. SQL prepare_async_index :ci_builds, :id_convert_to_bigint, unique: true, - name: :index_ci_builds_on_converted_id + name: :index_ci_builds_on_converted_id end def down diff --git a/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb b/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb index f350fbe3d12..1f6650140d4 100644 --- a/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb +++ b/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb @@ -20,7 +20,7 @@ class BackfillCadenceIdForBoardsScopedToIteration < Gitlab::Database::Migration[ def down MigrationBoard.where.not(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first + range = batch.pick(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')) delay = index * DELAY migrate_in(delay, MIGRATION, ['none', 'down', *range]) @@ -31,7 +31,7 @@ class BackfillCadenceIdForBoardsScopedToIteration < Gitlab::Database::Migration[ def schedule_backfill_project_boards MigrationBoard.where(iteration_id: -4).where.not(project_id: nil).where(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first + range = batch.pick(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')) delay = index * DELAY migrate_in(delay, MIGRATION, ['project', 'up', *range]) @@ -40,7 +40,7 @@ class BackfillCadenceIdForBoardsScopedToIteration < Gitlab::Database::Migration[ def schedule_backfill_group_boards MigrationBoard.where(iteration_id: -4).where.not(group_id: nil).where(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first + range = batch.pick(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')) delay = index * DELAY migrate_in(delay, MIGRATION, ['group', 'up', *range]) diff --git a/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb b/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb index 7544842c196..f164cdbf379 100644 --- a/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb +++ b/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb @@ -200,8 +200,7 @@ class FinalizeCiBuildsBigintConversion < Gitlab::Database::Migration[1.0] column: column, target_column: :id_convert_to_bigint, name: temporary_name, - on_delete: on_delete, - reverse_lock_order: true) + on_delete: on_delete) end end @@ -214,9 +213,6 @@ class FinalizeCiBuildsBigintConversion < Gitlab::Database::Migration[1.0] next unless foreign_key_exists?(from_table, TABLE_NAME, column: column, primary_key: :id, name: existing_name) with_lock_retries do - # Explicitly lock table in order of parent, child to attempt to avoid deadlocks - execute "LOCK TABLE #{TABLE_NAME}, #{from_table} IN ACCESS EXCLUSIVE MODE" - temporary_name = "#{existing_name}_tmp" remove_foreign_key(from_table, TABLE_NAME, column: column, primary_key: :id, name: existing_name) diff --git a/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb b/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb index 2e6ad12f928..3a758394d7f 100644 --- a/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb +++ b/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb @@ -1,52 +1,11 @@ # frozen_string_literal: true class DisableJobTokenScopeWhenUnused < Gitlab::Database::Migration[1.0] - disable_ddl_transaction! - - class ProjectCiCdSetting < ApplicationRecord - include EachBatch - - self.table_name = 'project_ci_cd_settings' - end - - module Ci - module JobToken - class ProjectScopeLink < ApplicationRecord - self.table_name = 'ci_job_token_project_scope_links' - end - end - end - def up - # Disabling job token scope after db/migrate/20210902171808_set_default_job_token_scope_false.rb - # if users haven't configured it. - ProjectCiCdSetting.each_batch(of: 10_000) do |settings| - with_enabled_but_unused_scope(settings).each_batch(of: 500) do |settings_to_update| - settings_to_update.update_all(job_token_scope_enabled: false) - end - end + # no-op: Must have run before %"15.X" as it is not compatible with decomposed CI database end def down - # irreversible data migration - - # The migration relies on the state of `job_token_scope_enabled` and - # updates it based on whether the feature is used or not. - # - # The inverse migration would be to set `job_token_scope_enabled: true` - # for those projects that have the feature disabled and unused. But there - # could be also existing cases where the feature is disabled and unused. - # For example, old projects. - end - - private - - # The presence of ProjectScopeLinks means that the job token scope - # is configured and we need to leave it enabled. Unused job token scope - # can be disabled since they weren't configured. - def with_enabled_but_unused_scope(settings) - settings - .where(job_token_scope_enabled: true) - .where.not(project_id: Ci::JobToken::ProjectScopeLink.select(:source_project_id)) + # no-op end end diff --git a/db/post_migrate/20211007155221_schedule_populate_status_column_of_security_scans.rb b/db/post_migrate/20211007155221_schedule_populate_status_column_of_security_scans.rb index 03032dfbb0a..04af23446fd 100644 --- a/db/post_migrate/20211007155221_schedule_populate_status_column_of_security_scans.rb +++ b/db/post_migrate/20211007155221_schedule_populate_status_column_of_security_scans.rb @@ -1,21 +1,8 @@ # frozen_string_literal: true class SchedulePopulateStatusColumnOfSecurityScans < Gitlab::Database::Migration[1.0] - MIGRATION = 'PopulateStatusColumnOfSecurityScans' - BATCH_SIZE = 10_000 - DELAY_INTERVAL = 2.minutes - - disable_ddl_transaction! - def up - return unless Gitlab.ee? - - queue_background_migration_jobs_by_range_at_intervals( - define_batchable_model('security_scans'), - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) + # no-op end def down diff --git a/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb b/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb index 3d39148f402..e42b74748d7 100644 --- a/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb +++ b/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb @@ -1,20 +1,8 @@ # frozen_string_literal: true class ScheduleBackfillCiNamespaceMirrors < Gitlab::Database::Migration[1.0] - MIGRATION = 'BackfillCiNamespaceMirrors' - BATCH_SIZE = 10_000 - DELAY_INTERVAL = 2.minutes - - disable_ddl_transaction! - def up - queue_background_migration_jobs_by_range_at_intervals( - Gitlab::BackgroundMigration::BackfillCiNamespaceMirrors::Namespace.base_query, - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - track_jobs: true - ) + # no-op end def down diff --git a/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb b/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb index 5678ee9f292..2a58eda040e 100644 --- a/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb +++ b/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb @@ -1,20 +1,8 @@ # frozen_string_literal: true class ScheduleBackfillCiProjectMirrors < Gitlab::Database::Migration[1.0] - MIGRATION = 'BackfillCiProjectMirrors' - BATCH_SIZE = 10_000 - DELAY_INTERVAL = 2.minutes - - disable_ddl_transaction! - def up - queue_background_migration_jobs_by_range_at_intervals( - Gitlab::BackgroundMigration::BackfillCiProjectMirrors::Project.base_query, - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - track_jobs: true - ) + # no-op end def down diff --git a/db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb b/db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb index 65ec2f9a282..a6775251d42 100644 --- a/db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb +++ b/db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb @@ -1,12 +1,8 @@ # frozen_string_literal: true class CleanupBackfillCiNamespaceMirrors < Gitlab::Database::Migration[1.0] - MIGRATION = 'BackfillCiNamespaceMirrors' - - disable_ddl_transaction! - def up - finalize_background_migration(MIGRATION) + # no-op end def down diff --git a/db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb b/db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb index 8c7d9a945ba..c0cdb74c595 100644 --- a/db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb +++ b/db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb @@ -1,12 +1,8 @@ # frozen_string_literal: true class CleanupBackfillCiProjectMirrors < Gitlab::Database::Migration[1.0] - MIGRATION = 'BackfillCiProjectMirrors' - - disable_ddl_transaction! - def up - finalize_background_migration(MIGRATION) + # no-op end def down diff --git a/db/post_migrate/20220213103859_remove_integrations_type.rb b/db/post_migrate/20220213103859_remove_integrations_type.rb index c3633d1e7d3..3c420760a2d 100644 --- a/db/post_migrate/20220213103859_remove_integrations_type.rb +++ b/db/post_migrate/20220213103859_remove_integrations_type.rb @@ -73,7 +73,7 @@ class RemoveIntegrationsType < Gitlab::Database::Migration[1.0] add_concurrent_index :integrations, :id, where: 'type_new is null', name: tmp_index_name define_batchable_model(:integrations).where(type_new: nil).each_batch do |batch| - min_id, max_id = batch.pluck(Arel.sql('MIN(id), MAX(id)')).first + min_id, max_id = batch.pick(Arel.sql('MIN(id), MAX(id)')) connection.execute(<<~SQL) WITH mapping(old_type, new_type) AS (VALUES diff --git a/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb b/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb index 69850b3a32f..2213268fa73 100644 --- a/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb +++ b/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb @@ -12,7 +12,7 @@ class ConsumeRemainingEncryptIntegrationPropertyJobs < Gitlab::Database::Migrati relation = model.where.not(properties: nil).where(encrypted_properties: nil) relation.each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first + range = batch.pick('MIN(id)', 'MAX(id)') Gitlab::BackgroundMigration::EncryptIntegrationProperties.new.perform(*range) end diff --git a/db/post_migrate/20220520040416_schedule_set_legacy_open_source_license_available_for_non_public_projects.rb b/db/post_migrate/20220520040416_schedule_set_legacy_open_source_license_available_for_non_public_projects.rb index 47b1c169d74..a9bb09b3378 100644 --- a/db/post_migrate/20220520040416_schedule_set_legacy_open_source_license_available_for_non_public_projects.rb +++ b/db/post_migrate/20220520040416_schedule_set_legacy_open_source_license_available_for_non_public_projects.rb @@ -1,31 +1,13 @@ # frozen_string_literal: true class ScheduleSetLegacyOpenSourceLicenseAvailableForNonPublicProjects < Gitlab::Database::Migration[2.0] - MIGRATION = 'SetLegacyOpenSourceLicenseAvailableForNonPublicProjects' - INTERVAL = 2.minutes - BATCH_SIZE = 5_000 - SUB_BATCH_SIZE = 200 - - disable_ddl_transaction! - restrict_gitlab_migration gitlab_schema: :gitlab_main def up - return unless Gitlab.com? - - queue_batched_background_migration( - MIGRATION, - :projects, - :id, - job_interval: INTERVAL, - batch_size: BATCH_SIZE, - sub_batch_size: SUB_BATCH_SIZE - ) + # Replaced by 20220722110026_reschedule_set_legacy_open_source_license_available_for_non_public_projects.rb end def down - return unless Gitlab.com? - - delete_batched_background_migration(MIGRATION, :projects, :id, []) + # Replaced by 20220722110026_reschedule_set_legacy_open_source_license_available_for_non_public_projects.rb end end diff --git a/db/post_migrate/20220524074947_finalize_backfill_null_note_discussion_ids.rb b/db/post_migrate/20220524074947_finalize_backfill_null_note_discussion_ids.rb index f11846ebe1d..45dbc028b18 100644 --- a/db/post_migrate/20220524074947_finalize_backfill_null_note_discussion_ids.rb +++ b/db/post_migrate/20220524074947_finalize_backfill_null_note_discussion_ids.rb @@ -12,7 +12,7 @@ class FinalizeBackfillNullNoteDiscussionIds < Gitlab::Database::Migration[2.0] Gitlab::BackgroundMigration.steal(MIGRATION) define_batchable_model('notes').where(discussion_id: nil).each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first + range = batch.pick('MIN(id)', 'MAX(id)') Gitlab::BackgroundMigration::BackfillNoteDiscussionId.new.perform(*range) end diff --git a/db/post_migrate/20220525201022_add_temporary_index_for_vulnerability_reads_cluster_agent_id_migration.rb b/db/post_migrate/20220525201022_add_temporary_index_for_vulnerability_reads_cluster_agent_id_migration.rb new file mode 100644 index 00000000000..b795a41e9cd --- /dev/null +++ b/db/post_migrate/20220525201022_add_temporary_index_for_vulnerability_reads_cluster_agent_id_migration.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddTemporaryIndexForVulnerabilityReadsClusterAgentIdMigration < Gitlab::Database::Migration[2.0] + INDEX_VULNERABILITY_READS_NAME = 'tmp_index_cis_vulnerability_reads_on_id' + + disable_ddl_transaction! + + def up + # this index is used in 20220525221133_schedule_backfill_vulnerability_reads_cluster_agent + add_concurrent_index :vulnerability_reads, :id, name: INDEX_VULNERABILITY_READS_NAME, where: 'report_type = 7' + end + + def down + remove_concurrent_index_by_name :vulnerability_reads, INDEX_VULNERABILITY_READS_NAME + end +end diff --git a/db/post_migrate/20220525221133_schedule_backfill_vulnerability_reads_cluster_agent.rb b/db/post_migrate/20220525221133_schedule_backfill_vulnerability_reads_cluster_agent.rb new file mode 100644 index 00000000000..bf83781e89c --- /dev/null +++ b/db/post_migrate/20220525221133_schedule_backfill_vulnerability_reads_cluster_agent.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class ScheduleBackfillVulnerabilityReadsClusterAgent < Gitlab::Database::Migration[2.0] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + BATCH_SIZE = 10_000 + SUB_BATCH_SIZE = 1_000 + DELAY_INTERVAL = 2.minutes + MIGRATION_NAME = 'BackfillVulnerabilityReadsClusterAgent' + BATCH_CLASS_NAME = 'BackfillVulnerabilityReadsClusterAgentBatchingStrategy' + + disable_ddl_transaction! + + def up + queue_batched_background_migration( + MIGRATION_NAME, + :vulnerability_reads, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + batch_class_name: BATCH_CLASS_NAME, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION_NAME, :vulnerability_reads, :id, []) + end +end diff --git a/db/post_migrate/20220603173103_update_vulnerabilities_project_id_id_index.rb b/db/post_migrate/20220603173103_update_vulnerabilities_project_id_id_index.rb new file mode 100644 index 00000000000..8f10fd61273 --- /dev/null +++ b/db/post_migrate/20220603173103_update_vulnerabilities_project_id_id_index.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class UpdateVulnerabilitiesProjectIdIdIndex < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + NEW_INDEX_NAME = 'idx_vulnerabilities_partial_devops_adoption_and_default_branch' + OLD_INDEX_NAME = 'idx_vulnerabilities_partial_devops_adoption' + + def up + add_concurrent_index :vulnerabilities, [:project_id, :created_at, :present_on_default_branch], + where: 'state != 1', + name: NEW_INDEX_NAME + + remove_concurrent_index_by_name(:vulnerabilities, OLD_INDEX_NAME) + end + + def down + add_concurrent_index :vulnerabilities, [:project_id, :created_at], where: 'state != 1', name: OLD_INDEX_NAME + + remove_concurrent_index_by_name(:vulnerabilities, NEW_INDEX_NAME) + end +end diff --git a/db/post_migrate/20220607082910_add_sync_tmp_index_for_potentially_misassociated_vulnerability_occurrences.rb b/db/post_migrate/20220607082910_add_sync_tmp_index_for_potentially_misassociated_vulnerability_occurrences.rb new file mode 100644 index 00000000000..fe4ffbf6cc3 --- /dev/null +++ b/db/post_migrate/20220607082910_add_sync_tmp_index_for_potentially_misassociated_vulnerability_occurrences.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddSyncTmpIndexForPotentiallyMisassociatedVulnerabilityOccurrences < Gitlab::Database::Migration[2.0] + INDEX_NAME = "tmp_index_vulnerability_occurrences_on_id_and_scanner_id" + REPORT_TYPES = { cluster_image_scanning: 7, generic: 99 }.freeze + CLAUSE = "report_type IN (#{REPORT_TYPES.values.join(',')})" + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerability_occurrences, + [:id, :scanner_id], + where: CLAUSE, + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME + end +end diff --git a/db/post_migrate/20220614185644_update_index_vulnerabilities_project_id_id.rb b/db/post_migrate/20220614185644_update_index_vulnerabilities_project_id_id.rb new file mode 100644 index 00000000000..142cac09a01 --- /dev/null +++ b/db/post_migrate/20220614185644_update_index_vulnerabilities_project_id_id.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class UpdateIndexVulnerabilitiesProjectIdId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + NEW_INDEX_NAME = 'index_vulnerabilities_project_id_and_id_on_default_branch' + OLD_INDEX_NAME = 'index_vulnerabilities_on_project_id_and_id' + + def up + add_concurrent_index :vulnerabilities, [:project_id, :id], + where: 'present_on_default_branch IS TRUE', + name: NEW_INDEX_NAME + + remove_concurrent_index_by_name(:vulnerabilities, OLD_INDEX_NAME) + end + + def down + add_concurrent_index :vulnerabilities, [:project_id, :id], name: OLD_INDEX_NAME + + remove_concurrent_index_by_name(:vulnerabilities, NEW_INDEX_NAME) + end +end diff --git a/db/post_migrate/20220621192541_add_project_id_state_severity_default_branch_index_for_vulnerabilities.rb b/db/post_migrate/20220621192541_add_project_id_state_severity_default_branch_index_for_vulnerabilities.rb new file mode 100644 index 00000000000..76753cdd737 --- /dev/null +++ b/db/post_migrate/20220621192541_add_project_id_state_severity_default_branch_index_for_vulnerabilities.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddProjectIdStateSeverityDefaultBranchIndexForVulnerabilities < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_vulnerabilities_project_id_state_severity_default_branch' + + def up + add_concurrent_index :vulnerabilities, [:project_id, :state, :severity, :present_on_default_branch], + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME + end +end diff --git a/db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb b/db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb index 64cdd75f5a7..1533c502b3d 100644 --- a/db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb +++ b/db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb @@ -9,10 +9,12 @@ class AddTempIndexForContainerRegistrySizeMigration < Gitlab::Database::Migratio def up # Temporary index used in 20220622080547_backfill_project_statistics_with_container_registry_size # Temporary index to be remove via https://gitlab.com/gitlab-org/gitlab/-/issues/366392 - add_concurrent_index :container_repositories, [:project_id], name: INDEX_CONTAINER_REGISTRY_SIZE, - where: "migration_state = 'import_done' OR created_at >= '2022-01-23'" - add_concurrent_index :project_statistics, [:project_id], name: INDEX_PROJECT_STATS_CONT_REG_SIZE, - where: "container_registry_size = 0" + add_concurrent_index :container_repositories, [:project_id], + name: INDEX_CONTAINER_REGISTRY_SIZE, + where: "migration_state = 'import_done' OR created_at >= '2022-01-23'" + add_concurrent_index :project_statistics, [:project_id], + name: INDEX_PROJECT_STATS_CONT_REG_SIZE, + where: "container_registry_size = 0" end def down diff --git a/db/post_migrate/20220629124942_remove_vulnerability_occurrences_migrated_to_new_structure_column.rb b/db/post_migrate/20220629124942_remove_vulnerability_occurrences_migrated_to_new_structure_column.rb new file mode 100644 index 00000000000..2a980290cc9 --- /dev/null +++ b/db/post_migrate/20220629124942_remove_vulnerability_occurrences_migrated_to_new_structure_column.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveVulnerabilityOccurrencesMigratedToNewStructureColumn < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_vulnerability_occurrences_on_migrated_to_new_structure' + + def up + with_lock_retries do + remove_column :vulnerability_occurrences, :migrated_to_new_structure + end + end + + def down + unless column_exists?(:vulnerability_occurrences, :migrated_to_new_structure) + add_column :vulnerability_occurrences, :migrated_to_new_structure, :boolean, default: false, null: false + end + + add_concurrent_index :vulnerability_occurrences, [:migrated_to_new_structure, :id], name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220707105529_cleanup_chat_name_service_id.rb b/db/post_migrate/20220707105529_cleanup_chat_name_service_id.rb new file mode 100644 index 00000000000..aa3af4acf31 --- /dev/null +++ b/db/post_migrate/20220707105529_cleanup_chat_name_service_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CleanupChatNameServiceId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + cleanup_concurrent_column_rename :chat_names, :service_id, :integration_id + end + + def down + undo_cleanup_concurrent_column_rename :chat_names, :service_id, :integration_id + end +end diff --git a/db/post_migrate/20220707160921_cleanup_slack_integration_service_id.rb b/db/post_migrate/20220707160921_cleanup_slack_integration_service_id.rb new file mode 100644 index 00000000000..25b4252e48b --- /dev/null +++ b/db/post_migrate/20220707160921_cleanup_slack_integration_service_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CleanupSlackIntegrationServiceId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + cleanup_concurrent_column_rename :slack_integrations, :service_id, :integration_id + end + + def down + undo_cleanup_concurrent_column_rename :slack_integrations, :service_id, :integration_id + end +end diff --git a/db/post_migrate/20220712131533_cleanup_issue_tracker_data_service_id.rb b/db/post_migrate/20220712131533_cleanup_issue_tracker_data_service_id.rb new file mode 100644 index 00000000000..be304c5fe6d --- /dev/null +++ b/db/post_migrate/20220712131533_cleanup_issue_tracker_data_service_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CleanupIssueTrackerDataServiceId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + cleanup_concurrent_column_rename :issue_tracker_data, :service_id, :integration_id + end + + def down + undo_cleanup_concurrent_column_rename :issue_tracker_data, :service_id, :integration_id + end +end diff --git a/db/post_migrate/20220712144900_cleanup_jira_tracker_data_service_id.rb b/db/post_migrate/20220712144900_cleanup_jira_tracker_data_service_id.rb new file mode 100644 index 00000000000..90b35f03054 --- /dev/null +++ b/db/post_migrate/20220712144900_cleanup_jira_tracker_data_service_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CleanupJiraTrackerDataServiceId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + cleanup_concurrent_column_rename :jira_tracker_data, :service_id, :integration_id + end + + def down + undo_cleanup_concurrent_column_rename :jira_tracker_data, :service_id, :integration_id + end +end diff --git a/db/post_migrate/20220715152108_backfill_project_import_level.rb b/db/post_migrate/20220715152108_backfill_project_import_level.rb new file mode 100644 index 00000000000..65a0dc0a58a --- /dev/null +++ b/db/post_migrate/20220715152108_backfill_project_import_level.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class BackfillProjectImportLevel < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + MIGRATION = 'BackfillProjectImportLevel' + INTERVAL = 120.seconds + + def up + queue_batched_background_migration( + MIGRATION, + :namespaces, + :id, + job_interval: INTERVAL + ) + end + + def down + delete_batched_background_migration(MIGRATION, :namespaces, :id, []) + end +end diff --git a/db/post_migrate/20220715185348_add_index_on_security_findings_id_and_partition_number.rb b/db/post_migrate/20220715185348_add_index_on_security_findings_id_and_partition_number.rb new file mode 100644 index 00000000000..e867ef81381 --- /dev/null +++ b/db/post_migrate/20220715185348_add_index_on_security_findings_id_and_partition_number.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexOnSecurityFindingsIdAndPartitionNumber < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'security_findings_partitioned_pkey' + + disable_ddl_transaction! + + def up + add_concurrent_index :security_findings, [:id, :partition_number], unique: true, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :security_findings, INDEX_NAME + end +end diff --git a/db/post_migrate/20220715185436_add_index_on_security_findings_unique_columns.rb b/db/post_migrate/20220715185436_add_index_on_security_findings_unique_columns.rb new file mode 100644 index 00000000000..33b069a27d4 --- /dev/null +++ b/db/post_migrate/20220715185436_add_index_on_security_findings_unique_columns.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexOnSecurityFindingsUniqueColumns < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_security_findings_on_unique_columns' + + disable_ddl_transaction! + + def up + add_concurrent_index :security_findings, [:uuid, :scan_id, :partition_number], unique: true, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :security_findings, INDEX_NAME + end +end diff --git a/db/post_migrate/20220715190612_drop_index_on_security_findings_uuid_and_scan_id.rb b/db/post_migrate/20220715190612_drop_index_on_security_findings_uuid_and_scan_id.rb new file mode 100644 index 00000000000..a8a9bab2c84 --- /dev/null +++ b/db/post_migrate/20220715190612_drop_index_on_security_findings_uuid_and_scan_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class DropIndexOnSecurityFindingsUuidAndScanId < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_security_findings_on_uuid_and_scan_id' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :security_findings, INDEX_NAME + end + + def down + add_concurrent_index :security_findings, [:uuid, :scan_id], unique: true, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220715191629_change_primary_key_of_security_findings_table.rb b/db/post_migrate/20220715191629_change_primary_key_of_security_findings_table.rb new file mode 100644 index 00000000000..c2859c68c52 --- /dev/null +++ b/db/post_migrate/20220715191629_change_primary_key_of_security_findings_table.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class ChangePrimaryKeyOfSecurityFindingsTable < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def up + execute(<<~SQL) + ALTER TABLE security_findings DROP CONSTRAINT security_findings_pkey; + SQL + + execute(<<~SQL) + ALTER TABLE security_findings ADD CONSTRAINT security_findings_pkey PRIMARY KEY USING index security_findings_partitioned_pkey; + SQL + end + + def down + execute(<<~SQL) + ALTER TABLE security_findings DROP CONSTRAINT security_findings_pkey; + SQL + + execute(<<~SQL) + ALTER TABLE security_findings ADD CONSTRAINT security_findings_pkey PRIMARY KEY (id); + SQL + + execute(<<~SQL) + CREATE UNIQUE INDEX security_findings_partitioned_pkey ON security_findings USING btree(id, partition_number); + SQL + end +end diff --git a/db/post_migrate/20220719081542_drop_queued_at_index_from_ci_builds.rb b/db/post_migrate/20220719081542_drop_queued_at_index_from_ci_builds.rb new file mode 100644 index 00000000000..4a16d022c70 --- /dev/null +++ b/db/post_migrate/20220719081542_drop_queued_at_index_from_ci_builds.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DropQueuedAtIndexFromCiBuilds < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_ci_builds_on_queued_at' + + def up + remove_concurrent_index_by_name :ci_builds, INDEX_NAME + end + + # rubocop:disable Migration/PreventIndexCreation + def down + add_concurrent_index :ci_builds, :queued_at, name: INDEX_NAME + end + # rubocop:enable Migration/PreventIndexCreation +end diff --git a/db/post_migrate/20220719165537_remove_ci_runners_semver_column.rb b/db/post_migrate/20220719165537_remove_ci_runners_semver_column.rb new file mode 100644 index 00000000000..a6929153d10 --- /dev/null +++ b/db/post_migrate/20220719165537_remove_ci_runners_semver_column.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveCiRunnersSemverColumn < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_ci_runners_on_id_and_semver_cidr' + + def up + with_lock_retries do + remove_column :ci_runners, :semver + end + end + + def down + with_lock_retries do + add_column :ci_runners, :semver, :text, null: true + end + add_text_limit :ci_runners, :semver, 16 + add_concurrent_index :ci_runners, 'id, (semver::cidr)', name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220720090354_remove_pending_builds_covering_index_from_ci_builds.rb b/db/post_migrate/20220720090354_remove_pending_builds_covering_index_from_ci_builds.rb new file mode 100644 index 00000000000..fb3d12840cc --- /dev/null +++ b/db/post_migrate/20220720090354_remove_pending_builds_covering_index_from_ci_builds.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class RemovePendingBuildsCoveringIndexFromCiBuilds < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_ci_builds_runner_id_pending_covering' + + def up + remove_concurrent_index_by_name :ci_builds, INDEX_NAME + end + + # rubocop:disable Migration/PreventIndexCreation + def down + disable_statement_timeout do + unless index_exists_by_name?(:ci_builds, INDEX_NAME) + execute <<~SQL.squish + CREATE INDEX CONCURRENTLY #{INDEX_NAME} + ON ci_builds (runner_id, id) + INCLUDE (project_id) + WHERE status = 'pending' AND type = 'Ci::Build' + SQL + end + end + end + # rubocop:enable Migration/PreventIndexCreation +end diff --git a/db/post_migrate/20220720121421_remove_pat_and_ssh_enforcement_columns_from_application_settings.rb b/db/post_migrate/20220720121421_remove_pat_and_ssh_enforcement_columns_from_application_settings.rb new file mode 100644 index 00000000000..b03cad08f35 --- /dev/null +++ b/db/post_migrate/20220720121421_remove_pat_and_ssh_enforcement_columns_from_application_settings.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class RemovePatAndSshEnforcementColumnsFromApplicationSettings < Gitlab::Database::Migration[2.0] + def change + remove_column :application_settings, :enforce_pat_expiration, :boolean, default: true, null: false + remove_column :application_settings, :enforce_ssh_key_expiration, :boolean, default: true, null: false + end +end diff --git a/db/post_migrate/20220720123249_remove_token_column_from_ci_builds.rb b/db/post_migrate/20220720123249_remove_token_column_from_ci_builds.rb new file mode 100644 index 00000000000..1bc13b6ea05 --- /dev/null +++ b/db/post_migrate/20220720123249_remove_token_column_from_ci_builds.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class RemoveTokenColumnFromCiBuilds < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + remove_column :ci_builds, :token, :string + end +end diff --git a/db/post_migrate/20220720171102_add_index_on_vulnerability_reads_namespace_id.rb b/db/post_migrate/20220720171102_add_index_on_vulnerability_reads_namespace_id.rb new file mode 100644 index 00000000000..e90fcfd3016 --- /dev/null +++ b/db/post_migrate/20220720171102_add_index_on_vulnerability_reads_namespace_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexOnVulnerabilityReadsNamespaceId < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_vuln_reads_on_namespace_id_state_severity_and_vuln_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerability_reads, + [:namespace_id, :state, :severity, :vulnerability_id], + name: INDEX_NAME, + order: { vulnerability_id: :desc } + end + + def down + remove_concurrent_index_by_name :vulnerability_reads, INDEX_NAME + end +end diff --git a/db/post_migrate/20220720171801_add_foreign_key_on_vulnerability_reads_namespace_id.rb b/db/post_migrate/20220720171801_add_foreign_key_on_vulnerability_reads_namespace_id.rb new file mode 100644 index 00000000000..c1b6a9d6909 --- /dev/null +++ b/db/post_migrate/20220720171801_add_foreign_key_on_vulnerability_reads_namespace_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddForeignKeyOnVulnerabilityReadsNamespaceId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :vulnerability_reads, :namespaces, column: :namespace_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :vulnerability_reads, column: :namespace_id + end + end +end diff --git a/db/post_migrate/20220721031446_schedule_disable_legacy_open_source_license_for_one_member_no_repo_projects.rb b/db/post_migrate/20220721031446_schedule_disable_legacy_open_source_license_for_one_member_no_repo_projects.rb new file mode 100644 index 00000000000..7665d49b1d9 --- /dev/null +++ b/db/post_migrate/20220721031446_schedule_disable_legacy_open_source_license_for_one_member_no_repo_projects.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class ScheduleDisableLegacyOpenSourceLicenseForOneMemberNoRepoProjects < Gitlab::Database::Migration[2.0] + MIGRATION = 'DisableLegacyOpenSourceLicenseForOneMemberNoRepoProjects' + INTERVAL = 2.minutes + BATCH_SIZE = 5_000 + MAX_BATCH_SIZE = 10_000 + SUB_BATCH_SIZE = 500 + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + return unless Gitlab.com? + + 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 + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, :projects, :id, []) + end +end diff --git a/db/post_migrate/20220721140252_prepare_partial_trigram_indexes_for_issues.rb b/db/post_migrate/20220721140252_prepare_partial_trigram_indexes_for_issues.rb new file mode 100644 index 00000000000..00a51f3024e --- /dev/null +++ b/db/post_migrate/20220721140252_prepare_partial_trigram_indexes_for_issues.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class PreparePartialTrigramIndexesForIssues < 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-\\u218F]*' OR description NOT SIMILAR TO '[\\u0000-\\u218F]*'" + + prepare_async_index :issues, :description, + name: DESCRIPTION_INDEX_NAME, + using: :gin, opclass: { description: :gin_trgm_ops }, + where: "title NOT SIMILAR TO '[\\u0000-\\u218F]*' OR description NOT SIMILAR TO '[\\u0000-\\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/20220722084543_schedule_disable_legacy_open_source_license_for_no_issues_no_repo_projects.rb b/db/post_migrate/20220722084543_schedule_disable_legacy_open_source_license_for_no_issues_no_repo_projects.rb new file mode 100644 index 00000000000..7fbf09846cf --- /dev/null +++ b/db/post_migrate/20220722084543_schedule_disable_legacy_open_source_license_for_no_issues_no_repo_projects.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class ScheduleDisableLegacyOpenSourceLicenseForNoIssuesNoRepoProjects < Gitlab::Database::Migration[2.0] + MIGRATION = 'DisableLegacyOpenSourceLicenseForNoIssuesNoRepoProjects' + INTERVAL = 2.minutes + BATCH_SIZE = 5_000 + MAX_BATCH_SIZE = 10_000 + SUB_BATCH_SIZE = 200 + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + return unless Gitlab.com? + + 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 + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, :projects, :id, []) + end +end diff --git a/db/post_migrate/20220722110026_reschedule_set_legacy_open_source_license_available_for_non_public_projects.rb b/db/post_migrate/20220722110026_reschedule_set_legacy_open_source_license_available_for_non_public_projects.rb new file mode 100644 index 00000000000..546923141e2 --- /dev/null +++ b/db/post_migrate/20220722110026_reschedule_set_legacy_open_source_license_available_for_non_public_projects.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class RescheduleSetLegacyOpenSourceLicenseAvailableForNonPublicProjects < Gitlab::Database::Migration[2.0] + MIGRATION = 'SetLegacyOpenSourceLicenseAvailableForNonPublicProjects' + INTERVAL = 2.minutes + BATCH_SIZE = 5_000 + MAX_BATCH_SIZE = 10_000 + SUB_BATCH_SIZE = 200 + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, :projects, :id, []) + + 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 + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, :projects, :id, []) + end +end diff --git a/db/post_migrate/20220722145845_schedule_backfilling_the_namespace_id_for_vulnerability_reads.rb b/db/post_migrate/20220722145845_schedule_backfilling_the_namespace_id_for_vulnerability_reads.rb new file mode 100644 index 00000000000..e2d1846f8f6 --- /dev/null +++ b/db/post_migrate/20220722145845_schedule_backfilling_the_namespace_id_for_vulnerability_reads.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ScheduleBackfillingTheNamespaceIdForVulnerabilityReads < Gitlab::Database::Migration[2.0] + MIGRATION_NAME = 'BackfillNamespaceIdOfVulnerabilityReads' + + restrict_gitlab_migration gitlab_schema: :gitlab_main + disable_ddl_transaction! + + def up + queue_batched_background_migration( + MIGRATION_NAME, + :vulnerability_reads, + :vulnerability_id, + job_interval: 2.minutes, + batch_size: 10_000, + sub_batch_size: 200 + ) + end + + def down + delete_batched_background_migration(MIGRATION_NAME, :vulnerability_reads, :vulnerability_id, []) + end +end diff --git a/db/post_migrate/20220725150127_update_jira_tracker_data_deployment_type_based_on_url.rb b/db/post_migrate/20220725150127_update_jira_tracker_data_deployment_type_based_on_url.rb new file mode 100644 index 00000000000..0deba9b3e81 --- /dev/null +++ b/db/post_migrate/20220725150127_update_jira_tracker_data_deployment_type_based_on_url.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class UpdateJiraTrackerDataDeploymentTypeBasedOnUrl < Gitlab::Database::Migration[2.0] + MIGRATION = 'UpdateJiraTrackerDataDeploymentTypeBasedOnUrl' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 2_500 + SUB_BATCH_SIZE = 2_500 + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + say "Scheduling #{MIGRATION} jobs" + delete_queued_jobs(MIGRATION) + queue_batched_background_migration( + MIGRATION, + :jira_tracker_data, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220726182310_add_user_fk_to_vulnerability_state_transitions.rb b/db/post_migrate/20220726182310_add_user_fk_to_vulnerability_state_transitions.rb new file mode 100644 index 00000000000..ad0bf6141b2 --- /dev/null +++ b/db/post_migrate/20220726182310_add_user_fk_to_vulnerability_state_transitions.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddUserFkToVulnerabilityStateTransitions < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_vulnerability_state_transitions_on_author_id' + + def up + add_concurrent_index :vulnerability_state_transitions, :author_id, name: INDEX_NAME + add_concurrent_foreign_key :vulnerability_state_transitions, :users, column: :author_id, on_delete: :nullify + end + + def down + with_lock_retries do + remove_foreign_key :vulnerability_state_transitions, column: :author_id + end + + remove_concurrent_index_by_name :vulnerability_state_transitions, INDEX_NAME + end +end diff --git a/db/post_migrate/20220728134255_update_index_vulnerabilities_common_finder.rb b/db/post_migrate/20220728134255_update_index_vulnerabilities_common_finder.rb new file mode 100644 index 00000000000..617d7661b5b --- /dev/null +++ b/db/post_migrate/20220728134255_update_index_vulnerabilities_common_finder.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class UpdateIndexVulnerabilitiesCommonFinder < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + NEW_INDEX_NAME = 'index_vulnerabilities_common_finder_query_on_default_branch' + OLD_INDEX_NAME = 'index_vulnerabilites_common_finder_query' + + def up + add_concurrent_index :vulnerabilities, [:project_id, :state, :report_type, :present_on_default_branch, + :severity, :id], name: NEW_INDEX_NAME + + remove_concurrent_index_by_name(:vulnerabilities, OLD_INDEX_NAME) + end + + def down + add_concurrent_index :vulnerabilities, [:project_id, :state, :report_type, :severity, :id], name: OLD_INDEX_NAME + + remove_concurrent_index_by_name(:vulnerabilities, NEW_INDEX_NAME) + end +end diff --git a/db/post_migrate/20220729033851_add_partial_legacy_open_source_license_available_index.rb b/db/post_migrate/20220729033851_add_partial_legacy_open_source_license_available_index.rb new file mode 100644 index 00000000000..c99c452c149 --- /dev/null +++ b/db/post_migrate/20220729033851_add_partial_legacy_open_source_license_available_index.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddPartialLegacyOpenSourceLicenseAvailableIndex < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_project_settings_on_legacy_open_source_license_available' + + def up + add_concurrent_index :project_settings, + %i[legacy_open_source_license_available], + where: "legacy_open_source_license_available = TRUE", + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name(:project_settings, INDEX_NAME) + end +end diff --git a/db/post_migrate/20220729052031_add_index_on_vulnerability_reads_namespace_id_with_report_type.rb b/db/post_migrate/20220729052031_add_index_on_vulnerability_reads_namespace_id_with_report_type.rb new file mode 100644 index 00000000000..53b2c1728e1 --- /dev/null +++ b/db/post_migrate/20220729052031_add_index_on_vulnerability_reads_namespace_id_with_report_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexOnVulnerabilityReadsNamespaceIdWithReportType < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_vulnerability_reads_common_finder_query_with_namespace_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerability_reads, + [:namespace_id, :state, :report_type, :severity, :vulnerability_id], + name: INDEX_NAME, + order: { vulnerability_id: :desc } + end + + def down + remove_concurrent_index_by_name :vulnerability_reads, INDEX_NAME + end +end diff --git a/db/post_migrate/20220801144713_add_partial_trigram_index_for_issue_title.rb b/db/post_migrate/20220801144713_add_partial_trigram_index_for_issue_title.rb new file mode 100644 index 00000000000..c4db8232eba --- /dev/null +++ b/db/post_migrate/20220801144713_add_partial_trigram_index_for_issue_title.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddPartialTrigramIndexForIssueTitle < 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-\\u218F]*' OR description NOT SIMILAR TO '[\\u0000-\\u218F]*'" + end + + def down + remove_concurrent_index_by_name :issues, INDEX_NAME + end +end diff --git a/db/post_migrate/20220801150028_add_partial_trigram_index_for_issue_description.rb b/db/post_migrate/20220801150028_add_partial_trigram_index_for_issue_description.rb new file mode 100644 index 00000000000..79f25718e15 --- /dev/null +++ b/db/post_migrate/20220801150028_add_partial_trigram_index_for_issue_description.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddPartialTrigramIndexForIssueDescription < 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-\\u218F]*' OR description NOT SIMILAR TO '[\\u0000-\\u218F]*'" + end + + def down + remove_concurrent_index_by_name :issues, INDEX_NAME + end +end diff --git a/db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb b/db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb new file mode 100644 index 00000000000..92ca0998bae --- /dev/null +++ b/db/post_migrate/20220802112102_schedule_migrate_shared_vulnerability_scanners.rb @@ -0,0 +1,34 @@ +# 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 + ) + end + + def down + delete_batched_background_migration(MIGRATION, TABLE_NAME, BATCH_COLUMN, []) + end +end diff --git a/db/post_migrate/20220802114351_reschedule_backfill_container_registry_size_into_project_statistics.rb b/db/post_migrate/20220802114351_reschedule_backfill_container_registry_size_into_project_statistics.rb new file mode 100644 index 00000000000..46b98d319fd --- /dev/null +++ b/db/post_migrate/20220802114351_reschedule_backfill_container_registry_size_into_project_statistics.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class RescheduleBackfillContainerRegistrySizeIntoProjectStatistics < Gitlab::Database::Migration[2.0] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 500 + MIGRATION_CLASS = 'BackfillProjectStatisticsContainerRepositorySize' + BATCH_CLASS_NAME = 'BackfillProjectStatisticsWithContainerRegistrySizeBatchingStrategy' + SUB_BATCH_SIZE = 100 + + disable_ddl_transaction! + + def up + return unless Gitlab.dev_or_test_env? || Gitlab.com? + + # remove the original migration + delete_batched_background_migration(MIGRATION_CLASS, :container_repositories, :project_id, []) + + # reschedule the migration + queue_batched_background_migration( + MIGRATION_CLASS, + :container_repositories, + :project_id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + batch_class_name: BATCH_CLASS_NAME, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.dev_or_test_env? || Gitlab.com? + + delete_batched_background_migration(MIGRATION_CLASS, :container_repositories, :project_id, []) + end +end diff --git a/db/post_migrate/20220802132158_index_on_integration_type_new_id_when_active_and_has_group.rb b/db/post_migrate/20220802132158_index_on_integration_type_new_id_when_active_and_has_group.rb new file mode 100644 index 00000000000..81e95f531c1 --- /dev/null +++ b/db/post_migrate/20220802132158_index_on_integration_type_new_id_when_active_and_has_group.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class IndexOnIntegrationTypeNewIdWhenActiveAndHasGroup < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_integrations_on_type_new_id_when_active_and_has_group' + + disable_ddl_transaction! + + def up + add_concurrent_index :integrations, + [:type_new, :id, :inherit_from_id], + name: INDEX_NAME, + where: '((active = true) AND (group_id IS NOT NULL))' + end + + def down + remove_concurrent_index_by_name :integrations, INDEX_NAME + end +end diff --git a/db/post_migrate/20220802204737_remove_deactivated_user_highest_role_stats.rb b/db/post_migrate/20220802204737_remove_deactivated_user_highest_role_stats.rb new file mode 100644 index 00000000000..e23fbfdf7f2 --- /dev/null +++ b/db/post_migrate/20220802204737_remove_deactivated_user_highest_role_stats.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class RemoveDeactivatedUserHighestRoleStats < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + # This migration is applicable to self-managed instances that may utilize the + # dormant user deactivation feature. This feature is not enabled on Gitlab.com. + return if Gitlab.com? + + users_table = define_batchable_model('users') + user_highest_roles_table = define_batchable_model('user_highest_roles') + + users_table.where(state: 'deactivated').each_batch do |users_batch| + user_ids = users_batch.pluck(:id) + user_highest_roles_table.where(user_id: user_ids).delete_all + end + end + + def down + # no-op + + # This migration removes entries from the UserHighestRole table and cannot be reversed + end +end diff --git a/db/post_migrate/20220803042351_add_tmp_index_todos_attention_request_action.rb b/db/post_migrate/20220803042351_add_tmp_index_todos_attention_request_action.rb new file mode 100644 index 00000000000..fa80b2b95e7 --- /dev/null +++ b/db/post_migrate/20220803042351_add_tmp_index_todos_attention_request_action.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddTmpIndexTodosAttentionRequestAction < Gitlab::Database::Migration[2.0] + INDEX_NAME = "tmp_index_todos_attention_request_action" + ATTENTION_REQUESTED = 10 + + disable_ddl_transaction! + + def up + add_concurrent_index :todos, [:id], + where: "action = #{ATTENTION_REQUESTED}", + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :todos, INDEX_NAME + end +end diff --git a/db/post_migrate/20220803042352_cleanup_mr_attention_request_todos.rb b/db/post_migrate/20220803042352_cleanup_mr_attention_request_todos.rb new file mode 100644 index 00000000000..d3b281b08ad --- /dev/null +++ b/db/post_migrate/20220803042352_cleanup_mr_attention_request_todos.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class CleanupMrAttentionRequestTodos < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + class Todo < MigrationRecord + self.table_name = 'todos' + + include ::EachBatch + + ATTENTION_REQUESTED = 10 + end + + def up + Todo.where(action: Todo::ATTENTION_REQUESTED).each_batch do |todos_batch| + todos_batch.delete_all + end + end + + def down + # Attention request feature has been reverted. + end +end diff --git a/db/post_migrate/20220804235614_add_comment_to_vulnerability_state_transitions.rb b/db/post_migrate/20220804235614_add_comment_to_vulnerability_state_transitions.rb new file mode 100644 index 00000000000..3e3cb5746bc --- /dev/null +++ b/db/post_migrate/20220804235614_add_comment_to_vulnerability_state_transitions.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddCommentToVulnerabilityStateTransitions < Gitlab::Database::Migration[2.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in db/post_migrate/20220805001210_add_text_limit_to_vulnerability_state_transitions_comment.rb + def change + add_column :vulnerability_state_transitions, :comment, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/post_migrate/20220805001210_add_text_limit_to_vulnerability_state_transitions_comment.rb b/db/post_migrate/20220805001210_add_text_limit_to_vulnerability_state_transitions_comment.rb new file mode 100644 index 00000000000..dd84c0620ce --- /dev/null +++ b/db/post_migrate/20220805001210_add_text_limit_to_vulnerability_state_transitions_comment.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToVulnerabilityStateTransitionsComment < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_text_limit :vulnerability_state_transitions, :comment, 255 + end + + def down + remove_text_limit :vulnerability_state_transitions, :comment + end +end diff --git a/db/post_migrate/20220808072054_prepare_index_removal_security_findings.rb b/db/post_migrate/20220808072054_prepare_index_removal_security_findings.rb new file mode 100644 index 00000000000..eb4158fa9dd --- /dev/null +++ b/db/post_migrate/20220808072054_prepare_index_removal_security_findings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class PrepareIndexRemovalSecurityFindings < Gitlab::Database::Migration[2.0] + INDEX_NAME = :index_on_security_findings_uuid_and_id_order_desc + + def up + prepare_async_index_removal :security_findings, [:uuid, :id], name: INDEX_NAME + end + + def down + unprepare_async_index_by_name :security_findings, INDEX_NAME + end +end diff --git a/db/post_migrate/20220808131659_remove_ci_namespace_monthly_usages_additional_amount_available_column.rb b/db/post_migrate/20220808131659_remove_ci_namespace_monthly_usages_additional_amount_available_column.rb new file mode 100644 index 00000000000..70a1e425e0d --- /dev/null +++ b/db/post_migrate/20220808131659_remove_ci_namespace_monthly_usages_additional_amount_available_column.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemoveCiNamespaceMonthlyUsagesAdditionalAmountAvailableColumn < Gitlab::Database::Migration[2.0] + def up + remove_column :ci_namespace_monthly_usages, :additional_amount_available + end + + def down + add_column :ci_namespace_monthly_usages, :additional_amount_available, :integer, default: 0, null: false + end +end diff --git a/db/post_migrate/20220810093742_add_async_tmp_index_job_artifacts_id_and_expire_at.rb b/db/post_migrate/20220810093742_add_async_tmp_index_job_artifacts_id_and_expire_at.rb new file mode 100644 index 00000000000..5a52b26ed92 --- /dev/null +++ b/db/post_migrate/20220810093742_add_async_tmp_index_job_artifacts_id_and_expire_at.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddAsyncTmpIndexJobArtifactsIdAndExpireAt < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'tmp_index_ci_job_artifacts_on_id_expire_at_file_type_trace' + + EXPIRE_AT_ON_22_MIDNIGHT_IN_TIMEZONE_OR_TRACE = <<~SQL + (EXTRACT(day FROM timezone('UTC', expire_at)) IN (21, 22, 23) + AND EXTRACT(minute FROM timezone('UTC', expire_at)) IN (0, 30, 45) + AND EXTRACT(second FROM timezone('UTC', expire_at)) = 0) + OR file_type = 3 + SQL + + def up + prepare_async_index :ci_job_artifacts, :id, + where: EXPIRE_AT_ON_22_MIDNIGHT_IN_TIMEZONE_OR_TRACE, name: INDEX_NAME + end + + def down + unprepare_async_index :ci_job_artifacts, INDEX_NAME + end +end |