diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /db/post_migrate | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'db/post_migrate')
55 files changed, 1122 insertions, 20 deletions
diff --git a/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb b/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb index 7f0168be1a4..f8239b6e0cd 100644 --- a/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb +++ b/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb @@ -1,26 +1,9 @@ # frozen_string_literal: true class BackfillIncidentIssueEscalationStatuses < Gitlab::Database::Migration[1.0] - MIGRATION = 'BackfillIncidentIssueEscalationStatuses' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 20_000 - - disable_ddl_transaction! - - class Issue < ActiveRecord::Base - include EachBatch - - self.table_name = 'issues' - end - - def up - relation = Issue.all - - queue_background_migration_jobs_by_range_at_intervals( - relation, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE, track_jobs: true) - end - - def down + # Removed in favor of creating records for existing incidents + # as-needed. See db/migrate/20220321234317_remove_all_issuable_escalation_statuses.rb. + def change # no-op end end diff --git a/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb b/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb new file mode 100644 index 00000000000..49c9efc497c --- /dev/null +++ b/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class BackfillNamespaceStatisticsWithDependencyProxySize < Gitlab::Database::Migration[1.0] + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 500 + MIGRATION = 'PopulateNamespaceStatistics' + + disable_ddl_transaction! + + def up + groups = exec_query <<~SQL + SELECT dependency_proxy_manifests.group_id FROM dependency_proxy_manifests + UNION + SELECT dependency_proxy_blobs.group_id from dependency_proxy_blobs + SQL + + groups.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |group_ids, index| + migrate_in(index * DELAY_INTERVAL, MIGRATION, [group_ids, [:dependency_proxy_size]]) + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220223124428_schedule_merge_topics_with_same_name.rb b/db/post_migrate/20220223124428_schedule_merge_topics_with_same_name.rb new file mode 100644 index 00000000000..7e79c89203a --- /dev/null +++ b/db/post_migrate/20220223124428_schedule_merge_topics_with_same_name.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ScheduleMergeTopicsWithSameName < Gitlab::Database::Migration[1.0] + MIGRATION = 'MergeTopicsWithSameName' + BATCH_SIZE = 100 + + disable_ddl_transaction! + + class Topic < ActiveRecord::Base + self.table_name = 'topics' + end + + def up + Topic.select('LOWER(name) as name').group('LOWER(name)').having('COUNT(*) > 1').order('LOWER(name)') + .in_groups_of(BATCH_SIZE, false).each_with_index do |group, i| + migrate_in((i + 1) * 2.minutes, MIGRATION, [group.map(&:name)]) + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220302114046_backfill_group_features.rb b/db/post_migrate/20220302114046_backfill_group_features.rb new file mode 100644 index 00000000000..dd8961b8bee --- /dev/null +++ b/db/post_migrate/20220302114046_backfill_group_features.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class BackfillGroupFeatures < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'BackfillGroupFeatures' + INTERVAL = 2.minutes + BATCH_SIZE = 10_000 + SUB_BATCH_SIZE = 1_000 + + def up + queue_batched_background_migration( + MIGRATION, + :namespaces, + :id, + BATCH_SIZE, + job_interval: INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + Gitlab::Database::BackgroundMigration::BatchedMigration + .for_configuration(MIGRATION, :namespaces, :id, [BATCH_SIZE]) + .delete_all + end +end diff --git a/db/post_migrate/20220311010352_create_scan_id_and_id_index_on_security_findings.rb b/db/post_migrate/20220311010352_create_scan_id_and_id_index_on_security_findings.rb new file mode 100644 index 00000000000..1b72c4b0a78 --- /dev/null +++ b/db/post_migrate/20220311010352_create_scan_id_and_id_index_on_security_findings.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CreateScanIdAndIdIndexOnSecurityFindings < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_security_findings_on_scan_id_and_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :security_findings, [:scan_id, :id], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :security_findings, INDEX_NAME + end +end diff --git a/db/post_migrate/20220315171027_add_tmp_index_to_support_leaky_regex_cleanup.rb b/db/post_migrate/20220315171027_add_tmp_index_to_support_leaky_regex_cleanup.rb new file mode 100644 index 00000000000..6f4bd29337e --- /dev/null +++ b/db/post_migrate/20220315171027_add_tmp_index_to_support_leaky_regex_cleanup.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddTmpIndexToSupportLeakyRegexCleanup < Gitlab::Database::Migration[1.0] + INDEX_NAME = "tmp_index_merge_requests_draft_and_status_leaky_regex" + LEAKY_REGEXP_STR = "^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP" + CORRECTED_REGEXP_STR = "^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)" + + disable_ddl_transaction! + + def up + add_concurrent_index :merge_requests, :id, + where: "draft = true AND state_id = 1 AND ((title)::text ~* '#{LEAKY_REGEXP_STR}'::text) AND ((title)::text !~* '#{CORRECTED_REGEXP_STR}'::text)", + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :merge_requests, INDEX_NAME + end +end diff --git a/db/post_migrate/20220315171129_cleanup_draft_data_from_faulty_regex.rb b/db/post_migrate/20220315171129_cleanup_draft_data_from_faulty_regex.rb new file mode 100644 index 00000000000..be81bf85f62 --- /dev/null +++ b/db/post_migrate/20220315171129_cleanup_draft_data_from_faulty_regex.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class CleanupDraftDataFromFaultyRegex < Gitlab::Database::Migration[1.0] + MIGRATION = 'CleanupDraftDataFromFaultyRegex' + DELAY_INTERVAL = 5.minutes + BATCH_SIZE = 20 + + disable_ddl_transaction! + + class MergeRequest < ActiveRecord::Base + LEAKY_REGEXP_STR = "^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP" + CORRECTED_REGEXP_STR = "^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)" + + self.table_name = 'merge_requests' + + include ::EachBatch + + def self.eligible + where(state_id: 1) + .where(draft: true) + .where("title ~* ?", LEAKY_REGEXP_STR) + .where("title !~* ?", CORRECTED_REGEXP_STR) + end + end + + def up + return unless Gitlab.com? + + queue_background_migration_jobs_by_range_at_intervals( + MergeRequest.eligible, + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # noop + # + end +end diff --git a/db/post_migrate/20220315181125_remove_issues_work_item_type_id_index.rb b/db/post_migrate/20220315181125_remove_issues_work_item_type_id_index.rb new file mode 100644 index 00000000000..6650201c063 --- /dev/null +++ b/db/post_migrate/20220315181125_remove_issues_work_item_type_id_index.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveIssuesWorkItemTypeIdIndex < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_issues_on_work_item_type_id' + + def up + remove_concurrent_index_by_name :issues, name: INDEX_NAME + end + + def down + add_concurrent_index :issues, :work_item_type_id, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220315181130_add_temporary_issue_type_index_for_work_item_types.rb b/db/post_migrate/20220315181130_add_temporary_issue_type_index_for_work_item_types.rb new file mode 100644 index 00000000000..52c525d81fb --- /dev/null +++ b/db/post_migrate/20220315181130_add_temporary_issue_type_index_for_work_item_types.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTemporaryIssueTypeIndexForWorkItemTypes < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'tmp_index_issues_on_issue_type_and_id' + + def up + add_concurrent_index :issues, [:issue_type, :id], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :issues, INDEX_NAME + end +end diff --git a/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb b/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb new file mode 100644 index 00000000000..8838a27f233 --- /dev/null +++ b/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class BackfillWorkItemTypeIdOnIssues < Gitlab::Database::Migration[1.0] + MIGRATION = 'BackfillWorkItemTypeIdForIssues' + BATCH_CLASS_NAME = 'BackfillIssueWorkItemTypeBatchingStrategy' + BATCH_SIZE = 10_000 + MAX_BATCH_SIZE = 30_000 + SUB_BATCH_SIZE = 100 + INTERVAL = 2.minutes + + class MigrationWorkItemType < ApplicationRecord + self.table_name = 'work_item_types' + + def self.id_by_type + where(namespace_id: nil).order(:base_type).pluck(:base_type, :id).to_h + end + end + + def up + # We expect no more than 5 types. Only 3 of them are expected to have associated issues at the moment + MigrationWorkItemType.id_by_type.each do |base_type, type_id| + queue_batched_background_migration( + MIGRATION, + :issues, + :id, + base_type, + type_id, + job_interval: INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE, + batch_class_name: BATCH_CLASS_NAME + ) + end + end + + def down + Gitlab::Database::BackgroundMigration::BatchedMigration.where(job_class_name: MIGRATION).delete_all + end +end diff --git a/db/post_migrate/20220315211043_add_index_to_vulnerability_reads.rb b/db/post_migrate/20220315211043_add_index_to_vulnerability_reads.rb new file mode 100644 index 00000000000..9fe78fb0a4e --- /dev/null +++ b/db/post_migrate/20220315211043_add_index_to_vulnerability_reads.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddIndexToVulnerabilityReads < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_vulnerability_reads_common_finder_query' + + disable_ddl_transaction! + + def up + add_concurrent_index( + :vulnerability_reads, + %i[project_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/20220316102900_add_index_to_deploy_tokens_on_creator_id.rb b/db/post_migrate/20220316102900_add_index_to_deploy_tokens_on_creator_id.rb new file mode 100644 index 00000000000..7cc942c813b --- /dev/null +++ b/db/post_migrate/20220316102900_add_index_to_deploy_tokens_on_creator_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexToDeployTokensOnCreatorId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_deploy_tokens_on_creator_id' + + def up + add_concurrent_index :deploy_tokens, :creator_id, name: INDEX_NAME + end + + def down + remove_concurrent_index :deploy_tokens, :creator_id, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220316102902_add_user_foreign_key_to_deploy_tokens.rb b/db/post_migrate/20220316102902_add_user_foreign_key_to_deploy_tokens.rb new file mode 100644 index 00000000000..57379e4c752 --- /dev/null +++ b/db/post_migrate/20220316102902_add_user_foreign_key_to_deploy_tokens.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddUserForeignKeyToDeployTokens < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :deploy_tokens, :users, column: :creator_id, on_delete: :nullify, reverse_lock_order: true + end + + def down + with_lock_retries do + remove_foreign_key :deploy_tokens, column: :creator_id + end + end +end diff --git a/db/post_migrate/20220316112118_update_organizations_name_index_add_id.rb b/db/post_migrate/20220316112118_update_organizations_name_index_add_id.rb new file mode 100644 index 00000000000..4d78e78e9db --- /dev/null +++ b/db/post_migrate/20220316112118_update_organizations_name_index_add_id.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class UpdateOrganizationsNameIndexAddId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + OLD_INDEX = 'index_customer_relations_organizations_on_unique_name_per_group' + NEW_INDEX = 'index_organizations_on_unique_name_per_group' + + def up + add_concurrent_index :customer_relations_organizations, 'group_id, lower(name), id', name: NEW_INDEX, unique: true + + remove_concurrent_index_by_name :customer_relations_organizations, OLD_INDEX + end + + def down + add_concurrent_index :customer_relations_organizations, 'group_id, lower(name)', name: OLD_INDEX, unique: true + + remove_concurrent_index_by_name :customer_relations_organizations, NEW_INDEX + end +end diff --git a/db/post_migrate/20220316112206_add_contacts_index_on_group_email_and_id.rb b/db/post_migrate/20220316112206_add_contacts_index_on_group_email_and_id.rb new file mode 100644 index 00000000000..21434a80314 --- /dev/null +++ b/db/post_migrate/20220316112206_add_contacts_index_on_group_email_and_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddContactsIndexOnGroupEmailAndId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_customer_relations_contacts_on_unique_email_per_group' + + def up + add_concurrent_index :customer_relations_contacts, 'group_id, lower(email), id', name: INDEX_NAME, unique: true + end + + def down + remove_concurrent_index_by_name :customer_relations_contacts, INDEX_NAME + end +end diff --git a/db/post_migrate/20220316165539_add_index_to_vulnerabilities.rb b/db/post_migrate/20220316165539_add_index_to_vulnerabilities.rb new file mode 100644 index 00000000000..1128ccd7b16 --- /dev/null +++ b/db/post_migrate/20220316165539_add_index_to_vulnerabilities.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddIndexToVulnerabilities < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_vulnerabilites_common_finder_query' + + disable_ddl_transaction! + + def up + add_concurrent_index( + :vulnerabilities, + %i[project_id state report_type severity id], + name: INDEX_NAME + ) + end + + def down + remove_concurrent_index_by_name( + :vulnerabilities, + INDEX_NAME + ) + end +end diff --git a/db/post_migrate/20220316202640_populate_container_repositories_migration_plan.rb b/db/post_migrate/20220316202640_populate_container_repositories_migration_plan.rb new file mode 100644 index 00000000000..7eef227ec3c --- /dev/null +++ b/db/post_migrate/20220316202640_populate_container_repositories_migration_plan.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class PopulateContainerRepositoriesMigrationPlan < Gitlab::Database::Migration[1.0] + MIGRATION = 'PopulateContainerRepositoryMigrationPlan' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 1500 + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('container_repositories'), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220317161914_remove_ci_runners_ci_builds_runner_id_fk.rb b/db/post_migrate/20220317161914_remove_ci_runners_ci_builds_runner_id_fk.rb new file mode 100644 index 00000000000..3c7c4e73199 --- /dev/null +++ b/db/post_migrate/20220317161914_remove_ci_runners_ci_builds_runner_id_fk.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveCiRunnersCiBuildsRunnerIdFk < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + return unless foreign_key_exists?(:ci_builds, :ci_runners, name: "fk_e4ef9c2f27") + + with_lock_retries do + execute('LOCK ci_runners, ci_builds IN ACCESS EXCLUSIVE MODE') if transaction_open? + + remove_foreign_key_if_exists(:ci_builds, :ci_runners, name: "fk_e4ef9c2f27") + end + end + + def down + add_concurrent_foreign_key :ci_builds, :ci_runners, name: "fk_e4ef9c2f27", column: :runner_id, target_column: :id, on_delete: :nullify, validate: false + end +end diff --git a/db/post_migrate/20220318111040_add_indexes_for_primary_email_second_cleanup_migration.rb b/db/post_migrate/20220318111040_add_indexes_for_primary_email_second_cleanup_migration.rb new file mode 100644 index 00000000000..5dcb99b36b6 --- /dev/null +++ b/db/post_migrate/20220318111040_add_indexes_for_primary_email_second_cleanup_migration.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class AddIndexesForPrimaryEmailSecondCleanupMigration < Gitlab::Database::Migration[1.0] + USERS_INDEX = :index_users_on_id_for_primary_email_migration + EMAIL_INDEX = :index_emails_on_email_user_id + + disable_ddl_transaction! + + def up + unless index_exists_by_name?(:users, USERS_INDEX) + + disable_statement_timeout do + execute <<~SQL + CREATE INDEX CONCURRENTLY #{USERS_INDEX} + ON users (id) INCLUDE (email, confirmed_at) + WHERE confirmed_at IS NOT NULL + SQL + end + end + + add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX + end + + def down + remove_concurrent_index_by_name :users, USERS_INDEX + remove_concurrent_index_by_name :emails, EMAIL_INDEX + end +end diff --git a/db/post_migrate/20220318111729_cleanup_after_fixing_issue_when_admin_changed_primary_email.rb b/db/post_migrate/20220318111729_cleanup_after_fixing_issue_when_admin_changed_primary_email.rb new file mode 100644 index 00000000000..3d29d78573a --- /dev/null +++ b/db/post_migrate/20220318111729_cleanup_after_fixing_issue_when_admin_changed_primary_email.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +class CleanupAfterFixingIssueWhenAdminChangedPrimaryEmail < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + BATCH_SIZE = 10_000 + + # Stubbed class to access the User table + class User < ActiveRecord::Base + include ::EachBatch + + self.table_name = 'users' + self.inheritance_column = :_type_disabled + + scope :confirmed, -> { where.not(confirmed_at: nil) } + + has_many :emails + end + + # Stubbed class to access the Emails table + class Email < ActiveRecord::Base + self.table_name = 'emails' + self.inheritance_column = :_type_disabled + + belongs_to :user + end + + def up + # Select confirmed users that do not have their primary email in the emails table, + # and create the email record. + not_exists_condition = 'NOT EXISTS (SELECT 1 FROM emails WHERE emails.email = users.email AND emails.user_id = users.id)' + + User.confirmed.each_batch(of: BATCH_SIZE) do |user_batch| + user_batch.select(:id, :email, :confirmed_at).where(not_exists_condition).each do |user| + current_time = Time.now.utc + + begin + Email.create( + user_id: user.id, + email: user.email, + confirmed_at: user.confirmed_at, + created_at: current_time, + updated_at: current_time + ) + rescue StandardError => error + Gitlab::AppLogger.error("Could not add primary email #{user.email} to emails for user with ID #{user.id} due to #{error}") + end + end + end + end + + def down + # Intentionally left blank + end +end diff --git a/db/post_migrate/20220318111949_drop_temporary_indexes_for_primary_email_migration_second_cleanup.rb b/db/post_migrate/20220318111949_drop_temporary_indexes_for_primary_email_migration_second_cleanup.rb new file mode 100644 index 00000000000..755751aaa1a --- /dev/null +++ b/db/post_migrate/20220318111949_drop_temporary_indexes_for_primary_email_migration_second_cleanup.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class DropTemporaryIndexesForPrimaryEmailMigrationSecondCleanup < Gitlab::Database::Migration[1.0] + USERS_INDEX = :index_users_on_id_for_primary_email_migration + EMAIL_INDEX = :index_emails_on_email_user_id + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :users, USERS_INDEX + remove_concurrent_index_by_name :emails, EMAIL_INDEX + end + + def down + unless index_exists_by_name?(:users, USERS_INDEX) + + disable_statement_timeout do + execute <<~SQL + CREATE INDEX CONCURRENTLY #{USERS_INDEX} + ON users (id) INCLUDE (email, confirmed_at) + WHERE confirmed_at IS NOT NULL + SQL + end + end + + add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX + end +end diff --git a/db/post_migrate/20220321025720_alter_constraint_remote_import_url.rb b/db/post_migrate/20220321025720_alter_constraint_remote_import_url.rb new file mode 100644 index 00000000000..90cb54cdd44 --- /dev/null +++ b/db/post_migrate/20220321025720_alter_constraint_remote_import_url.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AlterConstraintRemoteImportUrl < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + remove_text_limit :import_export_uploads, :remote_import_url + add_text_limit :import_export_uploads, :remote_import_url, 2048 + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220321201912_remove_user_email_lookup_limit.rb b/db/post_migrate/20220321201912_remove_user_email_lookup_limit.rb new file mode 100644 index 00000000000..a95534b586e --- /dev/null +++ b/db/post_migrate/20220321201912_remove_user_email_lookup_limit.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class RemoveUserEmailLookupLimit < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + remove_column :application_settings, :user_email_lookup_limit + end + + def down + add_column :application_settings, :user_email_lookup_limit, :integer, null: false, default: 60 + end +end diff --git a/db/post_migrate/20220322023800_add_tmp_index_routes_id_for_project_namespaces.rb b/db/post_migrate/20220322023800_add_tmp_index_routes_id_for_project_namespaces.rb new file mode 100644 index 00000000000..bc775514b75 --- /dev/null +++ b/db/post_migrate/20220322023800_add_tmp_index_routes_id_for_project_namespaces.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddTmpIndexRoutesIdForProjectNamespaces < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'tmp_index_for_project_namespace_id_migration_on_routes' + + disable_ddl_transaction! + + def up + # Temporary index to be removed in 15.0 + # https://gitlab.com/gitlab-org/gitlab/-/issues/352353 + add_concurrent_index :routes, :id, where: "namespace_id IS NULL AND source_type = 'Project'", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :routes, INDEX_NAME + end +end diff --git a/db/post_migrate/20220322035654_add_migration_plan_index_to_container_repositories.rb b/db/post_migrate/20220322035654_add_migration_plan_index_to_container_repositories.rb new file mode 100644 index 00000000000..78e331a8b63 --- /dev/null +++ b/db/post_migrate/20220322035654_add_migration_plan_index_to_container_repositories.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddMigrationPlanIndexToContainerRepositories < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'idx_container_repos_on_migration_state_migration_plan_created' + + disable_ddl_transaction! + + def up + add_concurrent_index :container_repositories, + [:migration_state, :migration_plan, :created_at], + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :container_repositories, INDEX_NAME + end +end diff --git a/db/post_migrate/20220322071127_finalize_project_namespaces_backfill.rb b/db/post_migrate/20220322071127_finalize_project_namespaces_backfill.rb new file mode 100644 index 00000000000..5a4d14dcfb7 --- /dev/null +++ b/db/post_migrate/20220322071127_finalize_project_namespaces_backfill.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# This migration acts as a gate-keeper for other migrations related to project namespace back-filling +# so that other migrations that depend on project namespace back-filling cannot be run unless project namespace +# back-filling has finalized successfully. +class FinalizeProjectNamespacesBackfill < Gitlab::Database::Migration[1.0] + MIGRATION = 'ProjectNamespaces::BackfillProjectNamespaces' + + def up + ensure_batched_background_migration_is_finished( + job_class_name: MIGRATION, + table_name: :projects, + column_name: :id, + job_arguments: [nil, 'up'] + ) + end + + def down + # noop + end +end diff --git a/db/post_migrate/20220322094410_remove_wiki_notes.rb b/db/post_migrate/20220322094410_remove_wiki_notes.rb new file mode 100644 index 00000000000..c3705e1e20f --- /dev/null +++ b/db/post_migrate/20220322094410_remove_wiki_notes.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveWikiNotes < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + class Note < ApplicationRecord + self.table_name = 'notes' + self.inheritance_column = :_type_disabled + end + + def up + return unless Gitlab.dev_or_test_env? || Gitlab.staging? || Gitlab.com? + + Note.where(noteable_type: 'Wiki', id: [97, 98, 110, 242, 272]).delete_all + end + + def down + # NO-OP + end +end diff --git a/db/post_migrate/20220322132242_update_pages_onboarding_state.rb b/db/post_migrate/20220322132242_update_pages_onboarding_state.rb new file mode 100644 index 00000000000..896ab78a266 --- /dev/null +++ b/db/post_migrate/20220322132242_update_pages_onboarding_state.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class UpdatePagesOnboardingState < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + BATCH_SIZE = 75 + + def up + define_batchable_model( + :project_pages_metadata + ).where( + deployed: true + ).each_batch( + of: BATCH_SIZE, + column: :project_id + ) do |batch| + batch.update_all(onboarding_complete: true) + end + end + + def down + define_batchable_model( + :project_pages_metadata + ).where( + onboarding_complete: true + ).each_batch( + of: BATCH_SIZE, + column: :project_id + ) do |batch| + batch.update_all(onboarding_complete: false) + end + end +end diff --git a/db/post_migrate/20220322205008_change_search_rate_limit_values.rb b/db/post_migrate/20220322205008_change_search_rate_limit_values.rb new file mode 100644 index 00000000000..ed4aad72ddf --- /dev/null +++ b/db/post_migrate/20220322205008_change_search_rate_limit_values.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class ChangeSearchRateLimitValues < Gitlab::Database::Migration[1.0] + def up + # Change search_rate_limits to a more reasonable value + # as long as they are still using the default values. + # + # The reason why `search_rate_limit` could be either 30 or 60 + # is because its value was ported over from the now deprecated + # `user_email_lookup_limit` which had a default value of 60. + execute("update application_settings set search_rate_limit=300 where search_rate_limit IN (30,60)") + execute("update application_settings set search_rate_limit_unauthenticated=100 where search_rate_limit_unauthenticated = 10") + end + + def down + # noop. Because this migration is updating values, it is not reversible. + end +end diff --git a/db/post_migrate/20220323023800_backfill_namespace_id_for_project_routes.rb b/db/post_migrate/20220323023800_backfill_namespace_id_for_project_routes.rb new file mode 100644 index 00000000000..b938688be2c --- /dev/null +++ b/db/post_migrate/20220323023800_backfill_namespace_id_for_project_routes.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class BackfillNamespaceIdForProjectRoutes < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'BackfillNamespaceIdForProjectRoute' + INTERVAL = 2.minutes + BATCH_SIZE = 1_000 + MAX_BATCH_SIZE = 10_000 + SUB_BATCH_SIZE = 200 + + def up + queue_batched_background_migration( + MIGRATION, + :routes, + :id, + job_interval: INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + Gitlab::Database::BackgroundMigration::BatchedMigration + .for_configuration(MIGRATION, :routes, :id, []) + .delete_all + end +end diff --git a/db/post_migrate/20220323130000_add_temp_index_on_null_project_namespace_ids.rb b/db/post_migrate/20220323130000_add_temp_index_on_null_project_namespace_ids.rb new file mode 100644 index 00000000000..e73993065b0 --- /dev/null +++ b/db/post_migrate/20220323130000_add_temp_index_on_null_project_namespace_ids.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTempIndexOnNullProjectNamespaceIds < Gitlab::Database::Migration[1.0] + TMP_INDEX_FOR_NULL_PROJECT_NAMESPACE_ID = 'tmp_index_for_null_project_namespace_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :projects, :id, name: TMP_INDEX_FOR_NULL_PROJECT_NAMESPACE_ID, where: 'project_namespace_id IS NULL' + end + + def down + remove_concurrent_index_by_name :projects, name: TMP_INDEX_FOR_NULL_PROJECT_NAMESPACE_ID + end +end diff --git a/db/post_migrate/20220323152202_add_index_on_visible_deployments.rb b/db/post_migrate/20220323152202_add_index_on_visible_deployments.rb new file mode 100644 index 00000000000..57ec2f7013d --- /dev/null +++ b/db/post_migrate/20220323152202_add_index_on_visible_deployments.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddIndexOnVisibleDeployments < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_deployments_for_visible_scope' + + def up + add_concurrent_index :deployments, + [:environment_id, :finished_at], + order: { finished_at: :desc }, + where: 'status IN (1, 2, 3, 4, 6)', + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :deployments, INDEX_NAME + end +end diff --git a/db/post_migrate/20220324032250_migrate_shimo_confluence_service_category.rb b/db/post_migrate/20220324032250_migrate_shimo_confluence_service_category.rb new file mode 100644 index 00000000000..d341cc50874 --- /dev/null +++ b/db/post_migrate/20220324032250_migrate_shimo_confluence_service_category.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class MigrateShimoConfluenceServiceCategory < Gitlab::Database::Migration[1.0] + MIGRATION = 'MigrateShimoConfluenceIntegrationCategory' + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 10_000 + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('integrations').where(type_new: %w[Integrations::Confluence Integrations::Shimo]), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true) + end + + def down + end +end diff --git a/db/post_migrate/20220324081709_fix_and_backfill_project_namespaces_for_projects_with_duplicate_name.rb b/db/post_migrate/20220324081709_fix_and_backfill_project_namespaces_for_projects_with_duplicate_name.rb new file mode 100644 index 00000000000..f5927a2cc16 --- /dev/null +++ b/db/post_migrate/20220324081709_fix_and_backfill_project_namespaces_for_projects_with_duplicate_name.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class FixAndBackfillProjectNamespacesForProjectsWithDuplicateName < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'FixDuplicateProjectNameAndPath' + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 1000 + + class Project < ActiveRecord::Base + include ::EachBatch + + self.table_name = 'projects' + + scope :without_project_namespace, -> { where(project_namespace_id: nil) } + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + Project.without_project_namespace, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE, track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220324110247_untrack_deletions_on_ci_job_artifacts.rb b/db/post_migrate/20220324110247_untrack_deletions_on_ci_job_artifacts.rb new file mode 100644 index 00000000000..d178c235e21 --- /dev/null +++ b/db/post_migrate/20220324110247_untrack_deletions_on_ci_job_artifacts.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class UntrackDeletionsOnCiJobArtifacts < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + untrack_record_deletions(:ci_job_artifacts) + end + + def down + track_record_deletions(:ci_job_artifacts) + end +end diff --git a/db/post_migrate/20220324180717_remove_project_pages_metadata_artifacts_archive_id_column.rb b/db/post_migrate/20220324180717_remove_project_pages_metadata_artifacts_archive_id_column.rb new file mode 100644 index 00000000000..287752b6b5c --- /dev/null +++ b/db/post_migrate/20220324180717_remove_project_pages_metadata_artifacts_archive_id_column.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveProjectPagesMetadataArtifactsArchiveIdColumn < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + remove_column :project_pages_metadata, :artifacts_archive_id + end + + def down + unless column_exists?(:project_pages_metadata, :artifacts_archive_id) + add_column :project_pages_metadata, :artifacts_archive_id, :bigint + end + + add_concurrent_index( + :project_pages_metadata, + :artifacts_archive_id, + name: "index_project_pages_metadata_on_artifacts_archive_id" + ) + end +end diff --git a/db/post_migrate/20220325000000_prepare_index_for_ci_job_artifacts_unlocked_with_expire_at.rb b/db/post_migrate/20220325000000_prepare_index_for_ci_job_artifacts_unlocked_with_expire_at.rb new file mode 100644 index 00000000000..fa43f3b7f59 --- /dev/null +++ b/db/post_migrate/20220325000000_prepare_index_for_ci_job_artifacts_unlocked_with_expire_at.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class PrepareIndexForCiJobArtifactsUnlockedWithExpireAt < Gitlab::Database::Migration[1.0] + TABLE_NAME = 'ci_job_artifacts' + INDEX_NAME = 'index_ci_job_artifacts_on_expire_at_for_removal' + CONDITIONS = 'locked = 0 AND expire_at IS NOT NULL' + + def up + prepare_async_index TABLE_NAME, [:expire_at], where: CONDITIONS, name: INDEX_NAME + end + + def down + unprepare_async_index_by_name TABLE_NAME, INDEX_NAME + end +end diff --git a/db/post_migrate/20220325000001_finalize_index_for_ci_job_artifacts_unlocked_with_expire_at.rb b/db/post_migrate/20220325000001_finalize_index_for_ci_job_artifacts_unlocked_with_expire_at.rb new file mode 100644 index 00000000000..d0fe7ceb34f --- /dev/null +++ b/db/post_migrate/20220325000001_finalize_index_for_ci_job_artifacts_unlocked_with_expire_at.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class FinalizeIndexForCiJobArtifactsUnlockedWithExpireAt < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + TABLE_NAME = 'ci_job_artifacts' + INDEX_NAME = 'index_ci_job_artifacts_on_expire_at_for_removal' + CONDITIONS = 'locked = 0 AND expire_at IS NOT NULL' + + def up + add_concurrent_index TABLE_NAME, [:expire_at], where: CONDITIONS, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end +end diff --git a/db/post_migrate/20220325050642_drop_integrations_template_column.rb b/db/post_migrate/20220325050642_drop_integrations_template_column.rb new file mode 100644 index 00000000000..e110c307a38 --- /dev/null +++ b/db/post_migrate/20220325050642_drop_integrations_template_column.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class DropIntegrationsTemplateColumn < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + remove_column :integrations, :template, :boolean, default: false + end +end diff --git a/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb b/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb new file mode 100644 index 00000000000..4c4c29e2b7c --- /dev/null +++ b/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class StealBackgroundJobForFixingConflictingProjectNamesAndPaths < Gitlab::Database::Migration[1.0] + def up + Gitlab::BackgroundMigration.steal('FixDuplicateProjectNameAndPath') + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb b/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb new file mode 100644 index 00000000000..d1cefa76cec --- /dev/null +++ b/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CreateUniqueIndexOnProjectsNameAndNamespaceId < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'unique_projects_on_name_namespace_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :projects, [:name, :namespace_id], unique: true, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :projects, INDEX_NAME + end +end diff --git a/db/post_migrate/20220326161803_add_cascade_delete_fk_on_project_namespace_id.rb b/db/post_migrate/20220326161803_add_cascade_delete_fk_on_project_namespace_id.rb new file mode 100644 index 00000000000..005532c53d9 --- /dev/null +++ b/db/post_migrate/20220326161803_add_cascade_delete_fk_on_project_namespace_id.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class AddCascadeDeleteFkOnProjectNamespaceId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + TARGET_COLUMN = :project_namespace_id + + def up + # add the new FK before removing the old one + add_concurrent_foreign_key( + :projects, + :namespaces, + column: TARGET_COLUMN, + name: fk_name("#{TARGET_COLUMN}_new"), + on_delete: :cascade + ) + + with_lock_retries do + remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN, name: fk_name(TARGET_COLUMN)) + end + end + + def down + add_concurrent_foreign_key( + :projects, + :namespaces, + column: TARGET_COLUMN, + name: fk_name(TARGET_COLUMN), + on_delete: :nullify + ) + + with_lock_retries do + remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN, name: fk_name("#{TARGET_COLUMN}_new")) + end + end + + def fk_name(column_name) + # generate a FK name + concurrent_foreign_key_name(:projects, column_name) + end +end diff --git a/db/post_migrate/20220326163653_add_not_null_contraint_to_project_namespace_id.rb b/db/post_migrate/20220326163653_add_not_null_contraint_to_project_namespace_id.rb new file mode 100644 index 00000000000..2273b84d003 --- /dev/null +++ b/db/post_migrate/20220326163653_add_not_null_contraint_to_project_namespace_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddNotNullContraintToProjectNamespaceId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_not_null_constraint :projects, :project_namespace_id, validate: false + end + + def down + remove_not_null_constraint :projects, :project_namespace_id + end +end diff --git a/db/post_migrate/20220329175119_remove_leftover_ci_job_artifact_deletions.rb b/db/post_migrate/20220329175119_remove_leftover_ci_job_artifact_deletions.rb new file mode 100644 index 00000000000..f0c09598bfb --- /dev/null +++ b/db/post_migrate/20220329175119_remove_leftover_ci_job_artifact_deletions.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RemoveLeftoverCiJobArtifactDeletions < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + # Delete all pending record deletions in the public.ci_job_artifacts until + # there are no more rows left. + loop do + result = execute <<~SQL + DELETE FROM "loose_foreign_keys_deleted_records" + WHERE + ("loose_foreign_keys_deleted_records"."partition", "loose_foreign_keys_deleted_records"."id") IN ( + SELECT "loose_foreign_keys_deleted_records"."partition", "loose_foreign_keys_deleted_records"."id" + FROM "loose_foreign_keys_deleted_records" + WHERE + "loose_foreign_keys_deleted_records"."fully_qualified_table_name" = 'public.ci_job_artifacts' AND + "loose_foreign_keys_deleted_records"."status" = 1 + LIMIT 100 + ) + SQL + + break if result.cmd_tuples == 0 + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220331074722_add_notes_null_discussion_id_temp_index_async.rb b/db/post_migrate/20220331074722_add_notes_null_discussion_id_temp_index_async.rb new file mode 100644 index 00000000000..9f52308935b --- /dev/null +++ b/db/post_migrate/20220331074722_add_notes_null_discussion_id_temp_index_async.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddNotesNullDiscussionIdTempIndexAsync < Gitlab::Database::Migration[1.0] + # Temporary index to be removed in 15.0 https://gitlab.com/gitlab-org/gitlab/-/issues/357581 + INDEX_NAME = 'tmp_index_notes_on_id_where_discussion_id_is_null' + + def up + prepare_async_index :notes, :id, where: 'discussion_id IS NULL', name: INDEX_NAME + end + + def down + unprepare_async_index_by_name :notes, INDEX_NAME + end +end diff --git a/db/post_migrate/20220401045621_remove_state_index_on_merge_request_assignees.rb b/db/post_migrate/20220401045621_remove_state_index_on_merge_request_assignees.rb new file mode 100644 index 00000000000..ff62a1c646d --- /dev/null +++ b/db/post_migrate/20220401045621_remove_state_index_on_merge_request_assignees.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveStateIndexOnMergeRequestAssignees < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_on_merge_request_assignees_state' + + def up + remove_concurrent_index_by_name :merge_request_assignees, INDEX_NAME + end + + def down + add_concurrent_index :merge_request_assignees, :state, where: 'state = 2', name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220401045642_remove_state_index_on_merge_request_reviewers.rb b/db/post_migrate/20220401045642_remove_state_index_on_merge_request_reviewers.rb new file mode 100644 index 00000000000..ef59d9fcc25 --- /dev/null +++ b/db/post_migrate/20220401045642_remove_state_index_on_merge_request_reviewers.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveStateIndexOnMergeRequestReviewers < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_on_merge_request_reviewers_state' + + def up + remove_concurrent_index_by_name :merge_request_reviewers, INDEX_NAME + end + + def down + add_concurrent_index :merge_request_reviewers, :state, where: 'state = 2', name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220404183350_add_forbidden_state_index_to_users.rb b/db/post_migrate/20220404183350_add_forbidden_state_index_to_users.rb new file mode 100644 index 00000000000..7ae61a60b73 --- /dev/null +++ b/db/post_migrate/20220404183350_add_forbidden_state_index_to_users.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddForbiddenStateIndexToUsers < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'users_forbidden_state_idx' + + def up + add_concurrent_index :users, :id, + name: INDEX_NAME, + where: "confirmed_at IS NOT NULL AND (state <> ALL (ARRAY['blocked', 'banned', 'ldap_blocked']))" + end + + def down + remove_concurrent_index_by_name :users, INDEX_NAME + end +end diff --git a/db/post_migrate/20220404184814_drop_broader_expired_artifact_index.rb b/db/post_migrate/20220404184814_drop_broader_expired_artifact_index.rb new file mode 100644 index 00000000000..b6327b89c11 --- /dev/null +++ b/db/post_migrate/20220404184814_drop_broader_expired_artifact_index.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class DropBroaderExpiredArtifactIndex < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + TABLE_NAME = 'ci_job_artifacts' + INDEX_NAME = 'ci_job_artifacts_expire_at_unlocked_idx' + + def up + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, [:expire_at], where: 'locked = 0', name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb b/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb new file mode 100644 index 00000000000..1f2c0715f04 --- /dev/null +++ b/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class ReplaceWorkItemTypeBackfillNextBatchStrategy < Gitlab::Database::Migration[1.0] + JOB_CLASS_NAME = 'BackfillWorkItemTypeIdForIssues' + NEW_STRATEGY_CLASS = 'BackfillIssueWorkItemTypeBatchingStrategy' + OLD_STRATEGY_CLASS = 'PrimaryKeyBatchingStrategy' + + class InlineBatchedMigration < ApplicationRecord + self.table_name = :batched_background_migrations + end + + def up + InlineBatchedMigration.where(job_class_name: JOB_CLASS_NAME) + .update_all(batch_class_name: NEW_STRATEGY_CLASS) + end + + def down + InlineBatchedMigration.where(job_class_name: JOB_CLASS_NAME) + .update_all(batch_class_name: OLD_STRATEGY_CLASS) + end +end diff --git a/db/post_migrate/20220409160628_add_async_index_for_events_followed_users.rb b/db/post_migrate/20220409160628_add_async_index_for_events_followed_users.rb new file mode 100644 index 00000000000..fb858248b19 --- /dev/null +++ b/db/post_migrate/20220409160628_add_async_index_for_events_followed_users.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddAsyncIndexForEventsFollowedUsers < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_events_for_followed_users' + + def up + prepare_async_index :events, %I[author_id target_type action id], name: INDEX_NAME + end + + def down + unprepare_async_index :events, %I[author_id target_type action id], name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb b/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb new file mode 100644 index 00000000000..f2aa9c0b717 --- /dev/null +++ b/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class FinalizeTraversalIdsBackgroundMigrations < Gitlab::Database::Migration[1.0] + def up + finalize_background_migration('BackfillNamespaceTraversalIdsRoots') + finalize_background_migration('BackfillNamespaceTraversalIdsChildren') + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220412143551_add_partial_index_on_unencrypted_integrations.rb b/db/post_migrate/20220412143551_add_partial_index_on_unencrypted_integrations.rb new file mode 100644 index 00000000000..0f5415d6bf5 --- /dev/null +++ b/db/post_migrate/20220412143551_add_partial_index_on_unencrypted_integrations.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +# +class AddPartialIndexOnUnencryptedIntegrations < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_integrations_on_id_where_not_encrypted' + INDEX_FILTER_CONDITION = 'properties IS NOT NULL AND encrypted_properties IS NULL' + + def up + add_concurrent_index :integrations, [:id], + where: INDEX_FILTER_CONDITION, + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :integrations, INDEX_NAME + end +end 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 new file mode 100644 index 00000000000..69850b3a32f --- /dev/null +++ b/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ConsumeRemainingEncryptIntegrationPropertyJobs < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + BATCH_SIZE = 50 + + def up + Gitlab::BackgroundMigration.steal('EncryptIntegrationProperties') + + model = define_batchable_model('integrations') + 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 + + Gitlab::BackgroundMigration::EncryptIntegrationProperties.new.perform(*range) + end + end + + def down + end +end diff --git a/db/post_migrate/20220413011328_remove_partial_index_on_unencrypted_integrations.rb b/db/post_migrate/20220413011328_remove_partial_index_on_unencrypted_integrations.rb new file mode 100644 index 00000000000..873080144ab --- /dev/null +++ b/db/post_migrate/20220413011328_remove_partial_index_on_unencrypted_integrations.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +# +# The inverse of 20220412143551_add_partial_index_on_unencrypted_integrations.rb +class RemovePartialIndexOnUnencryptedIntegrations < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_integrations_on_id_where_not_encrypted' + INDEX_FILTER_CONDITION = 'properties IS NOT NULL AND encrypted_properties IS NULL' + + def down + add_concurrent_index :integrations, [:id], + where: INDEX_FILTER_CONDITION, + name: INDEX_NAME + end + + def up + remove_concurrent_index_by_name :integrations, INDEX_NAME + end +end |