diff options
Diffstat (limited to 'db/post_migrate')
23 files changed, 587 insertions, 34 deletions
diff --git a/db/post_migrate/20190402224749_schedule_merge_request_assignees_migration_progress_check.rb b/db/post_migrate/20190402224749_schedule_merge_request_assignees_migration_progress_check.rb deleted file mode 100644 index 8ec6a4a24ec..00000000000 --- a/db/post_migrate/20190402224749_schedule_merge_request_assignees_migration_progress_check.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class ScheduleMergeRequestAssigneesMigrationProgressCheck < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - MIGRATION = 'MergeRequestAssigneesMigrationProgressCheck' - - DOWNTIME = false - - disable_ddl_transaction! - - def up - BackgroundMigrationWorker.perform_async(MIGRATION) - end - - def down - end -end diff --git a/db/post_migrate/20201112130715_schedule_recalculate_uuid_on_vulnerabilities_occurrences.rb b/db/post_migrate/20201112130715_schedule_recalculate_uuid_on_vulnerabilities_occurrences.rb new file mode 100644 index 00000000000..7bb97a39bda --- /dev/null +++ b/db/post_migrate/20201112130715_schedule_recalculate_uuid_on_vulnerabilities_occurrences.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class ScheduleRecalculateUuidOnVulnerabilitiesOccurrences < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 2_500 + + disable_ddl_transaction! + + class VulnerabilitiesFinding < ActiveRecord::Base + include ::EachBatch + + self.table_name = "vulnerability_occurrences" + end + + def up + # Make sure that RemoveDuplicateVulnerabilitiesFindings has finished running + # so that we don't run into duplicate UUID issues + Gitlab::BackgroundMigration.steal('RemoveDuplicateVulnerabilitiesFindings') + + say "Scheduling #{MIGRATION} jobs" + queue_background_migration_jobs_by_range_at_intervals( + VulnerabilitiesFinding, + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20201231133921_schedule_set_default_iteration_cadences.rb b/db/post_migrate/20201231133921_schedule_set_default_iteration_cadences.rb new file mode 100644 index 00000000000..32645430e19 --- /dev/null +++ b/db/post_migrate/20201231133921_schedule_set_default_iteration_cadences.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class ScheduleSetDefaultIterationCadences < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 1_000 + DELAY_INTERVAL = 2.minutes.to_i + MIGRATION_CLASS = 'SetDefaultIterationCadences' + + class Iteration < ActiveRecord::Base # rubocop:disable Style/Documentation + include EachBatch + + self.table_name = 'sprints' + end + + disable_ddl_transaction! + + def up + # Do nothing, rescheduling migration: 20210219102900_reschedule_set_default_iteration_cadences.rb + end + + def down + # Not needed + end +end diff --git a/db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb b/db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb index 8f6d312ae5e..87f391e240d 100644 --- a/db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb +++ b/db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb @@ -8,14 +8,12 @@ class CleanUpAssetProxyWhitelistRenameOnApplicationSettings < ActiveRecord::Migr disable_ddl_transaction! def up - cleanup_concurrent_column_rename :application_settings, - :asset_proxy_whitelist, - :asset_proxy_allowlist + # This migration has been made a no-op in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56352 + # because to revert the rename in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55419 we need + # to cleanup the triggers on the `asset_proxy_allowlist` column. As such, this migration would do nothing. end def down - undo_cleanup_concurrent_column_rename :application_settings, - :asset_proxy_whitelist, - :asset_proxy_allowlist + # no-op end end diff --git a/db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb b/db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb index 92241378495..43cfb27b94c 100644 --- a/db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb +++ b/db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb @@ -11,13 +11,7 @@ class ScheduleUuidPopulationForSecurityFindings < ActiveRecord::Migration[6.0] disable_ddl_transaction! def up - Gitlab::BackgroundMigration::PopulateUuidsForSecurityFindings.security_findings.each_batch(column: :scan_id, of: BATCH_SIZE) do |batch, index| - migrate_in( - DELAY_INTERVAL * index, - MIGRATION_CLASS, - batch.pluck(:scan_id) - ) - end + # no-op, replaced by 20210111075206_schedule_uuid_population_for_security_findings2.rb end def down diff --git a/db/post_migrate/20210111075206_schedule_uuid_population_for_security_findings2.rb b/db/post_migrate/20210111075206_schedule_uuid_population_for_security_findings2.rb new file mode 100644 index 00000000000..00569581ca4 --- /dev/null +++ b/db/post_migrate/20210111075206_schedule_uuid_population_for_security_findings2.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# This replaces the previous post-deployment migration 20210111075105_schedule_uuid_population_for_security_findings.rb, +# we have to run this again due to a bug in how we were receiving the arguments in the background migration. +class ScheduleUuidPopulationForSecurityFindings2 < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION_CLASS = 'PopulateUuidsForSecurityFindings' + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 25 + + disable_ddl_transaction! + + def up + ::Gitlab::BackgroundMigration.steal(MIGRATION_CLASS) do |job| + job.delete + + false + end + + Gitlab::BackgroundMigration::PopulateUuidsForSecurityFindings.security_findings.each_batch(column: :scan_id, of: BATCH_SIZE) do |batch, index| + migrate_in( + DELAY_INTERVAL * index, + MIGRATION_CLASS, + batch.pluck(:scan_id) + ) + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb b/db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb index 0631cc8095e..efd0eeb9d47 100644 --- a/db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb +++ b/db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb @@ -10,16 +10,16 @@ class BackfillUpdatedAtAfterRepositoryStorageMove < ActiveRecord::Migration[6.0] disable_ddl_transaction! - class ProjectRepositoryStorageMove < ActiveRecord::Base + class RepositoryStorageMove < ActiveRecord::Base include EachBatch self.table_name = 'project_repository_storage_moves' end def up - ProjectRepositoryStorageMove.reset_column_information + RepositoryStorageMove.reset_column_information - ProjectRepositoryStorageMove.select(:project_id).distinct.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index| + RepositoryStorageMove.select(:project_id).distinct.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index| migrate_in( INTERVAL * index, MIGRATION_CLASS, diff --git a/db/post_migrate/20210210221006_cleanup_projects_with_bad_has_external_issue_tracker_data.rb b/db/post_migrate/20210210221006_cleanup_projects_with_bad_has_external_issue_tracker_data.rb new file mode 100644 index 00000000000..4b8bf014066 --- /dev/null +++ b/db/post_migrate/20210210221006_cleanup_projects_with_bad_has_external_issue_tracker_data.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +class CleanupProjectsWithBadHasExternalIssueTrackerData < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + TMP_INDEX_NAME = 'tmp_idx_projects_on_id_where_has_external_issue_tracker_is_true'.freeze + BATCH_SIZE = 100 + + disable_ddl_transaction! + + class Service < ActiveRecord::Base + include EachBatch + belongs_to :project + + self.table_name = 'services' + self.inheritance_column = :_type_disabled + end + + class Project < ActiveRecord::Base + include EachBatch + + self.table_name = 'projects' + end + + def up + update_projects_with_active_external_issue_trackers + update_projects_without_active_external_issue_trackers + end + + def down + # no-op : can't go back to incorrect data + end + + private + + def update_projects_with_active_external_issue_trackers + scope = Service.where(active: true, category: 'issue_tracker').where.not(project_id: nil).distinct(:project_id) + + scope.each_batch(of: BATCH_SIZE) do |relation| + scope_with_projects = relation + .joins(:project) + .select('project_id') + .merge(Project.where(has_external_issue_tracker: false).where(pending_delete: false)) + + execute(<<~SQL) + WITH project_ids_to_update (id) AS ( + #{scope_with_projects.to_sql} + ) + UPDATE projects SET has_external_issue_tracker = true WHERE id IN (SELECT id FROM project_ids_to_update) + SQL + end + end + + def update_projects_without_active_external_issue_trackers + # Add a temporary index to speed up the scoping of projects. + index_where = <<~SQL + "projects"."has_external_issue_tracker" = TRUE + AND "projects"."pending_delete" = FALSE + SQL + + add_concurrent_index(:projects, :id, where: index_where, name: TMP_INDEX_NAME) + + services_sub_query = Service + .select('1') + .where('services.project_id = projects.id') + .where(category: 'issue_tracker') + .where(active: true) + + # 322 projects are scoped in this query on GitLab.com. + Project.where(index_where).each_batch(of: BATCH_SIZE) do |relation| + relation_with_exists_query = relation.where('NOT EXISTS (?)', services_sub_query) + execute(<<~SQL) + WITH project_ids_to_update (id) AS ( + #{relation_with_exists_query.select(:id).to_sql} + ) + UPDATE projects SET has_external_issue_tracker = false WHERE id IN (SELECT id FROM project_ids_to_update) + SQL + end + + # Drop the temporary index. + remove_concurrent_index_by_name(:projects, TMP_INDEX_NAME) + end +end diff --git a/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb b/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb new file mode 100644 index 00000000000..12e156d3b8a --- /dev/null +++ b/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class MigrateDelayedProjectRemovalFromNamespacesToNamespaceSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + class Namespace < ActiveRecord::Base + self.table_name = 'namespaces' + + include ::EachBatch + end + + def up + Namespace.select(:id).where(delayed_project_removal: true).each_batch do |batch| + values = batch.map { |record| "(#{record.id}, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)" } + + execute <<-EOF.strip_heredoc + INSERT INTO namespace_settings (namespace_id, delayed_project_removal, created_at, updated_at) + VALUES #{values.join(', ')} + ON CONFLICT (namespace_id) DO UPDATE + SET delayed_project_removal = TRUE + EOF + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20210215144909_migrate_usage_trends_sidekiq_queue.rb b/db/post_migrate/20210215144909_migrate_usage_trends_sidekiq_queue.rb new file mode 100644 index 00000000000..3e6eabfba97 --- /dev/null +++ b/db/post_migrate/20210215144909_migrate_usage_trends_sidekiq_queue.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class MigrateUsageTrendsSidekiqQueue < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + sidekiq_queue_migrate 'cronjob:analytics_instance_statistics_count_job_trigger', to: 'cronjob:analytics_usage_trends_count_job_trigger' + sidekiq_queue_migrate 'analytics_instance_statistics_counter_job', to: 'analytics_usage_trends_counter_job' + end + + def down + sidekiq_queue_migrate 'cronjob:analytics_usage_trends_count_job_trigger', to: 'cronjob:analytics_instance_statistics_count_job_trigger' + sidekiq_queue_migrate 'analytics_usage_trends_counter_job', to: 'analytics_instance_statistics_counter_job' + end +end diff --git a/db/post_migrate/20210217100728_move_create_release_evidence_queue_out_of_cronjob_namespace.rb b/db/post_migrate/20210217100728_move_create_release_evidence_queue_out_of_cronjob_namespace.rb new file mode 100644 index 00000000000..22bead87dc1 --- /dev/null +++ b/db/post_migrate/20210217100728_move_create_release_evidence_queue_out_of_cronjob_namespace.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class MoveCreateReleaseEvidenceQueueOutOfCronjobNamespace < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + def up + sidekiq_queue_migrate 'cronjob:releases_create_evidence', to: 'releases_create_evidence' + end + + def down + sidekiq_queue_migrate 'releases_create_evidence', to: 'cronjob:releases_create_evidence' + end +end diff --git a/db/post_migrate/20210218105431_remove_deprecated_ci_builds_columns.rb b/db/post_migrate/20210218105431_remove_deprecated_ci_builds_columns.rb new file mode 100644 index 00000000000..6fa7a15a90d --- /dev/null +++ b/db/post_migrate/20210218105431_remove_deprecated_ci_builds_columns.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class RemoveDeprecatedCiBuildsColumns < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_column :ci_builds, :artifacts_file + remove_column :ci_builds, :artifacts_file_store + remove_column :ci_builds, :artifacts_metadata + remove_column :ci_builds, :artifacts_metadata_store + remove_column :ci_builds, :artifacts_size + remove_column :ci_builds, :commands + end + end + + def down + # rubocop:disable Migration/AddColumnsToWideTables + with_lock_retries do + add_column :ci_builds, :artifacts_file, :text + add_column :ci_builds, :artifacts_file_store, :integer + add_column :ci_builds, :artifacts_metadata, :text + add_column :ci_builds, :artifacts_metadata_store, :integer + add_column :ci_builds, :artifacts_size, :bigint + add_column :ci_builds, :commands, :text + end + # rubocop:enable Migration/AddColumnsToWideTables + + add_concurrent_index :ci_builds, :artifacts_expire_at, where: "artifacts_file <> ''::text", name: 'index_ci_builds_on_artifacts_expire_at' + end +end diff --git a/db/post_migrate/20210218110552_remove_deprecated_ci_runner_column.rb b/db/post_migrate/20210218110552_remove_deprecated_ci_runner_column.rb new file mode 100644 index 00000000000..06fd900590b --- /dev/null +++ b/db/post_migrate/20210218110552_remove_deprecated_ci_runner_column.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class RemoveDeprecatedCiRunnerColumn < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_column :ci_runners, :is_shared + end + end + + def down + add_column :ci_runners, :is_shared, :boolean, default: false unless column_exists?(:ci_runners, :is_shared) + + add_concurrent_index :ci_runners, :is_shared + end +end diff --git a/db/post_migrate/20210219102900_reschedule_set_default_iteration_cadences.rb b/db/post_migrate/20210219102900_reschedule_set_default_iteration_cadences.rb new file mode 100644 index 00000000000..6c7b46737aa --- /dev/null +++ b/db/post_migrate/20210219102900_reschedule_set_default_iteration_cadences.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RescheduleSetDefaultIterationCadences < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 1_000 + DELAY_INTERVAL = 2.minutes.to_i + MIGRATION_CLASS = 'SetDefaultIterationCadences' + + class Iteration < ActiveRecord::Base # rubocop:disable Style/Documentation + include EachBatch + + self.table_name = 'sprints' + end + + disable_ddl_transaction! + + def up + Iteration.select(:group_id).distinct.each_batch(of: BATCH_SIZE, column: :group_id) do |batch, index| + group_ids = batch.pluck(:group_id) + + migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, group_ids) + end + end + + def down + # Not needed + end +end diff --git a/db/post_migrate/20210222185538_remove_backup_labels_foreign_keys.rb b/db/post_migrate/20210222185538_remove_backup_labels_foreign_keys.rb new file mode 100644 index 00000000000..614ec4875d6 --- /dev/null +++ b/db/post_migrate/20210222185538_remove_backup_labels_foreign_keys.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveBackupLabelsForeignKeys < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:backup_labels, :projects) + remove_foreign_key_if_exists(:backup_labels, :namespaces) + end + end + + def down + add_concurrent_foreign_key(:backup_labels, :projects, column: :project_id, on_delete: :cascade) + add_concurrent_foreign_key(:backup_labels, :namespaces, column: :group_id, on_delete: :cascade) + end +end diff --git a/db/post_migrate/20210222192144_remove_backup_labels_table.rb b/db/post_migrate/20210222192144_remove_backup_labels_table.rb new file mode 100644 index 00000000000..1208c3c970f --- /dev/null +++ b/db/post_migrate/20210222192144_remove_backup_labels_table.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class RemoveBackupLabelsTable < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + drop_table :backup_labels + end + + def down + create_table :backup_labels, id: false do |t| + t.integer :id, null: false + t.string :title + t.string :color + t.integer :project_id + t.timestamps null: true # rubocop:disable Migration/Timestamps + t.boolean :template, default: false + t.string :description + t.text :description_html + t.string :type + t.integer :group_id + t.integer :cached_markdown_version + t.integer :restore_action + t.string :new_title + end + + execute 'ALTER TABLE backup_labels ADD PRIMARY KEY (id)' + + add_index :backup_labels, [:group_id, :project_id, :title], name: 'backup_labels_group_id_project_id_title_idx', unique: true + add_index :backup_labels, [:group_id, :title], where: 'project_id = NULL::integer', name: 'backup_labels_group_id_title_idx' + add_index :backup_labels, :project_id, name: 'backup_labels_project_id_idx' + add_index :backup_labels, :template, name: 'backup_labels_template_idx', where: 'template' + add_index :backup_labels, :title, name: 'backup_labels_title_idx' + add_index :backup_labels, [:type, :project_id], name: 'backup_labels_type_project_id_idx' + end +end diff --git a/db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb b/db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb new file mode 100644 index 00000000000..af5c474e2ba --- /dev/null +++ b/db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class RescheduleArtifactExpiryBackfill < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION = 'BackfillArtifactExpiryDate'.freeze + SWITCH_DATE = Date.new(2020, 06, 22).freeze + + disable_ddl_transaction! + + class JobArtifact < ActiveRecord::Base + include EachBatch + + self.inheritance_column = :_type_disabled + self.table_name = 'ci_job_artifacts' + + scope :without_expiry_date, -> { where(expire_at: nil) } + scope :before_switch, -> { where("date(created_at AT TIME ZONE 'UTC') < ?::date", SWITCH_DATE) } + end + + def up + Gitlab::BackgroundMigration.steal(MIGRATION) do |job| + job.delete + + false + end + + queue_background_migration_jobs_by_range_at_intervals( + JobArtifact.without_expiry_date.before_switch, + MIGRATION, + 2.minutes, + batch_size: 200_000 + ) + end + + def down + Gitlab::BackgroundMigration.steal(MIGRATION) do |job| + job.delete + + false + end + end +end diff --git a/db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb b/db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb new file mode 100644 index 00000000000..e04f69f4206 --- /dev/null +++ b/db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class BackfillNamespaceStatisticsWithWikiSize < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 500 + MIGRATION = 'PopulateNamespaceStatistics' + + disable_ddl_transaction! + + def up + return unless Gitlab.ee? + + groups = exec_query <<~SQL + SELECT group_wiki_repositories.group_id + FROM group_wiki_repositories + 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, [:wiki_size]]) + end + end + + def down + # No-op + end +end diff --git a/db/post_migrate/20210303064112_add_not_null_constraints_to_gitlab_subscriptions_namespace_id.rb b/db/post_migrate/20210303064112_add_not_null_constraints_to_gitlab_subscriptions_namespace_id.rb new file mode 100644 index 00000000000..f1d2d80a0f3 --- /dev/null +++ b/db/post_migrate/20210303064112_add_not_null_constraints_to_gitlab_subscriptions_namespace_id.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddNotNullConstraintsToGitlabSubscriptionsNamespaceId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + # This will add the `NOT NULL` constraint WITHOUT validating it + add_not_null_constraint :gitlab_subscriptions, :namespace_id, validate: false + end + + def down + # Down is required as `add_not_null_constraint` is not reversible + remove_not_null_constraint :gitlab_subscriptions, :namespace_id + end +end diff --git a/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb b/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb new file mode 100644 index 00000000000..1fcfb3d43c0 --- /dev/null +++ b/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class CleanupGitlabSubscriptionsWithNullNamespaceId < ActiveRecord::Migration[6.0] + disable_ddl_transaction! + + class GitlabSubscription < ActiveRecord::Base + self.table_name = 'gitlab_subscriptions' + end + + def up + # As of today, there is 0 records whose namespace_id is null on GitLab.com. + # And we expect no such records on non GitLab.com instance. + # So this post-migration cleanup script is just for extra safe. + # + # This will be fast on GitLab.com, because: + # - gitlab_subscriptions.count=5021850 + # - namespace_id is indexed, so the query is pretty fast. Try on database-lab, this uses 5.931 ms + GitlabSubscription.where('namespace_id IS NULL').delete_all + end + + def down + # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint + end +end diff --git a/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb b/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb new file mode 100644 index 00000000000..80ea1748eed --- /dev/null +++ b/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class CleanupClusterTokensWithNullName < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + BATCH_SIZE = 1000 + + disable_ddl_transaction! + + class AgentToken < ActiveRecord::Base + include EachBatch + + self.table_name = 'cluster_agent_tokens' + end + + def up + AgentToken.each_batch(of: BATCH_SIZE) do |relation| + relation.where('name IS NULL').update_all("name = 'agent-token-' || id") + end + end + + def down + # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint + end +end diff --git a/db/post_migrate/20210304133508_schedule_remove_duplicate_vulnerabilities_findings2.rb b/db/post_migrate/20210304133508_schedule_remove_duplicate_vulnerabilities_findings2.rb new file mode 100644 index 00000000000..78574921fea --- /dev/null +++ b/db/post_migrate/20210304133508_schedule_remove_duplicate_vulnerabilities_findings2.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class ScheduleRemoveDuplicateVulnerabilitiesFindings2 < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + MIGRATION = 'RemoveDuplicateVulnerabilitiesFindings' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 5_000 + + disable_ddl_transaction! + + class VulnerabilitiesFinding < ActiveRecord::Base + include ::EachBatch + self.table_name = "vulnerability_occurrences" + end + + def up + say "Scheduling #{MIGRATION} jobs" + queue_background_migration_jobs_by_range_at_intervals( + VulnerabilitiesFinding, + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb b/db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb new file mode 100644 index 00000000000..3a37d8a8510 --- /dev/null +++ b/db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class BackfillPartitionedWebHookLogs < ActiveRecord::Migration[6.0] + include Gitlab::Database::PartitioningMigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + enqueue_partitioning_data_migration :web_hook_logs + end + + def down + cleanup_partitioning_data_migration :web_hook_logs + end +end |