diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /db/post_migrate | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'db/post_migrate')
39 files changed, 782 insertions, 0 deletions
diff --git a/db/post_migrate/20210713042000_fix_ci_sources_pipelines_index_names.rb b/db/post_migrate/20210713042000_fix_ci_sources_pipelines_index_names.rb new file mode 100644 index 00000000000..34701d8ba46 --- /dev/null +++ b/db/post_migrate/20210713042000_fix_ci_sources_pipelines_index_names.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +# When the `ci_sources_pipelines` table was first introduced in GitLab +# 9.3 EE, the foreign key names generate for the table appeared to +# have been calculated via a hash using the table name +# `ci_pipeline_source_pipelines`. This led to a merge conflict and +# confusion during a CE to EE merge in GitLab 10.0, which regenerated +# the schema with the correct foreign key names. +# +# Hence anyone who installed GitLab prior to 10.0 may have been seeded +# the database with stale, incorrect foreign key names. +# +# During the Great BigInt Conversion of 2021, several migrations +# assumed that the foreign key `fk_be5624bf37` existed for +# `ci_sources_pipeline`. However, older installations may have had the +# correct foreign key under the name `fk_3f0c88d7dc`. +# +# To eliminate future confusion and migration failures, we now rename +# the foreign key constraints and index to what they should be today. +class FixCiSourcesPipelinesIndexNames < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + TABLE_NAME = 'ci_sources_pipelines' + + # GitLab 9.5.4: https://gitlab.com/gitlab-org/gitlab/-/blob/v9.5.4-ee/db/schema.rb#L2026-2030 + # GitLab 10.0: https://gitlab.com/gitlab-org/gitlab/-/blob/v10.0.0-ee/db/schema.rb#L2064-2068 + OLD_TO_NEW_FOREIGN_KEY_DEFS = { + 'fk_3f0c88d7dc' => { table: :ci_builds, column: :source_job_id, name: 'fk_be5624bf37' }, + 'fk_b8c0fac459' => { table: :ci_pipelines, column: :pipeline_id, name: 'fk_e1bad85861' }, + 'fk_3a3e3cb83a' => { table: :ci_pipelines, column: :source_pipeline_id, name: 'fk_d4e29af7d7' }, + 'fk_8868d0f3e4' => { table: :projects, column: :source_project_id, name: 'fk_acd9737679' }, + 'fk_83b4346e48' => { table: :projects, name: 'fk_1e53c97c0a' } + } + OLD_INDEX_NAME = 'index_ci_pipeline_source_pipelines_on_source_job_id' + NEW_INDEX_NAME = 'index_ci_sources_pipelines_on_source_job_id' + + def up + OLD_TO_NEW_FOREIGN_KEY_DEFS.each do |old_name, entry| + options = { column: entry[:column], name: old_name }.compact + + if foreign_key_exists?(TABLE_NAME, entry[:table], **options) + rename_constraint(TABLE_NAME, old_name, entry[:name]) + end + end + + if index_exists_by_name?(TABLE_NAME, OLD_INDEX_NAME) + if index_exists_by_name?(TABLE_NAME, NEW_INDEX_NAME) + remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME) + else + rename_index(TABLE_NAME, OLD_INDEX_NAME, NEW_INDEX_NAME) + end + end + end + + # There's no reason to revert this change since it should apply on stale schemas + def down; end +end diff --git a/db/post_migrate/20211022214523_schedule_recalculate_vulnerability_finding_signatures_for_findings.rb b/db/post_migrate/20211022214523_schedule_recalculate_vulnerability_finding_signatures_for_findings.rb new file mode 100644 index 00000000000..bccbc4e3209 --- /dev/null +++ b/db/post_migrate/20211022214523_schedule_recalculate_vulnerability_finding_signatures_for_findings.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ScheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Database::Migration[1.0] + MIGRATION = 'RecalculateVulnerabilityFindingSignaturesForFindings' + BATCH_SIZE = 1_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('vulnerability_finding_signatures'), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211023102243_schedule_delete_invalid_epic_issues.rb b/db/post_migrate/20211023102243_schedule_delete_invalid_epic_issues.rb new file mode 100644 index 00000000000..e08ad8d89d1 --- /dev/null +++ b/db/post_migrate/20211023102243_schedule_delete_invalid_epic_issues.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class ScheduleDeleteInvalidEpicIssues < Gitlab::Database::Migration[1.0] + # This is a now a no-op + # See https://gitlab.com/gitlab-org/gitlab/-/issues/348477 + + def up + # no-op + end + + def down + # also no-op + end +end diff --git a/db/post_migrate/20211027043206_track_ci_pipeline_deletions.rb b/db/post_migrate/20211027043206_track_ci_pipeline_deletions.rb new file mode 100644 index 00000000000..3836159c2cd --- /dev/null +++ b/db/post_migrate/20211027043206_track_ci_pipeline_deletions.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackCiPipelineDeletions < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:ci_pipelines) + end + + def down + untrack_record_deletions(:ci_pipelines) + end +end diff --git a/db/post_migrate/20211027043229_track_ci_build_deletions.rb b/db/post_migrate/20211027043229_track_ci_build_deletions.rb new file mode 100644 index 00000000000..b76d5f3261c --- /dev/null +++ b/db/post_migrate/20211027043229_track_ci_build_deletions.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackCiBuildDeletions < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:ci_builds) + end + + def down + untrack_record_deletions(:ci_builds) + end +end diff --git a/db/post_migrate/20211101222614_consume_remaining_user_namespace_jobs.rb b/db/post_migrate/20211101222614_consume_remaining_user_namespace_jobs.rb new file mode 100644 index 00000000000..ded9e717bb1 --- /dev/null +++ b/db/post_migrate/20211101222614_consume_remaining_user_namespace_jobs.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class ConsumeRemainingUserNamespaceJobs < Gitlab::Database::Migration[1.0] + MIGRATION = 'BackfillUserNamespace' + BATCH_SIZE = 200 + DEFAULT_VALUE = 'User' + + disable_ddl_transaction! + + def up + Gitlab::BackgroundMigration.steal(MIGRATION) + + # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low. + define_batchable_model('namespaces').where(type: nil).each_batch(of: BATCH_SIZE) do |batch| + min, max = batch.pluck('MIN(id), MAX(id)').flatten + + Gitlab::BackgroundMigration::BackfillUserNamespace.new.perform(min, max, :namespaces, :id, BATCH_SIZE, 0) + end + + change_column_null :namespaces, :type, false + end + + def down + change_column_null :namespaces, :type, true + end +end diff --git a/db/post_migrate/20211103141403_remove_propagate_service_template_worker.rb b/db/post_migrate/20211103141403_remove_propagate_service_template_worker.rb new file mode 100644 index 00000000000..d949641dbce --- /dev/null +++ b/db/post_migrate/20211103141403_remove_propagate_service_template_worker.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemovePropagateServiceTemplateWorker < Gitlab::Database::Migration[1.0] + def up + Sidekiq::Queue.new('propagate_service_template').clear + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211104165220_remove_vulnerability_finding_links.rb b/db/post_migrate/20211104165220_remove_vulnerability_finding_links.rb new file mode 100644 index 00000000000..fc50aa812a7 --- /dev/null +++ b/db/post_migrate/20211104165220_remove_vulnerability_finding_links.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveVulnerabilityFindingLinks < Gitlab::Database::Migration[1.0] + BATCH_SIZE = 50_000 + MIGRATION = 'RemoveVulnerabilityFindingLinks' + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('vulnerability_finding_links'), + MIGRATION, + 2.minutes, + batch_size: BATCH_SIZE + ) + end + + def down + # no ops + end +end diff --git a/db/post_migrate/20211110143306_add_not_null_constraint_to_security_findings_uuid.rb b/db/post_migrate/20211110143306_add_not_null_constraint_to_security_findings_uuid.rb new file mode 100644 index 00000000000..bdb8f5cd120 --- /dev/null +++ b/db/post_migrate/20211110143306_add_not_null_constraint_to_security_findings_uuid.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddNotNullConstraintToSecurityFindingsUuid < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_not_null_constraint( + :security_findings, + :uuid, + validate: false + ) + end + + def down + remove_not_null_constraint( + :security_findings, + :uuid + ) + end +end diff --git a/db/post_migrate/20211110151320_add_temporary_index_on_security_findings_uuid.rb b/db/post_migrate/20211110151320_add_temporary_index_on_security_findings_uuid.rb new file mode 100644 index 00000000000..7bc4af0ec4d --- /dev/null +++ b/db/post_migrate/20211110151320_add_temporary_index_on_security_findings_uuid.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddTemporaryIndexOnSecurityFindingsUuid < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = "tmp_index_uuid_is_null" + + def up + add_concurrent_index( + :security_findings, + :id, + where: "uuid IS NULL", + name: INDEX_NAME + ) + end + + def down + remove_concurrent_index_by_name( + :security_findings, + INDEX_NAME + ) + end +end diff --git a/db/post_migrate/20211110151350_schedule_drop_invalid_security_findings.rb b/db/post_migrate/20211110151350_schedule_drop_invalid_security_findings.rb new file mode 100644 index 00000000000..98e7b2a8a15 --- /dev/null +++ b/db/post_migrate/20211110151350_schedule_drop_invalid_security_findings.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ScheduleDropInvalidSecurityFindings < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = "DropInvalidSecurityFindings" + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 100_000 + SUB_BATCH_SIZE = 10_000 + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('security_findings').where(uuid: nil), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + other_job_arguments: [SUB_BATCH_SIZE], + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211116091751_change_namespace_type_default_to_user.rb b/db/post_migrate/20211116091751_change_namespace_type_default_to_user.rb new file mode 100644 index 00000000000..468b26e9eb1 --- /dev/null +++ b/db/post_migrate/20211116091751_change_namespace_type_default_to_user.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ChangeNamespaceTypeDefaultToUser < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + change_column_default :namespaces, :type, 'User' + end + end + + def down + with_lock_retries do + change_column_default :namespaces, :type, nil + end + end +end diff --git a/db/post_migrate/20211116111644_schedule_remove_occurrence_pipelines_and_duplicate_vulnerabilities_findings.rb b/db/post_migrate/20211116111644_schedule_remove_occurrence_pipelines_and_duplicate_vulnerabilities_findings.rb new file mode 100644 index 00000000000..0424d32a81e --- /dev/null +++ b/db/post_migrate/20211116111644_schedule_remove_occurrence_pipelines_and_duplicate_vulnerabilities_findings.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ScheduleRemoveOccurrencePipelinesAndDuplicateVulnerabilitiesFindings < Gitlab::Database::Migration[1.0] + MIGRATION = 'RemoveOccurrencePipelinesAndDuplicateVulnerabilitiesFindings' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 10_000 + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('vulnerability_occurrences'), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211117084814_migrate_remaining_u2f_registrations.rb b/db/post_migrate/20211117084814_migrate_remaining_u2f_registrations.rb new file mode 100644 index 00000000000..ae9dba32a4a --- /dev/null +++ b/db/post_migrate/20211117084814_migrate_remaining_u2f_registrations.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class MigrateRemainingU2fRegistrations < Gitlab::Database::Migration[1.0] + BATCH_SIZE = 100 + + disable_ddl_transaction! + + def up + # We expect only a few number of records satisfying these conditions. + # on gitlab.com database, this number is 70 as on 17th Nov, 2021. + define_batchable_model('u2f_registrations') + .joins("LEFT JOIN webauthn_registrations ON webauthn_registrations.u2f_registration_id = u2f_registrations.id") + .where(webauthn_registrations: { u2f_registration_id: nil }) + .each_batch(of: BATCH_SIZE) do |batch, index| + batch.each do |record| + Gitlab::BackgroundMigration::MigrateU2fWebauthn.new.perform(record.id, record.id) + rescue StandardError => e + Gitlab::ErrorTracking.track_exception(e, u2f_registration_id: record.id) + end + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211118130836_drop_pages_deployments_builds_fk.rb b/db/post_migrate/20211118130836_drop_pages_deployments_builds_fk.rb new file mode 100644 index 00000000000..5eb532f2a00 --- /dev/null +++ b/db/post_migrate/20211118130836_drop_pages_deployments_builds_fk.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class DropPagesDeploymentsBuildsFk < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + FK_NAME = 'fk_rails_c3a90cf29b' + + def up + remove_foreign_key_if_exists(:pages_deployments, :ci_builds, name: FK_NAME) + end + + def down + add_concurrent_foreign_key( + :pages_deployments, + :ci_builds, + name: FK_NAME, + column: :ci_build_id, + target_column: :id, + on_delete: :nullify + ) + end +end diff --git a/db/post_migrate/20211118194239_drop_invalid_remediations.rb b/db/post_migrate/20211118194239_drop_invalid_remediations.rb new file mode 100644 index 00000000000..93edde87936 --- /dev/null +++ b/db/post_migrate/20211118194239_drop_invalid_remediations.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class DropInvalidRemediations < Gitlab::Database::Migration[1.0] + BATCH_SIZE = 3_000 + DELAY_INTERVAL = 3.minutes + MIGRATION_NAME = 'DropInvalidRemediations' + DAY_PRIOR_TO_BUG_INTRODUCTION = DateTime.new(2021, 8, 1, 0, 0, 0) + + disable_ddl_transaction! + + def up + return unless Gitlab.ee? + + relation = Gitlab::BackgroundMigration::DropInvalidRemediations::FindingRemediation.where("created_at > ?", DAY_PRIOR_TO_BUG_INTRODUCTION) + queue_background_migration_jobs_by_range_at_intervals(relation, + MIGRATION_NAME, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211119085036_add_text_limit_to_job_artifact_original_filename.rb b/db/post_migrate/20211119085036_add_text_limit_to_job_artifact_original_filename.rb new file mode 100644 index 00000000000..3eccbb1b3a4 --- /dev/null +++ b/db/post_migrate/20211119085036_add_text_limit_to_job_artifact_original_filename.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToJobArtifactOriginalFilename < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :ci_job_artifacts, :original_filename, 512 + end + + def down + remove_text_limit :ci_job_artifacts, :original_filename + end +end diff --git a/db/post_migrate/20211122033501_improve_index_on_events_for_calendar.rb b/db/post_migrate/20211122033501_improve_index_on_events_for_calendar.rb new file mode 100644 index 00000000000..517e0f08d6a --- /dev/null +++ b/db/post_migrate/20211122033501_improve_index_on_events_for_calendar.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ImproveIndexOnEventsForCalendar < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_events_author_id_project_id_action_target_type_created_at' + + def up + prepare_async_index :events, [:author_id, :project_id, :action, :target_type, :created_at], name: INDEX_NAME + end + + def down + unprepare_async_index :events, [:author_id, :project_id, :action, :target_type, :created_at], name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211122193948_cleanup_background_migration_of_requirements_to_work_items.rb b/db/post_migrate/20211122193948_cleanup_background_migration_of_requirements_to_work_items.rb new file mode 100644 index 00000000000..df4867d6ae7 --- /dev/null +++ b/db/post_migrate/20211122193948_cleanup_background_migration_of_requirements_to_work_items.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class CleanupBackgroundMigrationOfRequirementsToWorkItems < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'MigrateRequirementsToWorkItems' + + disable_ddl_transaction! + + def up + finalize_background_migration(MIGRATION) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211124132705_change_index_users_on_public_email.rb b/db/post_migrate/20211124132705_change_index_users_on_public_email.rb new file mode 100644 index 00000000000..6e74a325033 --- /dev/null +++ b/db/post_migrate/20211124132705_change_index_users_on_public_email.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class ChangeIndexUsersOnPublicEmail < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_users_on_public_email' + INDEX_EXCLUDING_NULL_NAME = 'index_users_on_public_email_excluding_null_and_empty' + + disable_ddl_transaction! + + def up + index_condition = "public_email != '' AND public_email IS NOT NULL" + + add_concurrent_index :users, [:public_email], where: index_condition, name: INDEX_EXCLUDING_NULL_NAME + remove_concurrent_index_by_name :users, INDEX_NAME + end + + def down + index_condition = "public_email != ''" + + add_concurrent_index :users, [:public_email], where: index_condition, name: INDEX_NAME + remove_concurrent_index_by_name :users, INDEX_EXCLUDING_NULL_NAME + end +end diff --git a/db/post_migrate/20211125120444_add_index_todos_project_id_user_id.rb b/db/post_migrate/20211125120444_add_index_todos_project_id_user_id.rb new file mode 100644 index 00000000000..5cc78fc75c4 --- /dev/null +++ b/db/post_migrate/20211125120444_add_index_todos_project_id_user_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexTodosProjectIdUserId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_todos_on_project_id_and_user_id_and_id' + + def up + add_concurrent_index :todos, [:project_id, :user_id, :id], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :todos, INDEX_NAME + end +end diff --git a/db/post_migrate/20211130165043_backfill_sequence_column_for_sprints_table.rb b/db/post_migrate/20211130165043_backfill_sequence_column_for_sprints_table.rb new file mode 100644 index 00000000000..420bfb8bcbc --- /dev/null +++ b/db/post_migrate/20211130165043_backfill_sequence_column_for_sprints_table.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class BackfillSequenceColumnForSprintsTable < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def up + execute( + <<-SQL + UPDATE sprints + SET sequence=t.row_number + FROM ( + SELECT id, row_number() OVER (PARTITION BY iterations_cadence_id ORDER BY start_date) + FROM sprints as s1 + WHERE s1.iterations_cadence_id IS NOT NULL + ) as t + WHERE t.id=sprints.id AND (sprints.sequence IS NULL OR sprints.sequence <> t.row_number) + SQL + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211130201100_track_deletions_in_namespaces.rb b/db/post_migrate/20211130201100_track_deletions_in_namespaces.rb new file mode 100644 index 00000000000..e688e0b467d --- /dev/null +++ b/db/post_migrate/20211130201100_track_deletions_in_namespaces.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackDeletionsInNamespaces < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:namespaces) + end + + def down + untrack_record_deletions(:namespaces) + end +end diff --git a/db/post_migrate/20211130201101_track_deletions_in_projects.rb b/db/post_migrate/20211130201101_track_deletions_in_projects.rb new file mode 100644 index 00000000000..dfe7ab4c037 --- /dev/null +++ b/db/post_migrate/20211130201101_track_deletions_in_projects.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackDeletionsInProjects < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:projects) + end + + def down + untrack_record_deletions(:projects) + end +end diff --git a/db/post_migrate/20211201101541_drop_clusters_applications_runners_ci_runners_fk.rb b/db/post_migrate/20211201101541_drop_clusters_applications_runners_ci_runners_fk.rb new file mode 100644 index 00000000000..9a02f64e350 --- /dev/null +++ b/db/post_migrate/20211201101541_drop_clusters_applications_runners_ci_runners_fk.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class DropClustersApplicationsRunnersCiRunnersFk < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:clusters_applications_runners, :ci_runners, name: 'fk_02de2ded36') + end + end + + def down + add_concurrent_foreign_key(:clusters_applications_runners, :ci_runners, name: 'fk_02de2ded36', column: :runner_id, target_column: :id, on_delete: 'set null') + end +end diff --git a/db/post_migrate/20211202145237_add_todos_project_and_id_index.rb b/db/post_migrate/20211202145237_add_todos_project_and_id_index.rb new file mode 100644 index 00000000000..69f7822c057 --- /dev/null +++ b/db/post_migrate/20211202145237_add_todos_project_and_id_index.rb @@ -0,0 +1,32 @@ +# 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 AddTodosProjectAndIdIndex < Gitlab::Database::Migration[1.0] + # When using the methods "add_concurrent_index" or "remove_concurrent_index" + # you must disable the use of transactions + # as these methods can not run in an existing transaction. + # When using "add_concurrent_index" or "remove_concurrent_index" methods make sure + # that either of them is the _only_ method called in the migration, + # any other changes should go in a separate migration. + # This ensures that upon failure _only_ the index creation or removing fails + # and can be retried or reverted easily. + # + # To disable transactions uncomment the following line and remove these + # comments: + disable_ddl_transaction! + + NEW_INDEX_NAME = 'index_todos_on_project_id_and_id' + OLD_INDEX_NAME = 'index_todos_on_project_id' + + def up + add_concurrent_index :todos, [:project_id, :id], name: NEW_INDEX_NAME + remove_concurrent_index_by_name :todos, OLD_INDEX_NAME + end + + def down + add_concurrent_index :todos, :project_id, name: OLD_INDEX_NAME + remove_concurrent_index_by_name :todos, NEW_INDEX_NAME + end +end diff --git a/db/post_migrate/20211203091642_add_index_to_projects_on_marked_for_deletion_at.rb b/db/post_migrate/20211203091642_add_index_to_projects_on_marked_for_deletion_at.rb new file mode 100644 index 00000000000..56b0df1f393 --- /dev/null +++ b/db/post_migrate/20211203091642_add_index_to_projects_on_marked_for_deletion_at.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexToProjectsOnMarkedForDeletionAt < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_projects_not_aimed_for_deletion' + + def up + add_concurrent_index :projects, :id, where: 'marked_for_deletion_at IS NULL', name: INDEX_NAME + end + + def down + remove_concurrent_index :projects, :id, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211206073851_create_calendar_events_index_synchronously.rb b/db/post_migrate/20211206073851_create_calendar_events_index_synchronously.rb new file mode 100644 index 00000000000..020dceac004 --- /dev/null +++ b/db/post_migrate/20211206073851_create_calendar_events_index_synchronously.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CreateCalendarEventsIndexSynchronously < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_events_author_id_project_id_action_target_type_created_at' + + def up + add_concurrent_index :events, [:author_id, :project_id, :action, :target_type, :created_at], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :events, INDEX_NAME + end +end diff --git a/db/post_migrate/20211206074547_remove_old_calendar_events_index.rb b/db/post_migrate/20211206074547_remove_old_calendar_events_index.rb new file mode 100644 index 00000000000..51460a9dc95 --- /dev/null +++ b/db/post_migrate/20211206074547_remove_old_calendar_events_index.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveOldCalendarEventsIndex < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_events_on_author_id_and_project_id' + + def up + remove_concurrent_index_by_name :events, OLD_INDEX_NAME + end + + def down + add_concurrent_index :events, [:author_id, :project_id], name: OLD_INDEX_NAME + end +end diff --git a/db/post_migrate/20211207090503_cleanup_first_mentioned_in_commit_jobs.rb b/db/post_migrate/20211207090503_cleanup_first_mentioned_in_commit_jobs.rb new file mode 100644 index 00000000000..3788a680fb6 --- /dev/null +++ b/db/post_migrate/20211207090503_cleanup_first_mentioned_in_commit_jobs.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class CleanupFirstMentionedInCommitJobs < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'FixFirstMentionedInCommitAt' + INDEX_NAME = 'index_issue_metrics_first_mentioned_in_commit' + + def up + finalize_background_migration(MIGRATION) + + remove_concurrent_index_by_name :issue_metrics, name: INDEX_NAME + end + + def down + # Handles reported schema inconsistencies (column with or without timezone) + # We did the same in db/post_migrate/20211004110500_add_temporary_index_to_issue_metrics.rb + condition = Gitlab::BackgroundMigration::FixFirstMentionedInCommitAt::TmpIssueMetrics + .first_mentioned_in_commit_at_condition + add_concurrent_index :issue_metrics, :issue_id, where: condition, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211208171402_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb b/db/post_migrate/20211208171402_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb new file mode 100644 index 00000000000..8eee082809b --- /dev/null +++ b/db/post_migrate/20211208171402_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class RescheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Database::Migration[1.0] + MIGRATION = 'RecalculateVulnerabilityFindingSignaturesForFindings' + BATCH_SIZE = 1_000 + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + # Due to production incident previous migration was orphaned and must be rescheduled, + # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72919#note_741188600 + def up + return unless Gitlab.ee? + + delete_queued_jobs(MIGRATION) + + requeue_background_migration_jobs_by_range_at_intervals( + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211209093636_track_ci_job_artifacts_deletes.rb b/db/post_migrate/20211209093636_track_ci_job_artifacts_deletes.rb new file mode 100644 index 00000000000..8c95c76d1fe --- /dev/null +++ b/db/post_migrate/20211209093636_track_ci_job_artifacts_deletes.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackCiJobArtifactsDeletes < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:ci_job_artifacts) + end + + def down + untrack_record_deletions(:ci_job_artifacts) + end +end diff --git a/db/post_migrate/20211209093828_track_users_deletes.rb b/db/post_migrate/20211209093828_track_users_deletes.rb new file mode 100644 index 00000000000..e25a8a36cb2 --- /dev/null +++ b/db/post_migrate/20211209093828_track_users_deletes.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackUsersDeletes < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:users) + end + + def down + untrack_record_deletions(:users) + end +end diff --git a/db/post_migrate/20211209093923_track_external_pull_requests_deletes.rb b/db/post_migrate/20211209093923_track_external_pull_requests_deletes.rb new file mode 100644 index 00000000000..cd8a6baf407 --- /dev/null +++ b/db/post_migrate/20211209093923_track_external_pull_requests_deletes.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackExternalPullRequestsDeletes < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:external_pull_requests) + end + + def down + untrack_record_deletions(:external_pull_requests) + end +end diff --git a/db/post_migrate/20211209094222_track_merge_requests_deletes.rb b/db/post_migrate/20211209094222_track_merge_requests_deletes.rb new file mode 100644 index 00000000000..51007082e9e --- /dev/null +++ b/db/post_migrate/20211209094222_track_merge_requests_deletes.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackMergeRequestsDeletes < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:merge_requests) + end + + def down + untrack_record_deletions(:merge_requests) + end +end diff --git a/db/post_migrate/20211210173137_remove_vulnerability_finding_links_again.rb b/db/post_migrate/20211210173137_remove_vulnerability_finding_links_again.rb new file mode 100644 index 00000000000..98ac4433193 --- /dev/null +++ b/db/post_migrate/20211210173137_remove_vulnerability_finding_links_again.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveVulnerabilityFindingLinksAgain < Gitlab::Database::Migration[1.0] + BATCH_SIZE = 50_000 + MIGRATION = 'RemoveVulnerabilityFindingLinks' + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('vulnerability_finding_links'), + MIGRATION, + 2.minutes, + batch_size: BATCH_SIZE + ) + end + + def down + # no ops + end +end diff --git a/db/post_migrate/20211213064821_add_agent_id_location_index_to_vulnerability_occurrences.rb b/db/post_migrate/20211213064821_add_agent_id_location_index_to_vulnerability_occurrences.rb new file mode 100644 index 00000000000..92b5a1b085c --- /dev/null +++ b/db/post_migrate/20211213064821_add_agent_id_location_index_to_vulnerability_occurrences.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddAgentIdLocationIndexToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_vulnerability_occurrences_on_location_agent_id' + + def up + add_concurrent_index :vulnerability_occurrences, "(location -> 'agent_id')", + using: 'GIN', + where: 'report_type = 7', + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME + end +end diff --git a/db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb b/db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb new file mode 100644 index 00000000000..49f498c911d --- /dev/null +++ b/db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class DropCiPipelinesMrMetricsFk < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:merge_request_metrics, :ci_pipelines, name: "fk_rails_33ae169d48") + end + end + + def down + add_concurrent_foreign_key(:merge_request_metrics, :ci_pipelines, name: "fk_rails_33ae169d48", column: :pipeline_id, target_column: :id, on_delete: "cascade") + end +end diff --git a/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb b/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb new file mode 100644 index 00000000000..5876d3f8a9a --- /dev/null +++ b/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ScheduleUpdateTimelogsNullSpentAt < Gitlab::Database::Migration[1.0] + DOWNTIME = false + BATCH_SIZE = 5_000 + DELAY_INTERVAL = 2.minutes + MIGRATION = 'UpdateTimelogsNullSpentAt' + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('timelogs').where(spent_at: nil), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end |