diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /db/post_migrate | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'db/post_migrate')
333 files changed, 956 insertions, 8389 deletions
diff --git a/db/post_migrate/20200106071113_update_fingerprint_sha256_within_keys.rb b/db/post_migrate/20200106071113_update_fingerprint_sha256_within_keys.rb deleted file mode 100644 index 06f5c881006..00000000000 --- a/db/post_migrate/20200106071113_update_fingerprint_sha256_within_keys.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class UpdateFingerprintSha256WithinKeys < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - class Key < ActiveRecord::Base - include EachBatch - - self.table_name = 'keys' - self.inheritance_column = :_type_disabled - end - - disable_ddl_transaction! - - def up - queue_background_migration_jobs_by_range_at_intervals(Key, 'MigrateFingerprintSha256WithinKeys', 5.minutes) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb b/db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb deleted file mode 100644 index 813cd600ddc..00000000000 --- a/db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class ScheduleUpdateExistingSubgroupToMatchVisibilityLevelOfParent < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'UpdateExistingSubgroupToMatchVisibilityLevelOfParent' - DELAY_INTERVAL = 5.minutes.to_i - BATCH_SIZE = 1000 - VISIBILITY_LEVELS = { - internal: 10, - private: 0 - } - - disable_ddl_transaction! - - def up - offset = update_groups(VISIBILITY_LEVELS[:internal]) - update_groups(VISIBILITY_LEVELS[:private], offset: offset) - end - - def down - # no-op - end - - private - - def update_groups(level, offset: 0) - groups = exec_query <<~SQL - SELECT id - FROM namespaces - WHERE visibility_level = #{level} - AND type = 'Group' - AND EXISTS (SELECT 1 - FROM namespaces AS children - WHERE children.parent_id = namespaces.id) - SQL - - ids = groups.rows.flatten - - iterator = 1 - - ids.in_groups_of(BATCH_SIZE, false) do |batch_of_ids| - delay = DELAY_INTERVAL * (iterator + offset) - BackgroundMigrationWorker.perform_in(delay, MIGRATION, [batch_of_ids, level]) - iterator += 1 - end - - say("Background jobs for visibility level #{level} scheduled in #{iterator} iterations") - - offset + iterator - end -end diff --git a/db/post_migrate/20200113151354_remove_creations_in_gitlab_subscription_histories.rb b/db/post_migrate/20200113151354_remove_creations_in_gitlab_subscription_histories.rb deleted file mode 100644 index 39ca5124b32..00000000000 --- a/db/post_migrate/20200113151354_remove_creations_in_gitlab_subscription_histories.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class RemoveCreationsInGitlabSubscriptionHistories < ActiveRecord::Migration[5.2] - DOWNTIME = false - GITLAB_SUBSCRIPTION_CREATED = 0 - - def up - return unless Gitlab.com? - - delete_sql = "DELETE FROM gitlab_subscription_histories WHERE change_type=#{GITLAB_SUBSCRIPTION_CREATED} RETURNING *" - - records = execute(delete_sql) - - logger = Gitlab::BackgroundMigration::Logger.build - records.to_a.each do |record| - logger.info record.as_json.merge(message: "gitlab_subscription_histories with change_type=0 was deleted") - end - end - - def down - # There's no way to restore, and the data is useless - # all the data to be deleted in case needed https://gitlab.com/gitlab-org/gitlab/uploads/7409379b0ed658624f5d33202b5668a1/gitlab_subscription_histories_change_type_0.sql.txt - end -end diff --git a/db/post_migrate/20200114112932_add_temporary_partial_index_on_project_id_to_services.rb b/db/post_migrate/20200114112932_add_temporary_partial_index_on_project_id_to_services.rb deleted file mode 100644 index 55494f1e4ac..00000000000 --- a/db/post_migrate/20200114112932_add_temporary_partial_index_on_project_id_to_services.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class AddTemporaryPartialIndexOnProjectIdToServices < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'tmp_index_on_project_id_partial_with_prometheus_services' - PARTIAL_FILTER = "type = 'PrometheusService'" - - disable_ddl_transaction! - - def up - add_concurrent_index :services, :project_id, where: PARTIAL_FILTER, name: INDEX_NAME - end - - def down - remove_concurrent_index :services, :project_id, where: PARTIAL_FILTER, name: INDEX_NAME - end -end diff --git a/db/post_migrate/20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb b/db/post_migrate/20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb deleted file mode 100644 index d49bd10887c..00000000000 --- a/db/post_migrate/20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class PatchPrometheusServicesForSharedClusterApplications < ActiveRecord::Migration[5.2] - def up - # no-op - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200117194850_backfill_operations_feature_flags_iid.rb b/db/post_migrate/20200117194850_backfill_operations_feature_flags_iid.rb deleted file mode 100644 index bc97bd6062d..00000000000 --- a/db/post_migrate/20200117194850_backfill_operations_feature_flags_iid.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class BackfillOperationsFeatureFlagsIid < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - ### - # This should update about 700 rows on gitlab.com - # Execution time is predicted to take less than a second based on #database-lab results - # https://gitlab.com/gitlab-org/gitlab/merge_requests/22175#migration-performance - ### - def up - execute('LOCK operations_feature_flags IN ACCESS EXCLUSIVE MODE') - - backfill_iids('operations_feature_flags') - - change_column_null :operations_feature_flags, :iid, false - end - - def down - change_column_null :operations_feature_flags, :iid, true - end -end diff --git a/db/post_migrate/20200117194900_delete_internal_ids_where_feature_flags_usage.rb b/db/post_migrate/20200117194900_delete_internal_ids_where_feature_flags_usage.rb deleted file mode 100644 index 0cf1ab03622..00000000000 --- a/db/post_migrate/20200117194900_delete_internal_ids_where_feature_flags_usage.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class DeleteInternalIdsWhereFeatureFlagsUsage < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sql = <<~SQL - DELETE FROM internal_ids WHERE usage = 6 - SQL - - execute(sql) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200120083607_remove_storage_version_column_from_snippets.rb b/db/post_migrate/20200120083607_remove_storage_version_column_from_snippets.rb deleted file mode 100644 index 62bb3f46cae..00000000000 --- a/db/post_migrate/20200120083607_remove_storage_version_column_from_snippets.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveStorageVersionColumnFromSnippets < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - return unless column_exists?(:snippets, :storage_version) - - remove_column :snippets, :storage_version - end - - def down - return if column_exists?(:snippets, :storage_version) - - add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault - :snippets, - :storage_version, - :integer, - default: 2, - allow_null: false - ) - end -end diff --git a/db/post_migrate/20200122123016_backfill_project_settings.rb b/db/post_migrate/20200122123016_backfill_project_settings.rb deleted file mode 100644 index 80ca79e979e..00000000000 --- a/db/post_migrate/20200122123016_backfill_project_settings.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class BackfillProjectSettings < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'BackfillProjectSettings' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 10_000 - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - include EachBatch - - self.table_name = 'projects' - end - - def up - say "Scheduling `#{MIGRATION}` jobs" - - queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end - - def down - # NOOP - end -end diff --git a/db/post_migrate/20200122144759_drop_kibana_column.rb b/db/post_migrate/20200122144759_drop_kibana_column.rb deleted file mode 100644 index ce94ca2dc27..00000000000 --- a/db/post_migrate/20200122144759_drop_kibana_column.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class DropKibanaColumn < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def change - remove_column :clusters_applications_elastic_stacks, :kibana_hostname, :string, limit: 255 - end -end diff --git a/db/post_migrate/20200123155929_remove_invalid_jira_data.rb b/db/post_migrate/20200123155929_remove_invalid_jira_data.rb deleted file mode 100644 index 7ddac15c3fb..00000000000 --- a/db/post_migrate/20200123155929_remove_invalid_jira_data.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveInvalidJiraData < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sql = "DELETE FROM jira_tracker_data WHERE \ - (length(encrypted_api_url) > 0 AND encrypted_api_url_iv IS NULL) \ - OR (length(encrypted_url) > 0 AND encrypted_url_iv IS NULL) \ - OR (length(encrypted_username) > 0 AND encrypted_username_iv IS NULL) \ - OR (length(encrypted_password) > 0 AND encrypted_password_iv IS NULL)" - - execute(sql) - end - - def down - # We need to figure out why migrating data to jira_tracker_data table - # failed and then can recreate the data - end -end diff --git a/db/post_migrate/20200124110831_migrate_design_notes_mentions_to_db.rb b/db/post_migrate/20200124110831_migrate_design_notes_mentions_to_db.rb deleted file mode 100644 index f1e4ee9807b..00000000000 --- a/db/post_migrate/20200124110831_migrate_design_notes_mentions_to_db.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -class MigrateDesignNotesMentionsToDb < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - DELAY = 2.minutes.to_i - BATCH_SIZE = 10000 - MIGRATION = 'UserMentions::CreateResourceUserMention' - - INDEX_NAME = 'design_mentions_temp_index' - INDEX_CONDITION = "note LIKE '%@%'::text AND notes.noteable_type = 'DesignManagement::Design'" - QUERY_CONDITIONS = "#{INDEX_CONDITION} AND design_user_mentions.design_id IS NULL" - JOIN = 'INNER JOIN design_management_designs ON design_management_designs.id = notes.noteable_id LEFT JOIN design_user_mentions ON notes.id = design_user_mentions.note_id' - - class DesignUserMention < ActiveRecord::Base - include EachBatch - - self.table_name = 'design_user_mentions' - end - - class Note < ActiveRecord::Base - include EachBatch - - self.table_name = 'notes' - end - - def up - return unless Gitlab.ee? - - # cleanup design user mentions with no actual mentions, - # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468 - DesignUserMention - .where(mentioned_users_ids: nil) - .where(mentioned_groups_ids: nil) - .where(mentioned_projects_ids: nil) - .each_batch(of: BATCH_SIZE) do |batch| - batch.delete_all - end - - # create temporary index for notes with mentions, may take well over 1h - add_concurrent_index(:notes, :id, where: INDEX_CONDITION, name: INDEX_NAME) - - Note - .joins(JOIN) - .where(QUERY_CONDITIONS) - .each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(notes.id)'), Arel.sql('MAX(notes.id)')).first - BackgroundMigrationWorker.perform_in(index * DELAY, MIGRATION, ['DesignManagement::Design', JOIN, QUERY_CONDITIONS, true, *range]) - end - end - - def down - # no-op - # temporary index is to be dropped in a different migration in an upcoming release: - # https://gitlab.com/gitlab-org/gitlab/issues/196842 - end -end diff --git a/db/post_migrate/20200127090233_remove_invalid_issue_tracker_data.rb b/db/post_migrate/20200127090233_remove_invalid_issue_tracker_data.rb deleted file mode 100644 index 6d64dd3d0d1..00000000000 --- a/db/post_migrate/20200127090233_remove_invalid_issue_tracker_data.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveInvalidIssueTrackerData < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sql = "DELETE FROM issue_tracker_data WHERE \ - (length(encrypted_issues_url) > 0 AND encrypted_issues_url_iv IS NULL) \ - OR (length(encrypted_new_issue_url) > 0 AND encrypted_new_issue_url_iv IS NULL) \ - OR (length(encrypted_project_url) > 0 AND encrypted_project_url_iv IS NULL)" - - execute(sql) - end - - def down - # We need to figure out why migrating data to issue_tracker_data table - # failed and then can recreate the data - end -end diff --git a/db/post_migrate/20200127111840_fix_projects_without_project_feature.rb b/db/post_migrate/20200127111840_fix_projects_without_project_feature.rb deleted file mode 100644 index 66e892444d1..00000000000 --- a/db/post_migrate/20200127111840_fix_projects_without_project_feature.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class FixProjectsWithoutProjectFeature < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - BATCH_SIZE = 50_000 - MIGRATION = 'FixProjectsWithoutProjectFeature' - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - include EachBatch - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200128132510_add_temporary_index_for_notes_with_mentions.rb b/db/post_migrate/20200128132510_add_temporary_index_for_notes_with_mentions.rb deleted file mode 100644 index bd55485f871..00000000000 --- a/db/post_migrate/20200128132510_add_temporary_index_for_notes_with_mentions.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class AddTemporaryIndexForNotesWithMentions < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - INDEX_CONDITION = "note LIKE '%@%'::text" - INDEX_NAME = 'note_mentions_temp_index' - - EPIC_MENTIONS_INDEX_NAME = 'epic_mentions_temp_index' - DESIGN_MENTIONS_INDEX_NAME = 'design_mentions_temp_index' - - def up - # create temporary index for notes with mentions, may take well over 1h - add_concurrent_index(:notes, [:id, :noteable_type], where: INDEX_CONDITION, name: INDEX_NAME) - - # cleanup previous temporary indexes, as we'll be usig the single one - remove_concurrent_index(:notes, :id, name: EPIC_MENTIONS_INDEX_NAME) - remove_concurrent_index(:notes, :id, name: DESIGN_MENTIONS_INDEX_NAME) - end - - def down - remove_concurrent_index(:notes, :id, name: INDEX_NAME) - - add_concurrent_index(:notes, :id, where: "#{INDEX_CONDITION} AND noteable_type='Epic'", name: EPIC_MENTIONS_INDEX_NAME) - add_concurrent_index(:notes, :id, where: "#{INDEX_CONDITION} AND noteable_type='DesignManagement::Design'", name: DESIGN_MENTIONS_INDEX_NAME) - end -end diff --git a/db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb b/db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb deleted file mode 100644 index 362aa3a60f7..00000000000 --- a/db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class CleanupEmptyCommitUserMentions < ActiveRecord::Migration[5.2] - DOWNTIME = false - BATCH_SIZE = 10_000 - - class CommitUserMention < ActiveRecord::Base - include EachBatch - - self.table_name = 'commit_user_mentions' - end - - def up - # cleanup commit user mentions with no actual mentions, - # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468 - CommitUserMention - .where(mentioned_users_ids: nil) - .where(mentioned_groups_ids: nil) - .where(mentioned_projects_ids: nil) - .each_batch(of: BATCH_SIZE) do |batch| - batch.delete_all - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200128134110_migrate_commit_notes_mentions_to_db.rb b/db/post_migrate/20200128134110_migrate_commit_notes_mentions_to_db.rb deleted file mode 100644 index 5b8ed99fb7a..00000000000 --- a/db/post_migrate/20200128134110_migrate_commit_notes_mentions_to_db.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class MigrateCommitNotesMentionsToDb < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - DELAY = 3.minutes.to_i - BATCH_SIZE = 1_000 - MIGRATION = 'UserMentions::CreateResourceUserMention' - - QUERY_CONDITIONS = "note LIKE '%@%'::text AND notes.noteable_type = 'Commit' AND commit_user_mentions.commit_id IS NULL" - JOIN = 'LEFT JOIN commit_user_mentions ON notes.id = commit_user_mentions.note_id' - - class Note < ActiveRecord::Base - include EachBatch - - self.table_name = 'notes' - end - - def up - Note - .joins(JOIN) - .where(QUERY_CONDITIONS) - .each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(notes.id)'), Arel.sql('MAX(notes.id)')).first - migrate_in(index * DELAY, MIGRATION, ['Commit', JOIN, QUERY_CONDITIONS, true, *range]) - end - end - - def down - # no-op - # temporary index is to be dropped in a different migration in an upcoming release: - # https://gitlab.com/gitlab-org/gitlab/issues/196842 - end -end diff --git a/db/post_migrate/20200128210353_cleanup_optimistic_locking_nulls.rb b/db/post_migrate/20200128210353_cleanup_optimistic_locking_nulls.rb deleted file mode 100644 index 5c172159561..00000000000 --- a/db/post_migrate/20200128210353_cleanup_optimistic_locking_nulls.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanupOptimisticLockingNulls < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - TABLES = %w(epics merge_requests issues).freeze - BATCH_SIZE = 10_000 - - def declare_class(table) - Class.new(ActiveRecord::Base) do - include EachBatch - - self.table_name = table - self.inheritance_column = :_type_disabled # Disable STI - end - end - - def up - TABLES.each do |table| - add_concurrent_index table.to_sym, :lock_version, where: "lock_version IS NULL" - - queue_background_migration_jobs_by_range_at_intervals( - declare_class(table).where(lock_version: nil), - 'CleanupOptimisticLockingNulls', - 2.minutes, - batch_size: BATCH_SIZE, - other_job_arguments: [table] - ) - end - end - - def down - TABLES.each do |table| - remove_concurrent_index table.to_sym, :lock_version, where: "lock_version IS NULL" - end - end -end diff --git a/db/post_migrate/20200129035708_cleanup_rename_pages_domains_domain_type_to_scope.rb b/db/post_migrate/20200129035708_cleanup_rename_pages_domains_domain_type_to_scope.rb deleted file mode 100644 index d1d2b4962dd..00000000000 --- a/db/post_migrate/20200129035708_cleanup_rename_pages_domains_domain_type_to_scope.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupRenamePagesDomainsDomainTypeToScope < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :pages_domains, :domain_type, :scope - end - - def down - undo_cleanup_concurrent_column_rename :pages_domains, :domain_type, :scope - end -end diff --git a/db/post_migrate/20200130145430_reschedule_migrate_issue_trackers_data.rb b/db/post_migrate/20200130145430_reschedule_migrate_issue_trackers_data.rb deleted file mode 100644 index 312a8c95b92..00000000000 --- a/db/post_migrate/20200130145430_reschedule_migrate_issue_trackers_data.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -class RescheduleMigrateIssueTrackersData < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 3.minutes.to_i - BATCH_SIZE = 5_000 - MIGRATION = 'MigrateIssueTrackersSensitiveData' - - disable_ddl_transaction! - - class Service < ActiveRecord::Base - self.table_name = 'services' - self.inheritance_column = :_type_disabled - - include ::EachBatch - end - - def up - relation = Service.where(category: 'issue_tracker').where("properties IS NOT NULL AND properties != '{}' AND properties != ''") - queue_background_migration_jobs_by_range_at_intervals(relation, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - remove_issue_tracker_data_sql = "DELETE FROM issue_tracker_data WHERE \ - (length(encrypted_issues_url) > 0 AND encrypted_issues_url_iv IS NULL) \ - OR (length(encrypted_new_issue_url) > 0 AND encrypted_new_issue_url_iv IS NULL) \ - OR (length(encrypted_project_url) > 0 AND encrypted_project_url_iv IS NULL)" - - execute(remove_issue_tracker_data_sql) - - remove_jira_tracker_data_sql = "DELETE FROM jira_tracker_data WHERE \ - (length(encrypted_api_url) > 0 AND encrypted_api_url_iv IS NULL) \ - OR (length(encrypted_url) > 0 AND encrypted_url_iv IS NULL) \ - OR (length(encrypted_username) > 0 AND encrypted_username_iv IS NULL) \ - OR (length(encrypted_password) > 0 AND encrypted_password_iv IS NULL)" - - execute(remove_jira_tracker_data_sql) - end -end diff --git a/db/post_migrate/20200203104214_services_remove_temporary_index_on_project_id.rb b/db/post_migrate/20200203104214_services_remove_temporary_index_on_project_id.rb deleted file mode 100644 index c9566d0256c..00000000000 --- a/db/post_migrate/20200203104214_services_remove_temporary_index_on_project_id.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class ServicesRemoveTemporaryIndexOnProjectId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'tmp_index_on_project_id_partial_with_prometheus_services' - PARTIAL_FILTER = "type = 'PrometheusService'" - - disable_ddl_transaction! - - def up - remove_concurrent_index :services, :project_id, where: PARTIAL_FILTER, name: INDEX_NAME - end - - def down - add_concurrent_index :services, :project_id, where: PARTIAL_FILTER, name: INDEX_NAME - end -end diff --git a/db/post_migrate/20200204113223_schedule_recalculate_project_authorizations.rb b/db/post_migrate/20200204113223_schedule_recalculate_project_authorizations.rb deleted file mode 100644 index 83b58300115..00000000000 --- a/db/post_migrate/20200204113223_schedule_recalculate_project_authorizations.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRecalculateProjectAuthorizations < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'RecalculateProjectAuthorizations' - BATCH_SIZE = 2_500 - DELAY_INTERVAL = 2.minutes.to_i - - disable_ddl_transaction! - - class Namespace < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'namespaces' - end - - class ProjectAuthorization < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'project_authorizations' - end - - def up - say "Scheduling #{MIGRATION} jobs" - - max_group_id = Namespace.where(type: 'Group').maximum(:id) - project_authorizations = ProjectAuthorization.where('project_id <= ?', max_group_id) - .select(:user_id) - .distinct - - project_authorizations.each_batch(of: BATCH_SIZE, column: :user_id) do |authorizations, index| - delay = index * DELAY_INTERVAL - user_ids = authorizations.map(&:user_id) - BackgroundMigrationWorker.perform_in(delay, MIGRATION, [user_ids]) - end - end - - def down - end -end diff --git a/db/post_migrate/20200204113224_schedule_recalculate_project_authorizations_second_run.rb b/db/post_migrate/20200204113224_schedule_recalculate_project_authorizations_second_run.rb deleted file mode 100644 index 8f4a347b5e2..00000000000 --- a/db/post_migrate/20200204113224_schedule_recalculate_project_authorizations_second_run.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRecalculateProjectAuthorizationsSecondRun < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'RecalculateProjectAuthorizationsWithMinMaxUserId' - BATCH_SIZE = 2_500 - DELAY_INTERVAL = 2.minutes.to_i - - disable_ddl_transaction! - - class User < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'users' - end - - def up - say "Scheduling #{MIGRATION} jobs" - - User.each_batch(of: BATCH_SIZE) do |batch, index| - delay = index * DELAY_INTERVAL - range = batch.pluck('MIN(id)', 'MAX(id)').first - BackgroundMigrationWorker.perform_in(delay, MIGRATION, range) - end - end - - def down - end -end diff --git a/db/post_migrate/20200204113225_schedule_recalculate_project_authorizations_third_run.rb b/db/post_migrate/20200204113225_schedule_recalculate_project_authorizations_third_run.rb deleted file mode 100644 index 47b22b4800a..00000000000 --- a/db/post_migrate/20200204113225_schedule_recalculate_project_authorizations_third_run.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRecalculateProjectAuthorizationsThirdRun < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'RecalculateProjectAuthorizationsWithMinMaxUserId' - BATCH_SIZE = 2_500 - DELAY_INTERVAL = 2.minutes.to_i - - disable_ddl_transaction! - - class User < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'users' - end - - def up - say "Scheduling #{MIGRATION} jobs" - - queue_background_migration_jobs_by_range_at_intervals(User, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end - - def down - end -end diff --git a/db/post_migrate/20200206091544_migrate_create_commit_signature_worker_sidekiq_queue.rb b/db/post_migrate/20200206091544_migrate_create_commit_signature_worker_sidekiq_queue.rb deleted file mode 100644 index eec9abf4a31..00000000000 --- a/db/post_migrate/20200206091544_migrate_create_commit_signature_worker_sidekiq_queue.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class MigrateCreateCommitSignatureWorkerSidekiqQueue < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'create_gpg_signature', to: 'create_commit_signature' - end - - def down - sidekiq_queue_migrate 'create_commit_signature', to: 'create_gpg_signature' - end -end diff --git a/db/post_migrate/20200206135203_udpate_index_ci_builds_on_name_for_security_products.rb b/db/post_migrate/20200206135203_udpate_index_ci_builds_on_name_for_security_products.rb deleted file mode 100644 index ddaa3049543..00000000000 --- a/db/post_migrate/20200206135203_udpate_index_ci_builds_on_name_for_security_products.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class UdpateIndexCiBuildsOnNameForSecurityProducts < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_ci_builds_on_name_for_security_products_values' - INDEX_NAME_NEW = 'index_ci_builds_on_name_for_security_reports_values' - INITIAL_INDEX = "((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, ('dast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('license_management'::character varying)::text, ('sast'::character varying)::text" - - disable_ddl_transaction! - - def up - add_concurrent_index(:ci_builds, - :name, - name: INDEX_NAME_NEW, - where: INITIAL_INDEX + ", ('license_scanning'::character varying)::text]))") - - remove_concurrent_index_by_name(:ci_builds, INDEX_NAME) - end - - def down - add_concurrent_index(:ci_builds, - :name, - name: INDEX_NAME, - where: INITIAL_INDEX + ']))') - - remove_concurrent_index_by_name(:ci_builds, INDEX_NAME_NEW) - end -end diff --git a/db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb b/db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb deleted file mode 100644 index 44a32938483..00000000000 --- a/db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class AddTemporaryIndexToPromotionNotes < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :notes, - :note, - where: "noteable_type = 'Issue' AND system IS TRUE AND note LIKE 'promoted to epic%'", - name: 'tmp_idx_on_promoted_notes' - end - - def down - # NO OP - end -end diff --git a/db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb b/db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb deleted file mode 100644 index d25d6ed2dc7..00000000000 --- a/db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -class ScheduleFixOrphanPromotedIssues < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 100 - BACKGROUND_MIGRATION = 'FixOrphanPromotedIssues' - - disable_ddl_transaction! - - class Note < ActiveRecord::Base - include EachBatch - - self.table_name = 'notes' - - scope :of_promotion, -> do - where(noteable_type: 'Issue') - .where('notes.system IS TRUE') - .where("notes.note LIKE 'promoted to epic%'") - end - end - - def up - Note.of_promotion.each_batch(of: BATCH_SIZE) do |notes, index| - jobs = notes.map { |note| [BACKGROUND_MIGRATION, [note.id]] } - - BackgroundMigrationWorker.bulk_perform_async(jobs) - end - end - - def down - # NO OP - end -end diff --git a/db/post_migrate/20200210062432_schedule_link_lfs_objects.rb b/db/post_migrate/20200210062432_schedule_link_lfs_objects.rb deleted file mode 100644 index b401065dd94..00000000000 --- a/db/post_migrate/20200210062432_schedule_link_lfs_objects.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class ScheduleLinkLfsObjects < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # no-op as background migration being schedule times out in some instances - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200210092405_save_instance_administrators_group_id.rb b/db/post_migrate/20200210092405_save_instance_administrators_group_id.rb deleted file mode 100644 index e539a187672..00000000000 --- a/db/post_migrate/20200210092405_save_instance_administrators_group_id.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -class SaveInstanceAdministratorsGroupId < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute( - <<-SQL - UPDATE - application_settings - SET - instance_administrators_group_id = ( - SELECT - namespace_id - FROM - projects - WHERE - id = application_settings.instance_administration_project_id - ) - WHERE - instance_administrators_group_id IS NULL - AND - instance_administration_project_id IS NOT NULL - AND - ID in ( - SELECT - max(id) - FROM - application_settings - ) - SQL - ) - end - - def down - # no-op - - # The change performed by `up` cannot be reversed because once the migration runs, - # we do not know what value application_settings.instance_administrators_group_id - # had before the migration was run. - end -end diff --git a/db/post_migrate/20200211152410_remove_instance_from_services.rb b/db/post_migrate/20200211152410_remove_instance_from_services.rb deleted file mode 100644 index 1f27455b541..00000000000 --- a/db/post_migrate/20200211152410_remove_instance_from_services.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveInstanceFromServices < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - return unless column_exists?(:services, :instance) - - undo_rename_column_concurrently :services, :template, :instance - end - - def down - # This migration should not be rolled back because it - # removes a column that got added in migrations that - # have been reverted in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24857 - end -end diff --git a/db/post_migrate/20200211155000_cleanup_empty_merge_request_mentions.rb b/db/post_migrate/20200211155000_cleanup_empty_merge_request_mentions.rb deleted file mode 100644 index e90d192388b..00000000000 --- a/db/post_migrate/20200211155000_cleanup_empty_merge_request_mentions.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class CleanupEmptyMergeRequestMentions < ActiveRecord::Migration[5.2] - DOWNTIME = false - BATCH_SIZE = 1_000 - - class MergeRequestUserMention < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_request_user_mentions' - end - - def up - # cleanup merge request user mentions with no actual mentions, - # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468 - MergeRequestUserMention - .where(mentioned_users_ids: nil) - .where(mentioned_groups_ids: nil) - .where(mentioned_projects_ids: nil).each_batch(of: BATCH_SIZE) do |batch| - batch.delete_all - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200211155100_add_temporary_merge_request_with_mentions_index.rb b/db/post_migrate/20200211155100_add_temporary_merge_request_with_mentions_index.rb deleted file mode 100644 index 5b25f29d5f7..00000000000 --- a/db/post_migrate/20200211155100_add_temporary_merge_request_with_mentions_index.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class AddTemporaryMergeRequestWithMentionsIndex < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_CONDITION = "description like '%@%' OR title like '%@%'" - INDEX_NAME = 'merge_request_mentions_temp_index' - - disable_ddl_transaction! - - def up - # create temporary index for notes with mentions, may take well over 1h - add_concurrent_index(:merge_requests, :id, where: INDEX_CONDITION, name: INDEX_NAME) - end - - def down - remove_concurrent_index(:merge_requests, :id, where: INDEX_CONDITION, name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db.rb b/db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db.rb deleted file mode 100644 index b622badb561..00000000000 --- a/db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -class MigrateMergeRequestMentionsToDb < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY = 3.minutes.to_i - BATCH_SIZE = 1_000 - MIGRATION = 'UserMentions::CreateResourceUserMention' - - JOIN = "LEFT JOIN merge_request_user_mentions on merge_requests.id = merge_request_user_mentions.merge_request_id" - QUERY_CONDITIONS = "(description like '%@%' OR title like '%@%') AND merge_request_user_mentions.merge_request_id IS NULL" - - disable_ddl_transaction! - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - end - - def up - MergeRequest - .joins(JOIN) - .where(QUERY_CONDITIONS) - .each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(merge_requests.id)'), Arel.sql('MAX(merge_requests.id)')).first - migrate_in(index * DELAY, MIGRATION, ['MergeRequest', JOIN, QUERY_CONDITIONS, false, *range]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200212052620_readd_template_column_to_services.rb b/db/post_migrate/20200212052620_readd_template_column_to_services.rb deleted file mode 100644 index c636cb0a07b..00000000000 --- a/db/post_migrate/20200212052620_readd_template_column_to_services.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class ReaddTemplateColumnToServices < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - # rubocop:disable Migration/UpdateLargeTable - def up - return if column_exists? :services, :template - - # The migration to drop the template column never actually shipped - # to production, so we should be okay to re-add it without worrying - # about doing a data migration. If we needed to restore the value - # of `template`, we would look for entries with `project_id IS NULL`. - add_column_with_default :services, :template, :boolean, default: false, allow_null: true # rubocop:disable Migration/AddColumnWithDefault - end - # rubocop:enable Migration/UpdateLargeTable - - def down - # NOP since the column is expected to exist - end -end diff --git a/db/post_migrate/20200213204737_remove_unnecessary_milestone_join_tables.rb b/db/post_migrate/20200213204737_remove_unnecessary_milestone_join_tables.rb deleted file mode 100644 index 19b3af53836..00000000000 --- a/db/post_migrate/20200213204737_remove_unnecessary_milestone_join_tables.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveUnnecessaryMilestoneJoinTables < ActiveRecord::Migration[6.0] - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - def up - drop_table :issue_milestones - drop_table :merge_request_milestones - end - - def down - create_table :issue_milestones, id: false do |t| - t.references :issue, foreign_key: { on_delete: :cascade }, index: { unique: true }, null: false - t.references :milestone, foreign_key: { on_delete: :cascade }, index: true, null: false - end - - add_index :issue_milestones, [:issue_id, :milestone_id], unique: true - - create_table :merge_request_milestones, id: false do |t| - t.references :merge_request, foreign_key: { on_delete: :cascade }, index: { unique: true }, null: false - t.references :milestone, foreign_key: { on_delete: :cascade }, index: true, null: false - end - - add_index :merge_request_milestones, [:merge_request_id, :milestone_id], name: 'index_mrs_milestones_on_mr_id_and_milestone_id', unique: true - end -end diff --git a/db/post_migrate/20200213220159_migrate_store_security_reports_sidekiq_queue.rb b/db/post_migrate/20200213220159_migrate_store_security_reports_sidekiq_queue.rb deleted file mode 100644 index 5bba4c95328..00000000000 --- a/db/post_migrate/20200213220159_migrate_store_security_reports_sidekiq_queue.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class MigrateStoreSecurityReportsSidekiqQueue < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'pipeline_default:store_security_reports', to: 'security_scans:store_security_reports' - end - - def down - sidekiq_queue_migrate 'security_scans:store_security_reports', to: 'pipeline_default:store_security_reports' - end -end diff --git a/db/post_migrate/20200213220211_migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue.rb b/db/post_migrate/20200213220211_migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue.rb deleted file mode 100644 index e3ed4c60f21..00000000000 --- a/db/post_migrate/20200213220211_migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class MigrateSyncSecurityReportsToReportApprovalRulesSidekiqQueue < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'pipeline_default:sync_security_reports_to_report_approval_rules', - to: 'security_scans:sync_security_reports_to_report_approval_rules' - end - - def down - sidekiq_queue_migrate 'security_scans:sync_security_reports_to_report_approval_rules', - to: 'pipeline_default:sync_security_reports_to_report_approval_rules' - end -end diff --git a/db/post_migrate/20200214034836_remove_security_dashboard_feature_flag.rb b/db/post_migrate/20200214034836_remove_security_dashboard_feature_flag.rb deleted file mode 100644 index 79723619533..00000000000 --- a/db/post_migrate/20200214034836_remove_security_dashboard_feature_flag.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class RemoveSecurityDashboardFeatureFlag < ActiveRecord::Migration[6.0] - DOWNTIME = false - - class FeatureGate < ApplicationRecord - self.table_name = 'feature_gates' - end - - def up - FeatureGate.find_by(feature_key: :security_dashboard, key: :boolean)&.delete - end - - def down - instance_security_dashboard_feature = FeatureGate.find_by(feature_key: :instance_security_dashboard, key: :boolean) - - if instance_security_dashboard_feature.present? - FeatureGate.safe_find_or_create_by!( - feature_key: :security_dashboard, - key: instance_security_dashboard_feature.key, - value: instance_security_dashboard_feature.value - ) - end - end -end diff --git a/db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb b/db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb deleted file mode 100644 index a44efa3c460..00000000000 --- a/db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class CreateEnvironmentForSelfMonitoringProject < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute <<~SQL - INSERT INTO environments (project_id, name, slug, created_at, updated_at) - SELECT instance_administration_project_id, 'production', 'production', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP - FROM application_settings - WHERE instance_administration_project_id IS NOT NULL - AND NOT EXISTS ( - SELECT 1 - FROM environments - INNER JOIN application_settings - ON application_settings.instance_administration_project_id = environments.project_id - ) - SQL - end - - def down - # no-op - - # This migration cannot be reversed because it cannot be ensured that the environment for the Self Monitoring Project - # did not already exist before the migration ran - in that case, the migration does nothing, and it would be unexpected - # behavior for that environment to be deleted by reversing this migration. - end -end diff --git a/db/post_migrate/20200217210353_cleanup_optimistic_locking_nulls_pt2.rb b/db/post_migrate/20200217210353_cleanup_optimistic_locking_nulls_pt2.rb deleted file mode 100644 index 1ec3e817e8e..00000000000 --- a/db/post_migrate/20200217210353_cleanup_optimistic_locking_nulls_pt2.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class CleanupOptimisticLockingNullsPt2 < ActiveRecord::Migration[5.2] - def change - # no-op: the MR that contained this migration was reverted - end -end diff --git a/db/post_migrate/20200217223651_add_index_to_job_artifact_secure_reports.rb b/db/post_migrate/20200217223651_add_index_to_job_artifact_secure_reports.rb deleted file mode 100644 index ca297272f8e..00000000000 --- a/db/post_migrate/20200217223651_add_index_to_job_artifact_secure_reports.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class AddIndexToJobArtifactSecureReports < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'job_artifacts_secure_reports_temp_index' - PARTIAL_FILTER = "file_type BETWEEN 5 AND 8" - - disable_ddl_transaction! - - def up - # This is a temporary index used for the migration of Security Reports to Security Scans - add_concurrent_index(:ci_job_artifacts, - [:id, :file_type, :job_id, :created_at, :updated_at], - name: INDEX_NAME, - where: PARTIAL_FILTER) - end - - def down - remove_concurrent_index(:ci_job_artifacts, - [:id, :file_type, :job_id, :created_at, :updated_at]) - end -end diff --git a/db/post_migrate/20200217225719_schedule_migrate_security_scans.rb b/db/post_migrate/20200217225719_schedule_migrate_security_scans.rb deleted file mode 100644 index 087c189f9fd..00000000000 --- a/db/post_migrate/20200217225719_schedule_migrate_security_scans.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class ScheduleMigrateSecurityScans < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 2.minutes.to_i - BATCH_SIZE = 10_000 - MIGRATION = 'MigrateSecurityScans' - - disable_ddl_transaction! - - class JobArtifact < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'ci_job_artifacts' - - scope :security_reports, -> { where('file_type BETWEEN 5 and 8') } - end - - def up - queue_background_migration_jobs_by_range_at_intervals(JobArtifact.security_reports, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # intentionally blank - end -end diff --git a/db/post_migrate/20200219183456_remove_issue_state_indexes.rb b/db/post_migrate/20200219183456_remove_issue_state_indexes.rb deleted file mode 100644 index cdf10b8172e..00000000000 --- a/db/post_migrate/20200219183456_remove_issue_state_indexes.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -class RemoveIssueStateIndexes < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - # issues state column is ignored since 12.6 and will be removed on a following migration - def up - remove_concurrent_index_by_name :issues, 'index_issues_on_state' - remove_concurrent_index_by_name :issues, 'index_issues_on_project_id_and_created_at_and_id_and_state' - remove_concurrent_index_by_name :issues, 'idx_issues_on_project_id_and_due_date_and_id_and_state_partial' - remove_concurrent_index_by_name :issues, 'index_issues_on_project_id_and_rel_position_and_state_and_id' - remove_concurrent_index_by_name :issues, 'index_issues_on_project_id_and_updated_at_and_id_and_state' - end - - def down - add_concurrent_index :issues, :state, name: 'index_issues_on_state' - - add_concurrent_index :issues, - [:project_id, :created_at, :id, :state], - name: 'index_issues_on_project_id_and_created_at_and_id_and_state' - - add_concurrent_index :issues, - [:project_id, :due_date, :id, :state], - where: 'due_date IS NOT NULL', - name: 'idx_issues_on_project_id_and_due_date_and_id_and_state_partial' - - add_concurrent_index :issues, - [:project_id, :relative_position, :state, :id], - order: { id: :desc }, - name: 'index_issues_on_project_id_and_rel_position_and_state_and_id' - - add_concurrent_index :issues, - [:project_id, :updated_at, :id, :state], - name: 'index_issues_on_project_id_and_updated_at_and_id_and_state' - end -end diff --git a/db/post_migrate/20200219184219_remove_merge_request_state_indexes.rb b/db/post_migrate/20200219184219_remove_merge_request_state_indexes.rb deleted file mode 100644 index deb95acc1cf..00000000000 --- a/db/post_migrate/20200219184219_remove_merge_request_state_indexes.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -class RemoveMergeRequestStateIndexes < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - # merge_requests state column is ignored since 12.6 and will be removed on a following migration - def up - remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_id_and_merge_jid' - remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_source_project_and_branch_state_opened' - remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_state_and_merge_status' - remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_target_project_id_and_iid_opened' - end - - def down - add_concurrent_index :merge_requests, - [:id, :merge_jid], - where: "merge_jid IS NOT NULL and state = 'locked'", - name: 'index_merge_requests_on_id_and_merge_jid' - - add_concurrent_index :merge_requests, - [:source_project_id, :source_branch], - where: "state = 'opened'", - name: 'index_merge_requests_on_source_project_and_branch_state_opened' - - add_concurrent_index :merge_requests, - [:state, :merge_status], - where: "state = 'opened' AND merge_status = 'can_be_merged'", - name: 'index_merge_requests_on_state_and_merge_status' - - add_concurrent_index :merge_requests, - [:target_project_id, :iid], - where: "state = 'opened'", - name: 'index_merge_requests_on_target_project_id_and_iid_opened' - end -end diff --git a/db/post_migrate/20200219193058_remove_state_from_issues.rb b/db/post_migrate/20200219193058_remove_state_from_issues.rb deleted file mode 100644 index 007ba600ce7..00000000000 --- a/db/post_migrate/20200219193058_remove_state_from_issues.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class RemoveStateFromIssues < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - return unless issue_state_column_exists? - - # Ignored in 12.6 - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/19574 - with_lock_retries do - remove_column :issues, :state, :string - end - end - - def down - return if issue_state_column_exists? - - with_lock_retries do - add_column :issues, :state, :string - end - end - - private - - def issue_state_column_exists? - column_exists?(:issues, :state) - end -end diff --git a/db/post_migrate/20200219193117_remove_state_from_merge_requests.rb b/db/post_migrate/20200219193117_remove_state_from_merge_requests.rb deleted file mode 100644 index 384a694b549..00000000000 --- a/db/post_migrate/20200219193117_remove_state_from_merge_requests.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class RemoveStateFromMergeRequests < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - return unless merge_requests_state_column_exists? - - # Ignored in 12.6 - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/19574 - with_lock_retries do - remove_column :merge_requests, :state, :string - end - end - - def down - return if merge_requests_state_column_exists? - - with_lock_retries do - add_column :merge_requests, :state, :string - end - end - - private - - def merge_requests_state_column_exists? - column_exists?(:merge_requests, :state) - end -end diff --git a/db/post_migrate/20200220115023_fix_projects_without_prometheus_service.rb b/db/post_migrate/20200220115023_fix_projects_without_prometheus_service.rb deleted file mode 100644 index 274a392a52a..00000000000 --- a/db/post_migrate/20200220115023_fix_projects_without_prometheus_service.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class FixProjectsWithoutPrometheusService < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - BATCH_SIZE = 50_000 - MIGRATION = 'FixProjectsWithoutPrometheusService' - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - include EachBatch - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200221142216_remove_repository_storage_from_snippets.rb b/db/post_migrate/20200221142216_remove_repository_storage_from_snippets.rb deleted file mode 100644 index f9ef985218b..00000000000 --- a/db/post_migrate/20200221142216_remove_repository_storage_from_snippets.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class RemoveRepositoryStorageFromSnippets < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - return unless column_exists?(:snippets, :repository_storage) - - remove_column :snippets, :repository_storage - end - - def down - return if column_exists?(:snippets, :repository_storage) - - add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault - :snippets, - :repository_storage, - :string, - default: 'default', - limit: 255, - allow_null: false - ) - end -end diff --git a/db/post_migrate/20200226124757_remove_health_status_from_epics.rb b/db/post_migrate/20200226124757_remove_health_status_from_epics.rb deleted file mode 100644 index e59edbacd2b..00000000000 --- a/db/post_migrate/20200226124757_remove_health_status_from_epics.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveHealthStatusFromEpics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - with_lock_retries do - remove_column :epics, :health_status - end - end - - def down - with_lock_retries do - add_column :epics, :health_status, :integer, limit: 2 - end - end -end diff --git a/db/post_migrate/20200226162239_cleanup_closed_at_rename_in_vulnerabilities.rb b/db/post_migrate/20200226162239_cleanup_closed_at_rename_in_vulnerabilities.rb deleted file mode 100644 index eb7df0b8d22..00000000000 --- a/db/post_migrate/20200226162239_cleanup_closed_at_rename_in_vulnerabilities.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupClosedAtRenameInVulnerabilities < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :vulnerabilities, :closed_at, :dismissed_at - end - - def down - undo_cleanup_concurrent_column_rename :vulnerabilities, :closed_at, :dismissed_at - end -end diff --git a/db/post_migrate/20200226162723_cleanup_closed_by_rename_in_vulnerabilities.rb b/db/post_migrate/20200226162723_cleanup_closed_by_rename_in_vulnerabilities.rb deleted file mode 100644 index 4aa3568db14..00000000000 --- a/db/post_migrate/20200226162723_cleanup_closed_by_rename_in_vulnerabilities.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupClosedByRenameInVulnerabilities < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :vulnerabilities, :closed_by_id, :dismissed_by_id - end - - def down - undo_cleanup_concurrent_column_rename :vulnerabilities, :closed_by_id, :dismissed_by_id - end -end diff --git a/db/post_migrate/20200227140242_update_occurrence_severity_column.rb b/db/post_migrate/20200227140242_update_occurrence_severity_column.rb deleted file mode 100644 index 6d250532383..00000000000 --- a/db/post_migrate/20200227140242_update_occurrence_severity_column.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -class UpdateOccurrenceSeverityColumn < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - BATCH_SIZE = 1_000 - INTERVAL = 5.minutes - - # 23_044 records to be updated on GitLab.com, - def up - # create temporary index for undefined vulnerabilities - add_concurrent_index(:vulnerability_occurrences, :id, where: 'severity = 0', name: 'undefined_vulnerabilities') - - return unless Gitlab.ee? - - migration = Gitlab::BackgroundMigration::RemoveUndefinedOccurrenceSeverityLevel - migration_name = migration.to_s.demodulize - relation = migration::Occurrence.undefined_severity - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - # temporary index is to be dropped in a different migration in an upcoming release - remove_concurrent_index(:vulnerability_occurrences, :id, where: 'severity = 0', name: 'undefined_vulnerabilities') - # This migration can not be reversed because we can not know which records had undefined severity - end -end diff --git a/db/post_migrate/20200302142052_update_vulnerability_severity_column.rb b/db/post_migrate/20200302142052_update_vulnerability_severity_column.rb deleted file mode 100644 index fa38569f35d..00000000000 --- a/db/post_migrate/20200302142052_update_vulnerability_severity_column.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class UpdateVulnerabilitySeverityColumn < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - BATCH_SIZE = 1_000 - INTERVAL = 2.minutes - - def up - # create temporary index for undefined vulnerabilities - add_concurrent_index(:vulnerabilities, :id, where: 'severity = 0', name: 'undefined_vulnerability') - - return unless Gitlab.ee? - - migration = Gitlab::BackgroundMigration::RemoveUndefinedVulnerabilitySeverityLevel - migration_name = migration.to_s.demodulize - relation = migration::Vulnerability.undefined_severity - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - # This migration can not be reversed because we can not know which records had undefined severity - end -end diff --git a/db/post_migrate/20200304211738_remove_file_type_from_packages_package_files.rb b/db/post_migrate/20200304211738_remove_file_type_from_packages_package_files.rb deleted file mode 100644 index 98bce8845ab..00000000000 --- a/db/post_migrate/20200304211738_remove_file_type_from_packages_package_files.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class RemoveFileTypeFromPackagesPackageFiles < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def change - remove_column :packages_package_files, :file_type, :integer - end -end diff --git a/db/post_migrate/20200305082754_remove_duplicate_labels_from_project.rb b/db/post_migrate/20200305082754_remove_duplicate_labels_from_project.rb deleted file mode 100644 index f7df9f28187..00000000000 --- a/db/post_migrate/20200305082754_remove_duplicate_labels_from_project.rb +++ /dev/null @@ -1,132 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicateLabelsFromProject < ActiveRecord::Migration[6.0] - DOWNTIME = false - - CREATE = 1 - RENAME = 2 - - disable_ddl_transaction! - - class BackupLabel < Label - self.inheritance_column = :_type_disabled - - self.table_name = 'backup_labels' - end - - class Label < ApplicationRecord - self.table_name = 'labels' - end - - class Project < ApplicationRecord - include EachBatch - - self.table_name = 'projects' - end - - BATCH_SIZE = 100_000 - - def up - # Split to smaller chunks - # Loop rather than background job, every 100,000 - # there are 45,000,000 projects in total - Project.each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - transaction do - remove_full_duplicates(*range) - end - - transaction do - rename_partial_duplicates(*range) - end - end - end - - def down - Project.each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - restore_renamed_labels(*range) - restore_deleted_labels(*range) - end - end - - def remove_full_duplicates(start_id, stop_id) - # Fields that are considered duplicate: - # project_id title template description type color - - duplicate_labels = ApplicationRecord.connection.execute(<<-SQL.squish) -WITH data AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT labels.*, - row_number() OVER (PARTITION BY labels.project_id, labels.title, labels.template, labels.description, labels.type, labels.color ORDER BY labels.id) AS row_number, - #{CREATE} AS restore_action - FROM labels - WHERE labels.project_id BETWEEN #{start_id} AND #{stop_id} - AND NOT EXISTS (SELECT * FROM board_labels WHERE board_labels.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM label_links WHERE label_links.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM label_priorities WHERE label_priorities.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM lists WHERE lists.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM resource_label_events WHERE resource_label_events.label_id = labels.id) -) SELECT * FROM data WHERE row_number > 1; - SQL - - if duplicate_labels.any? - # create backup records - BackupLabel.insert_all!(duplicate_labels.map { |label| label.except("row_number") }) - - Label.where(id: duplicate_labels.pluck("id")).delete_all - end - end - - def rename_partial_duplicates(start_id, stop_id) - # We need to ensure that the new title (with `_duplicate#{ID}`) doesn't exceed the limit. - # Truncate the original title (if needed) to 245 characters minus the length of the ID - # then add `_duplicate#{ID}` - - soft_duplicates = ApplicationRecord.connection.execute(<<-SQL.squish) -WITH data AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT - *, - substring(title from 1 for 245 - length(id::text)) || '_duplicate' || id::text as new_title, - #{RENAME} AS restore_action, - row_number() OVER (PARTITION BY project_id, title ORDER BY id) AS row_number - FROM labels - WHERE project_id BETWEEN #{start_id} AND #{stop_id} -) SELECT * FROM data WHERE row_number > 1; - SQL - - if soft_duplicates.any? - # create backup records - BackupLabel.insert_all!(soft_duplicates.map { |label| label.except("row_number") }) - - ApplicationRecord.connection.execute(<<-SQL.squish) -UPDATE labels SET title = substring(title from 1 for 245 - length(id::text)) || '_duplicate' || id::text -WHERE labels.id IN (#{soft_duplicates.map { |dup| dup["id"] }.join(", ")}); - SQL - end - end - - def restore_renamed_labels(start_id, stop_id) - # the backup label IDs are not incremental, they are copied directly from the Labels table - ApplicationRecord.connection.execute(<<-SQL.squish) -WITH backups AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT id, title - FROM backup_labels - WHERE project_id BETWEEN #{start_id} AND #{stop_id} AND - restore_action = #{RENAME} -) UPDATE labels SET title = backups.title -FROM backups -WHERE labels.id = backups.id; - SQL - end - - def restore_deleted_labels(start_id, stop_id) - ActiveRecord::Base.connection.execute(<<-SQL.squish) -INSERT INTO labels -SELECT id, title, color, project_id, created_at, updated_at, template, description, description_html, type, group_id, cached_markdown_version FROM backup_labels - WHERE backup_labels.project_id BETWEEN #{start_id} AND #{stop_id} - AND backup_labels.restore_action = #{CREATE} - SQL - end -end diff --git a/db/post_migrate/20200305082858_add_uniqueness_index_to_label_title_and_project.rb b/db/post_migrate/20200305082858_add_uniqueness_index_to_label_title_and_project.rb deleted file mode 100644 index ce235ba4aea..00000000000 --- a/db/post_migrate/20200305082858_add_uniqueness_index_to_label_title_and_project.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class AddUniquenessIndexToLabelTitleAndProject < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - PROJECT_AND_TITLE = [:project_id, :title] - - def up - add_concurrent_index :labels, PROJECT_AND_TITLE, where: "labels.group_id IS NULL", unique: true, name: "index_labels_on_project_id_and_title_unique" - remove_concurrent_index :labels, PROJECT_AND_TITLE, name: "index_labels_on_project_id_and_title" - end - - def down - add_concurrent_index :labels, PROJECT_AND_TITLE, where: "labels.group_id IS NULL", unique: false, name: "index_labels_on_project_id_and_title" - remove_concurrent_index :labels, PROJECT_AND_TITLE, name: "index_labels_on_project_id_and_title_unique" - end -end diff --git a/db/post_migrate/20200310075115_schedule_link_lfs_objects_projects.rb b/db/post_migrate/20200310075115_schedule_link_lfs_objects_projects.rb deleted file mode 100644 index d1ed53d8e70..00000000000 --- a/db/post_migrate/20200310075115_schedule_link_lfs_objects_projects.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class ScheduleLinkLfsObjectsProjects < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'LinkLfsObjectsProjects' - BATCH_SIZE = 1000 - - disable_ddl_transaction! - - def up - lfs_objects_projects = Gitlab::BackgroundMigration::LinkLfsObjectsProjects::LfsObjectsProject.linkable - - queue_background_migration_jobs_by_range_at_intervals( - lfs_objects_projects, - MIGRATION, - BackgroundMigrationWorker.minimum_interval, - batch_size: BATCH_SIZE - ) - end - - def down - # No-op. No need to make this reversible. In case the jobs enqueued runs and - # fails at some point, some records will be created. When rescheduled, those - # records won't be re-created. It's also hard to track which records to clean - # up if ever. - end -end diff --git a/db/post_migrate/20200310135818_remove_temporary_promoted_notes_index.rb b/db/post_migrate/20200310135818_remove_temporary_promoted_notes_index.rb deleted file mode 100644 index 0b9bbf1e17b..00000000000 --- a/db/post_migrate/20200310135818_remove_temporary_promoted_notes_index.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -# Removes temporary index to fix orphan promoted issues. -# For more information check: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/23916 -class RemoveTemporaryPromotedNotesIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name :notes, 'tmp_idx_on_promoted_notes' - end - - def down - add_concurrent_index :notes, - :note, - where: "noteable_type = 'Issue' AND system IS TRUE AND note LIKE 'promoted to epic%'", - name: 'tmp_idx_on_promoted_notes' - end -end diff --git a/db/post_migrate/20200310215714_migrate_saml_identities_to_scim_identities.rb b/db/post_migrate/20200310215714_migrate_saml_identities_to_scim_identities.rb deleted file mode 100644 index 570eec53be3..00000000000 --- a/db/post_migrate/20200310215714_migrate_saml_identities_to_scim_identities.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class MigrateSamlIdentitiesToScimIdentities < ActiveRecord::Migration[6.0] - DOWNTIME = false - - class Identity < ActiveRecord::Base - self.table_name = 'identities' - - include ::EachBatch - end - - def up - Identity - .joins('INNER JOIN saml_providers ON saml_providers.id = identities.saml_provider_id') - .where('saml_providers.group_id IN (SELECT group_id FROM scim_oauth_access_tokens)') - .select('identities.extern_uid, identities.user_id, saml_providers.group_id, TRUE AS active, - identities.created_at, CURRENT_TIMESTAMP AS updated_at') - .each_batch do |batch| - data_to_insert = batch.map do |record| - record.attributes.extract!("extern_uid", "user_id", "group_id", "active", "created_at", "updated_at") - end - - Gitlab::Database.main.bulk_insert(:scim_identities, data_to_insert, on_conflict: :do_nothing) # rubocop:disable Gitlab/BulkInsert - end - end - - def down - end -end diff --git a/db/post_migrate/20200311130802_schedule_populate_user_highest_roles_table.rb b/db/post_migrate/20200311130802_schedule_populate_user_highest_roles_table.rb deleted file mode 100644 index 36f0d42a855..00000000000 --- a/db/post_migrate/20200311130802_schedule_populate_user_highest_roles_table.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateUserHighestRolesTable < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - BATCH_SIZE = 10_000 - DELAY = 5.minutes.to_i - DOWNTIME = false - MIGRATION = 'PopulateUserHighestRolesTable' - - disable_ddl_transaction! - - class User < ActiveRecord::Base - include EachBatch - - scope :active, -> { - where(state: 'active', user_type: nil, bot_type: nil) - .where('ghost IS NOT TRUE') - } - end - - def up - # We currently have ~5_300_000 users with the state active on GitLab.com. - # This means it'll schedule ~530 jobs (10k Users each) with a 5 minutes gap, - # so this should take ~44 hours for all background migrations to complete. - User.active.each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first - delay = index * DELAY - - migrate_in(delay.seconds, MIGRATION, [*range]) - end - end - - def down - # nothing - end -end diff --git a/db/post_migrate/20200311192351_add_index_on_noteable_type_and_noteable_id_to_sent_notifications.rb b/db/post_migrate/20200311192351_add_index_on_noteable_type_and_noteable_id_to_sent_notifications.rb deleted file mode 100644 index fa0246218c3..00000000000 --- a/db/post_migrate/20200311192351_add_index_on_noteable_type_and_noteable_id_to_sent_notifications.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnNoteableTypeAndNoteableIdToSentNotifications < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_sent_notifications_on_noteable_type_noteable_id' - - disable_ddl_transaction! - - def up - add_concurrent_index :sent_notifications, - [:noteable_id], - name: INDEX_NAME, - where: "noteable_type = 'Issue'" - end - - def down - remove_concurrent_index_by_name :sent_notifications, INDEX_NAME - end -end diff --git a/db/post_migrate/20200312134637_backfill_environment_id_on_deployment_merge_requests.rb b/db/post_migrate/20200312134637_backfill_environment_id_on_deployment_merge_requests.rb deleted file mode 100644 index 77cb1ae8508..00000000000 --- a/db/post_migrate/20200312134637_backfill_environment_id_on_deployment_merge_requests.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class BackfillEnvironmentIdOnDeploymentMergeRequests < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # no-op - - # this migration is deleted because there is no foreign key for - # deployments.environment_id and this caused a failure upgrading - # deployments_merge_requests.environment_id - # - # Details on the following issues: - # * https://gitlab.com/gitlab-org/gitlab/-/issues/217191 - # * https://gitlab.com/gitlab-org/gitlab/-/issues/26229 - end - - def down - # no-op - - # this migration is designed to delete duplicated data - end -end diff --git a/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb b/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb deleted file mode 100644 index 59cd2b31772..00000000000 --- a/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class RemoveOrphanedChatNames < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute("DELETE FROM chat_names WHERE service_id NOT IN(SELECT id FROM services WHERE services.type = 'chat')") - end - - def down - say 'Orphaned user chat names were removed as a part of this migration and are non-recoverable' - end -end diff --git a/db/post_migrate/20200313204021_validate_foreign_key_from_chat_name_to_service.rb b/db/post_migrate/20200313204021_validate_foreign_key_from_chat_name_to_service.rb deleted file mode 100644 index fd9feab17db..00000000000 --- a/db/post_migrate/20200313204021_validate_foreign_key_from_chat_name_to_service.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class ValidateForeignKeyFromChatNameToService < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - DOWNTIME = false - - def up - validate_foreign_key :chat_names, :service_id - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200319071702_consume_remaining_link_lfs_objects_projects_jobs.rb b/db/post_migrate/20200319071702_consume_remaining_link_lfs_objects_projects_jobs.rb deleted file mode 100644 index 63fa0234a5b..00000000000 --- a/db/post_migrate/20200319071702_consume_remaining_link_lfs_objects_projects_jobs.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class ConsumeRemainingLinkLfsObjectsProjectsJobs < ActiveRecord::Migration[6.0] - DOWNTIME = false - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal('LinkLfsObjectsProjects') - end - - def down - # no-op as there is no need to do anything if this gets rolled back - end -end diff --git a/db/post_migrate/20200323011225_complete_migrate_security_scans.rb b/db/post_migrate/20200323011225_complete_migrate_security_scans.rb deleted file mode 100644 index 39c9a78b1b6..00000000000 --- a/db/post_migrate/20200323011225_complete_migrate_security_scans.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class CompleteMigrateSecurityScans < ActiveRecord::Migration[6.0] - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal('MigrateSecurityScans') - end - - def down - # intentionally blank - end -end diff --git a/db/post_migrate/20200323011955_remove_index_used_for_scan_migration.rb b/db/post_migrate/20200323011955_remove_index_used_for_scan_migration.rb deleted file mode 100644 index 0568cdb8483..00000000000 --- a/db/post_migrate/20200323011955_remove_index_used_for_scan_migration.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class RemoveIndexUsedForScanMigration < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'job_artifacts_secure_reports_temp_index' - COLUMNS = [:id, :file_type, :job_id, :created_at, :updated_at] - - disable_ddl_transaction! - - def up - if index_exists?(:ci_job_artifacts, COLUMNS, name: INDEX_NAME) - remove_concurrent_index(:ci_job_artifacts, COLUMNS, name: INDEX_NAME) - end - end - - def down - add_concurrent_index(:ci_job_artifacts, - COLUMNS, - name: INDEX_NAME, - where: 'file_type BETWEEN 5 AND 8') - end -end diff --git a/db/post_migrate/20200323080714_trigger_background_migration_for_users_bio.rb b/db/post_migrate/20200323080714_trigger_background_migration_for_users_bio.rb deleted file mode 100644 index 31ab41a6b88..00000000000 --- a/db/post_migrate/20200323080714_trigger_background_migration_for_users_bio.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class TriggerBackgroundMigrationForUsersBio < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 2.minutes.to_i - BATCH_SIZE = 500 - MIGRATION = 'MigrateUsersBioToUserDetails' - - disable_ddl_transaction! - - class User < ActiveRecord::Base - self.table_name = 'users' - - include ::EachBatch - end - - def up - relation = User.where("(COALESCE(bio, '') IS DISTINCT FROM '')") - - queue_background_migration_jobs_by_range_at_intervals(relation, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb b/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb deleted file mode 100644 index 984f4f20441..00000000000 --- a/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -class ScheduleBackfillPushRulesIdInProjects < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - MIGRATION = 'BackfillPushRulesIdInProjects' - BATCH_SIZE = 1_000 - - class PushRules < ActiveRecord::Base - include EachBatch - - self.table_name = 'push_rules' - end - - def up - # Update one record that is connected to the instance - value_to_be_updated_to = ScheduleBackfillPushRulesIdInProjects::PushRules.find_by(is_sample: true)&.id - - if value_to_be_updated_to - execute "UPDATE application_settings SET push_rule_id = #{value_to_be_updated_to} - WHERE id IN (SELECT MAX(id) FROM application_settings);" - end - - ApplicationSetting.expire - - queue_background_migration_jobs_by_range_at_intervals(ScheduleBackfillPushRulesIdInProjects::PushRules, - MIGRATION, - 5.minutes, - batch_size: BATCH_SIZE) - end - - def down - execute "UPDATE application_settings SET push_rule_id = NULL" - - ApplicationSetting.expire - end -end diff --git a/db/post_migrate/20200401091051_remove_reference_columns_from_resource_milestone_events.rb b/db/post_migrate/20200401091051_remove_reference_columns_from_resource_milestone_events.rb deleted file mode 100644 index 639ab93cf18..00000000000 --- a/db/post_migrate/20200401091051_remove_reference_columns_from_resource_milestone_events.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class RemoveReferenceColumnsFromResourceMilestoneEvents < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def change - remove_column :resource_milestone_events, :reference, :text - remove_column :resource_milestone_events, :reference_html, :text - remove_column :resource_milestone_events, :cached_markdown_version, :integer - end -end diff --git a/db/post_migrate/20200403132349_remove_old_index_pages_domains_need_auto_ssl_renewal.rb b/db/post_migrate/20200403132349_remove_old_index_pages_domains_need_auto_ssl_renewal.rb deleted file mode 100644 index b36dce188df..00000000000 --- a/db/post_migrate/20200403132349_remove_old_index_pages_domains_need_auto_ssl_renewal.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class RemoveOldIndexPagesDomainsNeedAutoSslRenewal < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - INDEX_NAME = 'index_pages_domains_need_auto_ssl_renewal' - - disable_ddl_transaction! - - def up - remove_concurrent_index(:pages_domains, [:certificate_source, :certificate_valid_not_after], - where: "auto_ssl_enabled = true", name: INDEX_NAME) - end - - def down - add_concurrent_index(:pages_domains, [:certificate_source, :certificate_valid_not_after], - where: "auto_ssl_enabled = true", name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb b/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb deleted file mode 100644 index ab217ba92ab..00000000000 --- a/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class BackfillDeploymentClustersFromDeployments < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'BackfillDeploymentClustersFromDeployments' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 10_000 - - disable_ddl_transaction! - - class Deployment < ActiveRecord::Base - include EachBatch - - default_scope { where.not(cluster_id: nil) } # rubocop:disable Cop/DefaultScope - - self.table_name = 'deployments' - end - - def up - say "Scheduling `#{MIGRATION}` jobs" - - queue_background_migration_jobs_by_range_at_intervals(Deployment, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end - - def down - # NOOP - end -end diff --git a/db/post_migrate/20200406193427_add_index_to_issues_health_status.rb b/db/post_migrate/20200406193427_add_index_to_issues_health_status.rb deleted file mode 100644 index 83baf5b6d75..00000000000 --- a/db/post_migrate/20200406193427_add_index_to_issues_health_status.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class AddIndexToIssuesHealthStatus < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'idx_issues_on_health_status_not_null' - - disable_ddl_transaction! - - def up - add_concurrent_index( - :issues, - :health_status, - where: 'health_status IS NOT NULL', - name: INDEX_NAME - ) - end - - def down - remove_concurrent_index_by_name(:issues, INDEX_NAME) - end -end diff --git a/db/post_migrate/20200407094005_drop_vulnerability_severity_index.rb b/db/post_migrate/20200407094005_drop_vulnerability_severity_index.rb deleted file mode 100644 index 14e6ce32097..00000000000 --- a/db/post_migrate/20200407094005_drop_vulnerability_severity_index.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class DropVulnerabilitySeverityIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - INDEX_NAME = 'undefined_vulnerabilities' - - def up - remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME - end - - def down - add_concurrent_index(:vulnerability_occurrences, :id, where: 'severity = 0', name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200407094923_drop_vulnerabilities_severity_index.rb b/db/post_migrate/20200407094923_drop_vulnerabilities_severity_index.rb deleted file mode 100644 index 90ec7dc7ec2..00000000000 --- a/db/post_migrate/20200407094923_drop_vulnerabilities_severity_index.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class DropVulnerabilitiesSeverityIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - INDEX_NAME = 'undefined_vulnerability' - - def up - remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME - end - - def down - add_concurrent_index(:vulnerabilities, :id, where: 'severity = 0', name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200408110856_add_nginx_five_hundred_percentage_metric.rb b/db/post_migrate/20200408110856_add_nginx_five_hundred_percentage_metric.rb deleted file mode 100644 index a99e0291fe8..00000000000 --- a/db/post_migrate/20200408110856_add_nginx_five_hundred_percentage_metric.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class AddNginxFiveHundredPercentageMetric < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - ::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200408132152_remove_namespaces_trial_ends_on.rb b/db/post_migrate/20200408132152_remove_namespaces_trial_ends_on.rb deleted file mode 100644 index a303b9d1869..00000000000 --- a/db/post_migrate/20200408132152_remove_namespaces_trial_ends_on.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class RemoveNamespacesTrialEndsOn < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name :namespaces, 'index_namespaces_on_trial_ends_on' - - with_lock_retries do - remove_column :namespaces, :trial_ends_on - end - end - - def down - unless column_exists?(:namespaces, :trial_ends_on) - with_lock_retries do - add_column :namespaces, :trial_ends_on, :datetime_with_timezone # rubocop:disable Migration/AddColumnsToWideTables - end - end - - add_concurrent_index :namespaces, :trial_ends_on, using: 'btree', where: 'trial_ends_on IS NOT NULL' - end -end diff --git a/db/post_migrate/20200409211607_migrate_legacy_attachments.rb b/db/post_migrate/20200409211607_migrate_legacy_attachments.rb deleted file mode 100644 index fb4a996d3b7..00000000000 --- a/db/post_migrate/20200409211607_migrate_legacy_attachments.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class MigrateLegacyAttachments < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - - MIGRATION = 'LegacyUploadsMigrator' - BATCH_SIZE = 5000 - INTERVAL = 5.minutes.to_i - - class Upload < ActiveRecord::Base - self.table_name = 'uploads' - - include ::EachBatch - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Upload.where(uploader: 'AttachmentUploader', model_type: 'Note'), - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200416111111_migrate_vulnerability_dismissals.rb b/db/post_migrate/20200416111111_migrate_vulnerability_dismissals.rb deleted file mode 100644 index 6ca3db8902b..00000000000 --- a/db/post_migrate/20200416111111_migrate_vulnerability_dismissals.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class MigrateVulnerabilityDismissals < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - MIGRATION = 'UpdateVulnerabilitiesToDismissed' - BATCH_SIZE = 500 - DELAY_INTERVAL = 2.minutes.to_i - - class Vulnerability < ActiveRecord::Base - self.table_name = 'vulnerabilities' - self.inheritance_column = :_type_disabled - - include ::EachBatch - end - - def up - return unless Gitlab.ee? - - Vulnerability.select('project_id').group(:project_id).each_batch(of: BATCH_SIZE, column: "project_id") do |project_batch, index| - batch_delay = (index - 1) * BATCH_SIZE * DELAY_INTERVAL - - project_batch.each_with_index do |project, project_batch_index| - project_delay = project_batch_index * DELAY_INTERVAL - migrate_in(batch_delay + project_delay, MIGRATION, project[:project_id]) - end - end - end - - def down - # nothing to do - end -end diff --git a/db/post_migrate/20200420094444_backfill_snippet_repositories.rb b/db/post_migrate/20200420094444_backfill_snippet_repositories.rb deleted file mode 100644 index 452a1a5330f..00000000000 --- a/db/post_migrate/20200420094444_backfill_snippet_repositories.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class BackfillSnippetRepositories < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 3.minutes - BATCH_SIZE = 100 - MIGRATION = 'BackfillSnippetRepositories' - - disable_ddl_transaction! - - class Snippet < ActiveRecord::Base - include EachBatch - - self.table_name = 'snippets' - self.inheritance_column = :_type_disabled - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Snippet, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200420162730_remove_additional_application_settings_rows.rb b/db/post_migrate/20200420162730_remove_additional_application_settings_rows.rb deleted file mode 100644 index e4a0ec1eb4a..00000000000 --- a/db/post_migrate/20200420162730_remove_additional_application_settings_rows.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class RemoveAdditionalApplicationSettingsRows < ActiveRecord::Migration[6.0] - class ApplicationSetting < ActiveRecord::Base - self.table_name = 'application_settings' - end - - def up - return if ApplicationSetting.count == 1 - - execute "DELETE from application_settings WHERE id NOT IN (SELECT MAX(id) FROM application_settings);" - end - - def down - # no changes - end -end diff --git a/db/post_migrate/20200421195234_backfill_status_page_published_incidents.rb b/db/post_migrate/20200421195234_backfill_status_page_published_incidents.rb deleted file mode 100644 index fa7a5a9d924..00000000000 --- a/db/post_migrate/20200421195234_backfill_status_page_published_incidents.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -class BackfillStatusPagePublishedIncidents < ActiveRecord::Migration[6.0] - DOWNTIME = false - - disable_ddl_transaction! - - class Incident < ActiveRecord::Base - self.table_name = 'status_page_published_incidents' - end - - class StatusPageIssue < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'issues' - - scope :published_only, -> do - joins('INNER JOIN status_page_settings ON status_page_settings.project_id = issues.project_id') - .where('status_page_settings.enabled = true') - .where(confidential: false) - end - end - - def up - current_time = Time.current - - StatusPageIssue.published_only.each_batch do |batch| - incidents = batch.map do |status_page_issue| - { - issue_id: status_page_issue.id, - created_at: current_time, - updated_at: current_time - } - end - - Incident.insert_all(incidents, unique_by: :issue_id) - end - end - - def down - # no op - - # While we expect this table to be empty at the point of - # the up migration, there is no reliable way to determine - # whether records were added as a part of the migration - # or after it has run. - end -end diff --git a/db/post_migrate/20200424043515_drop_namespaces_plan_id.rb b/db/post_migrate/20200424043515_drop_namespaces_plan_id.rb deleted file mode 100644 index b05f2da648a..00000000000 --- a/db/post_migrate/20200424043515_drop_namespaces_plan_id.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class DropNamespacesPlanId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - with_lock_retries do - remove_column :namespaces, :plan_id - end - end - - def down - unless column_exists?(:namespaces, :plan_id) - with_lock_retries do - add_column :namespaces, :plan_id, :integer # rubocop:disable Migration/AddColumnsToWideTables - end - end - - add_concurrent_index :namespaces, :plan_id - add_concurrent_foreign_key :namespaces, :plans, column: :plan_id, on_delete: :nullify - end -end diff --git a/db/post_migrate/20200427064130_cleanup_optimistic_locking_nulls_pt2_fixed.rb b/db/post_migrate/20200427064130_cleanup_optimistic_locking_nulls_pt2_fixed.rb deleted file mode 100644 index 63f85fc7156..00000000000 --- a/db/post_migrate/20200427064130_cleanup_optimistic_locking_nulls_pt2_fixed.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -class CleanupOptimisticLockingNullsPt2Fixed < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - TABLES = %w(ci_stages ci_builds ci_pipelines).freeze - BATCH_SIZE = 10_000 - - def declare_class(table) - Class.new(ActiveRecord::Base) do - include EachBatch - - self.table_name = table - self.inheritance_column = :_type_disabled # Disable STI - end - end - - def up - last_table_final_delay = 0 - - TABLES.each do |table| - # cleanup wrong index created in the previous migration, it might be there on staging - remove_concurrent_index table.to_sym, :lock_version, where: "lock_version IS NULL" - - add_concurrent_index table.to_sym, :id, where: "lock_version IS NULL", name: "tmp_index_#{table}_lock_version" - - last_table_final_delay = queue_background_migration_jobs_by_range_at_intervals( - declare_class(table).where(lock_version: nil), - 'CleanupOptimisticLockingNulls', - 2.minutes, - batch_size: BATCH_SIZE, - other_job_arguments: [table], - initial_delay: last_table_final_delay - ) - end - end - - def down - TABLES.each do |table| - remove_concurrent_index table.to_sym, :id, where: "lock_version IS NULL", name: "tmp_index_#{table}_lock_version" - end - end -end diff --git a/db/post_migrate/20200428134356_remove_elastic_experimental_indexer_from_application_settings.rb b/db/post_migrate/20200428134356_remove_elastic_experimental_indexer_from_application_settings.rb deleted file mode 100644 index a9baf6fd8e3..00000000000 --- a/db/post_migrate/20200428134356_remove_elastic_experimental_indexer_from_application_settings.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true -class RemoveElasticExperimentalIndexerFromApplicationSettings < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def change - remove_column :application_settings, :elasticsearch_experimental_indexer, :boolean - end -end diff --git a/db/post_migrate/20200429002150_cleanup_sprints_state_rename.rb b/db/post_migrate/20200429002150_cleanup_sprints_state_rename.rb deleted file mode 100644 index 7f67a55a19d..00000000000 --- a/db/post_migrate/20200429002150_cleanup_sprints_state_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupSprintsStateRename < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :sprints, :state, :state_enum - end - - def down - undo_cleanup_concurrent_column_rename :sprints, :state, :state_enum - end -end diff --git a/db/post_migrate/20200506085748_update_undefined_confidence_from_occurrences.rb b/db/post_migrate/20200506085748_update_undefined_confidence_from_occurrences.rb deleted file mode 100644 index 06c82ad404b..00000000000 --- a/db/post_migrate/20200506085748_update_undefined_confidence_from_occurrences.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -class UpdateUndefinedConfidenceFromOccurrences < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - INDEX_NAME = 'index_vulnerability_occurrences_on_id_and_confidence_eq_zero' - DOWNTIME = false - - disable_ddl_transaction! - BATCH_SIZE = 1_000 - INTERVAL = 2.minutes - - # 286_159 records to be updated on GitLab.com - def up - # create temporary index for undefined vulnerabilities - add_concurrent_index(:vulnerability_occurrences, :id, where: 'confidence = 0', name: INDEX_NAME) - - return unless Gitlab.ee? - - migration = Gitlab::BackgroundMigration::RemoveUndefinedOccurrenceConfidenceLevel - migration_name = migration.to_s.demodulize - relation = migration::Occurrence.undefined_confidence - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - # temporary index is to be dropped in a different migration in an upcoming release - remove_concurrent_index(:vulnerability_occurrences, :id, where: 'confidence = 0', name: INDEX_NAME) - # This migration can not be reversed because we can not know which records had undefined confidence - end -end diff --git a/db/post_migrate/20200506125731_cleanup_user_highest_roles_population.rb b/db/post_migrate/20200506125731_cleanup_user_highest_roles_population.rb deleted file mode 100644 index 5e613228c56..00000000000 --- a/db/post_migrate/20200506125731_cleanup_user_highest_roles_population.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class CleanupUserHighestRolesPopulation < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_for_migrating_user_highest_roles_table' - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal('PopulateUserHighestRolesTable') - - remove_concurrent_index(:users, :id, name: INDEX_NAME) - end - - def down - add_concurrent_index(:users, - :id, - where: "state = 'active' AND user_type IS NULL AND bot_type IS NULL AND ghost IS NOT TRUE", - name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200506154421_migrate_scim_identities_to_saml_for_new_users.rb b/db/post_migrate/20200506154421_migrate_scim_identities_to_saml_for_new_users.rb deleted file mode 100644 index 718e788aad7..00000000000 --- a/db/post_migrate/20200506154421_migrate_scim_identities_to_saml_for_new_users.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class MigrateScimIdentitiesToSamlForNewUsers < ActiveRecord::Migration[6.0] - DOWNTIME = false - - class ScimIdentity < ActiveRecord::Base - self.table_name = 'scim_identities' - - belongs_to :user - - include ::EachBatch - end - - class Identity < ActiveRecord::Base - self.table_name = 'identities' - - belongs_to :saml_provider - end - - def up - users_with_saml_provider = Identity.select('user_id').joins(:saml_provider) - - ScimIdentity.each_batch do |relation| - identity_records = relation - .select("scim_identities.extern_uid, 'group_saml', scim_identities.user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, saml_providers.id") - .joins(:user) - .joins('inner join saml_providers on saml_providers.group_id=scim_identities.group_id') - .where("date_trunc('second',scim_identities.created_at) at time zone 'UTC' = date_trunc('second',users.created_at)") - .where.not(user_id: users_with_saml_provider) - - execute "insert into identities (extern_uid, provider, user_id, created_at, updated_at, saml_provider_id) #{identity_records.to_sql} on conflict do nothing" - end - end - - def down - end -end diff --git a/db/post_migrate/20200508091106_remove_bot_type.rb b/db/post_migrate/20200508091106_remove_bot_type.rb deleted file mode 100644 index 2afcf5308e7..00000000000 --- a/db/post_migrate/20200508091106_remove_bot_type.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class RemoveBotType < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name :users, 'index_users_on_bot_type' - - with_lock_retries do - remove_column :users, :bot_type - end - end - - def down - unless column_exists?(:users, :bot_type) - with_lock_retries do - add_column :users, :bot_type, :integer, limit: 2 # rubocop:disable Migration/AddColumnsToWideTables - end - end - - execute 'UPDATE users set bot_type = user_type WHERE user_type IN(1,2,3,6)' - - add_concurrent_index :users, :bot_type - end -end diff --git a/db/post_migrate/20200511080113_add_projects_foreign_key_to_namespaces.rb b/db/post_migrate/20200511080113_add_projects_foreign_key_to_namespaces.rb deleted file mode 100644 index a7f67a3b5cd..00000000000 --- a/db/post_migrate/20200511080113_add_projects_foreign_key_to_namespaces.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class AddProjectsForeignKeyToNamespaces < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - FK_NAME = 'fk_projects_namespace_id' - - def up - with_lock_retries do - add_foreign_key( - :projects, - :namespaces, - column: :namespace_id, - on_delete: :restrict, - validate: false, - name: FK_NAME - ) - end - end - - def down - with_lock_retries do - remove_foreign_key_if_exists :projects, column: :namespace_id, name: FK_NAME - end - end -end diff --git a/db/post_migrate/20200511083541_cleanup_projects_with_missing_namespace.rb b/db/post_migrate/20200511083541_cleanup_projects_with_missing_namespace.rb deleted file mode 100644 index 8e6ee0f35ca..00000000000 --- a/db/post_migrate/20200511083541_cleanup_projects_with_missing_namespace.rb +++ /dev/null @@ -1,261 +0,0 @@ -# frozen_string_literal: true - -# rubocop:disable Migration/PreventStrings - -# This migration cleans up Projects that were orphaned when their namespace was deleted -# Instead of deleting them, we: -# - Find (or create) the Ghost User -# - Create (if not already exists) a `lost-and-found` group owned by the Ghost User -# - Find orphaned projects --> namespace_id can not be found in namespaces -# - Move the orphaned projects to the `lost-and-found` group -# (while making them private and setting `archived=true`) -# -# On GitLab.com (2020-05-11) this migration will update 66 orphaned projects -class CleanupProjectsWithMissingNamespace < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - VISIBILITY_PRIVATE = 0 - ACCESS_LEVEL_OWNER = 50 - - # The batch size of projects to check in each iteration - # We expect the selectivity for orphaned projects to be very low: - # (66 orphaned projects out of a total 13.6M) - # so 10K should be a safe choice - BATCH_SIZE = 10000 - - disable_ddl_transaction! - - class UserDetail < ActiveRecord::Base - self.table_name = 'user_details' - - belongs_to :user, class_name: 'CleanupProjectsWithMissingNamespace::User' - end - - class User < ActiveRecord::Base - self.table_name = 'users' - - LOST_AND_FOUND_GROUP = 'lost-and-found' - USER_TYPE_GHOST = 5 - DEFAULT_PROJECTS_LIMIT = 100000 - - default_value_for :admin, false - default_value_for :can_create_group, true # we need this to create the group - default_value_for :can_create_team, false - default_value_for :project_view, :files - default_value_for :notified_of_own_activity, false - default_value_for :preferred_language, I18n.default_locale - - has_one :user_detail, class_name: 'CleanupProjectsWithMissingNamespace::UserDetail' - has_one :namespace, -> { where(type: nil) }, - foreign_key: :owner_id, inverse_of: :owner, autosave: true, - class_name: 'CleanupProjectsWithMissingNamespace::Namespace' - - before_save :ensure_namespace_correct - before_save :ensure_bio_is_assigned_to_user_details, if: :bio_changed? - - enum project_view: { readme: 0, activity: 1, files: 2 } - - def ensure_namespace_correct - if namespace - namespace.path = username if username_changed? - namespace.name = name if name_changed? - else - build_namespace(path: username, name: name) - end - end - - def ensure_bio_is_assigned_to_user_details - user_detail.bio = bio.to_s[0...255] - end - - def user_detail - super.presence || build_user_detail - end - - # Return (or create if necessary) the `lost-and-found` group - def lost_and_found_group - existing_lost_and_found_group || Group.create_unique_group(self, LOST_AND_FOUND_GROUP) - end - - def existing_lost_and_found_group - # There should only be one Group for User Ghost starting with LOST_AND_FOUND_GROUP - Group - .joins('INNER JOIN members ON namespaces.id = members.source_id') - .where(namespaces: { type: 'Group' }) - .where(members: { type: 'GroupMember' }) - .where(members: { source_type: 'Namespace' }) - .where(members: { user_id: self.id }) - .where(members: { requested_at: nil }) - .where(members: { access_level: ACCESS_LEVEL_OWNER }) - .find_by(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%")) - end - - class << self - # Return (or create if necessary) the ghost user - def ghost - email = 'ghost%s@example.com' - - unique_internal(where(user_type: USER_TYPE_GHOST), 'ghost', email) do |u| - u.bio = _('This is a "Ghost User", created to hold all issues authored by users that have since been deleted. This user cannot be removed.') - u.name = 'Ghost User' - end - end - - def unique_internal(scope, username, email_pattern, &block) - scope.first || create_unique_internal(scope, username, email_pattern, &block) - end - - def create_unique_internal(scope, username, email_pattern, &creation_block) - # Since we only want a single one of these in an instance, we use an - # exclusive lease to ensure that this block is never run concurrently. - lease_key = "user:unique_internal:#{username}" - lease = Gitlab::ExclusiveLease.new(lease_key, timeout: 1.minute.to_i) - - until uuid = lease.try_obtain - # Keep trying until we obtain the lease. To prevent hammering Redis too - # much we'll wait for a bit between retries. - sleep(1) - end - - # Recheck if the user is already present. One might have been - # added between the time we last checked (first line of this method) - # and the time we acquired the lock. - existing_user = uncached { scope.first } - return existing_user if existing_user.present? - - uniquify = Uniquify.new - - username = uniquify.string(username) { |s| User.find_by_username(s) } - - email = uniquify.string(-> (n) { Kernel.sprintf(email_pattern, n) }) do |s| - User.find_by_email(s) - end - - User.create!( - username: username, - email: email, - user_type: USER_TYPE_GHOST, - projects_limit: DEFAULT_PROJECTS_LIMIT, - state: :active, - &creation_block - ) - ensure - Gitlab::ExclusiveLease.cancel(lease_key, uuid) - end - end - end - - class Namespace < ActiveRecord::Base - self.table_name = 'namespaces' - - belongs_to :owner, class_name: 'CleanupProjectsWithMissingNamespace::User' - end - - class Group < Namespace - # Disable STI to allow us to manually set "type = 'Group'" - # Otherwise rails forces "type = CleanupProjectsWithMissingNamespace::Group" - self.inheritance_column = :_type_disabled - - def self.create_unique_group(user, group_name) - # 'lost-and-found' may be already defined, find a unique one - group_name = Uniquify.new.string(group_name) do |str| - Group.where(parent_id: nil, name: str).exists? - end - - group = Group.create!( - name: group_name, - path: group_name, - type: 'Group', - description: 'Group to store orphaned projects', - visibility_level: VISIBILITY_PRIVATE - ) - - # No need to create a route for the lost-and-found group - - GroupMember.add_user(group, user, ACCESS_LEVEL_OWNER) - - group - end - end - - class Member < ActiveRecord::Base - self.table_name = 'members' - end - - class GroupMember < Member - NOTIFICATION_SETTING_GLOBAL = 3 - - # Disable STI to allow us to manually set "type = 'GroupMember'" - # Otherwise rails forces "type = CleanupProjectsWithMissingNamespace::GroupMember" - self.inheritance_column = :_type_disabled - - def self.add_user(source, user, access_level) - GroupMember.create!( - type: 'GroupMember', - source_id: source.id, - user_id: user.id, - source_type: 'Namespace', - access_level: access_level, - notification_level: NOTIFICATION_SETTING_GLOBAL - ) - end - end - - class Project < ActiveRecord::Base - self.table_name = 'projects' - - include ::EachBatch - - def self.without_namespace - where( - 'NOT EXISTS ( - SELECT 1 - FROM namespaces - WHERE projects.namespace_id = namespaces.id - )' - ) - end - end - - def up - # Reset the column information of all the models that update the database - # to ensure the Active Record's knowledge of the table structure is current - User.reset_column_information - Namespace.reset_column_information - Member.reset_column_information - Project.reset_column_information - - # Find or Create the ghost user - ghost_user = User.ghost - - # Find or Create the `lost-and-found` - lost_and_found = ghost_user.lost_and_found_group - - # With BATCH_SIZE=10K and projects.count=13.6M - # ~1360 iterations will be run: - # - each requires on average ~160ms for relation.without_namespace - # - worst case scenario is that 66 of those batches will trigger an update (~200ms each) - # In general, we expect less than 5% (=66/13.6M x 10K) to trigger an update - # Expected total run time: ~235 seconds (== 220 seconds + 14 seconds) - Project.each_batch(of: BATCH_SIZE) do |relation| - relation.without_namespace.update_all <<~SQL - namespace_id = #{lost_and_found.id}, - archived = TRUE, - visibility_level = #{VISIBILITY_PRIVATE}, - - -- Names are expected to be unique inside their namespace - -- (uniqueness validation on namespace_id, name) - -- Attach the id to the name and path to make sure that they are unique - name = name || '_' || id::text, - path = path || '_' || id::text - SQL - end - end - - def down - # no-op: the original state for those projects was inconsistent - # Also, the original namespace_id for each project is lost during the update - end -end -# rubocop:enable Migration/PreventStrings diff --git a/db/post_migrate/20200511092714_update_undefined_confidence_from_vulnerabilities.rb b/db/post_migrate/20200511092714_update_undefined_confidence_from_vulnerabilities.rb deleted file mode 100644 index d6611ddbd66..00000000000 --- a/db/post_migrate/20200511092714_update_undefined_confidence_from_vulnerabilities.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -class UpdateUndefinedConfidenceFromVulnerabilities < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - INDEX_NAME = 'index_vulnerability_on_id_and_confidence_eq_zero' - DOWNTIME = false - - disable_ddl_transaction! - BATCH_SIZE = 1_000 - INTERVAL = 2.minutes - - # 87_602 records to be updated on GitLab.com - def up - # create temporary index for undefined vulnerabilities - add_concurrent_index(:vulnerabilities, :id, where: 'confidence = 0', name: INDEX_NAME) - - return unless Gitlab.ee? - - migration = Gitlab::BackgroundMigration::RemoveUndefinedVulnerabilityConfidenceLevel - migration_name = migration.to_s.demodulize - relation = migration::Vulnerability.undefined_confidence - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - # temporary index is to be dropped in a different migration in an upcoming release - remove_concurrent_index(:vulnerabilities, :id, where: 'confidence = 0', name: INDEX_NAME) - # This migration can not be reversed because we can not know which records had undefined confidence - end -end diff --git a/db/post_migrate/20200511130130_ensure_deprecated_jenkins_service_records_removal.rb b/db/post_migrate/20200511130130_ensure_deprecated_jenkins_service_records_removal.rb deleted file mode 100644 index 4c1f29f8e47..00000000000 --- a/db/post_migrate/20200511130130_ensure_deprecated_jenkins_service_records_removal.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class EnsureDeprecatedJenkinsServiceRecordsRemoval < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute <<~SQL.strip - DELETE FROM services WHERE type = 'JenkinsDeprecatedService'; - SQL - end - - def down - # no-op - - # The records were removed by `up` - end -end diff --git a/db/post_migrate/20200511145545_change_variable_interpolation_format_in_common_metrics.rb b/db/post_migrate/20200511145545_change_variable_interpolation_format_in_common_metrics.rb deleted file mode 100644 index ac3c545350d..00000000000 --- a/db/post_migrate/20200511145545_change_variable_interpolation_format_in_common_metrics.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class ChangeVariableInterpolationFormatInCommonMetrics < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - ::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute - end - - def down - # no-op - # The import cannot be reversed since we do not know the state that the - # common metrics in the PrometheusMetric table were in before the import. - end -end diff --git a/db/post_migrate/20200511162057_add_missing_instance_to_servicess.rb b/db/post_migrate/20200511162057_add_missing_instance_to_servicess.rb deleted file mode 100644 index efaef085e8c..00000000000 --- a/db/post_migrate/20200511162057_add_missing_instance_to_servicess.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class AddMissingInstanceToServicess < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - # This is a corrective migration to keep the instance column. - # Upgrade from 12.7 to 12.9 removes the instance column as it was first added - # in the normal migration and then removed in the post migration. - # - # 12.8 removed the instance column in a post deployment migration https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24885 - # 12.9 added the instance column in a normal migration https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25714 - # - # rubocop:disable Migration/AddColumnWithDefault - # rubocop:disable Migration/UpdateLargeTable - def up - unless column_exists?(:services, :instance) - add_column_with_default(:services, :instance, :boolean, default: false) - end - end - # rubocop:enable Migration/AddColumnWithDefault - # rubocop:enable Migration/UpdateLargeTable - - def down - # Does not apply - end -end diff --git a/db/post_migrate/20200511162115_add_missing_index_to_service_unique_instance_per_type.rb b/db/post_migrate/20200511162115_add_missing_index_to_service_unique_instance_per_type.rb deleted file mode 100644 index c9e0193f5d2..00000000000 --- a/db/post_migrate/20200511162115_add_missing_index_to_service_unique_instance_per_type.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class AddMissingIndexToServiceUniqueInstancePerType < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - # This is a corrective migration to keep the index on instance column. - # Upgrade from 12.7 to 12.9 removes the instance column as it was first added - # in the normal migration and then removed in the post migration. - # - # 12.8 removed the instance column in a post deployment migration https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24885 - # 12.9 added the instance column in a normal migration https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25714 - def up - unless index_exists_by_name?(:services, 'index_services_on_type_and_instance') - add_concurrent_index(:services, [:type, :instance], unique: true, where: 'instance IS TRUE') - end - end - - def down - # Does not apply - end -end diff --git a/db/post_migrate/20200511220023_validate_projects_foreign_key_to_namespaces.rb b/db/post_migrate/20200511220023_validate_projects_foreign_key_to_namespaces.rb deleted file mode 100644 index 37a761507fc..00000000000 --- a/db/post_migrate/20200511220023_validate_projects_foreign_key_to_namespaces.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class ValidateProjectsForeignKeyToNamespaces < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - FK_NAME = 'fk_projects_namespace_id' - - def up - # Validate the FK added with 20200511080113_add_projects_foreign_key_to_namespaces.rb - validate_foreign_key :projects, :namespace_id, name: FK_NAME - end - - def down - # no-op: No need to invalidate the foreign key - # The inconsistent data are permanently fixed with the data migration - # `20200511083541_cleanup_projects_with_missing_namespace.rb` - # even if it is rolled back. - # If there is an issue with the FK, we'll roll back the migration that adds the FK - end -end diff --git a/db/post_migrate/20200513171959_enable_hashed_storage.rb b/db/post_migrate/20200513171959_enable_hashed_storage.rb deleted file mode 100644 index 53e52b1caff..00000000000 --- a/db/post_migrate/20200513171959_enable_hashed_storage.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class EnableHashedStorage < ActiveRecord::Migration[6.0] - DOWNTIME = false - - class ApplicationSetting < ActiveRecord::Base - self.table_name = 'application_settings' - end - - def up - ApplicationSetting.update_all(hashed_storage_enabled: true) - end - - def down - # in 13.0 we are forcing hashed storage to always be enabled for new projects - end -end diff --git a/db/post_migrate/20200514000009_add_not_null_constraint_on_file_store_to_lfs_objects.rb b/db/post_migrate/20200514000009_add_not_null_constraint_on_file_store_to_lfs_objects.rb deleted file mode 100644 index 6b3b9a3155d..00000000000 --- a/db/post_migrate/20200514000009_add_not_null_constraint_on_file_store_to_lfs_objects.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintOnFileStoreToLfsObjects < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint(:lfs_objects, :file_store, validate: false) - end - - def down - remove_not_null_constraint(:lfs_objects, :file_store) - end -end diff --git a/db/post_migrate/20200514000132_add_not_null_constraint_on_store_to_uploads.rb b/db/post_migrate/20200514000132_add_not_null_constraint_on_store_to_uploads.rb deleted file mode 100644 index c5f1cfa79b8..00000000000 --- a/db/post_migrate/20200514000132_add_not_null_constraint_on_store_to_uploads.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintOnStoreToUploads < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint(:uploads, :store, validate: false) - end - - def down - remove_not_null_constraint(:uploads, :store) - end -end diff --git a/db/post_migrate/20200514000340_add_not_null_constraint_on_file_store_to_ci_jobs_artifacts.rb b/db/post_migrate/20200514000340_add_not_null_constraint_on_file_store_to_ci_jobs_artifacts.rb deleted file mode 100644 index 5759803e3b7..00000000000 --- a/db/post_migrate/20200514000340_add_not_null_constraint_on_file_store_to_ci_jobs_artifacts.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintOnFileStoreToCiJobsArtifacts < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint(:ci_job_artifacts, :file_store, validate: false) - end - - def down - remove_not_null_constraint(:ci_job_artifacts, :file_store) - end -end diff --git a/db/post_migrate/20200518114540_schedule_fix_ruby_object_in_audit_events.rb b/db/post_migrate/20200518114540_schedule_fix_ruby_object_in_audit_events.rb deleted file mode 100644 index e4335089540..00000000000 --- a/db/post_migrate/20200518114540_schedule_fix_ruby_object_in_audit_events.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -class ScheduleFixRubyObjectInAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_audit_events_on_ruby_object_in_details' - INTERVAL = 2.minutes.to_i - BATCH_SIZE = 1_000 - MIGRATION = 'FixRubyObjectInAuditEvents' - - disable_ddl_transaction! - - class AuditEvent < ActiveRecord::Base - self.table_name = 'audit_events' - - include ::EachBatch - end - - def up - return unless Gitlab.ee? - - # create temporary index for audit_events with ruby/object in details field, may take well over 1h - add_concurrent_index(:audit_events, :id, where: "details ~~ '%ruby/object%'", name: INDEX_NAME) - - relation = AuditEvent.where("details ~~ '%ruby/object%'") - - queue_background_migration_jobs_by_range_at_intervals( - relation, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE - ) - end - - def down - # temporary index is to be dropped in a different migration in an upcoming release - # https://gitlab.com/gitlab-org/gitlab/issues/196842 - remove_concurrent_index_by_name(:audit_events, INDEX_NAME) - end -end diff --git a/db/post_migrate/20200518133123_add_index_on_starting_ending_at_to_metrics_dashboard_annotations.rb b/db/post_migrate/20200518133123_add_index_on_starting_ending_at_to_metrics_dashboard_annotations.rb deleted file mode 100644 index 3094fff0d1d..00000000000 --- a/db/post_migrate/20200518133123_add_index_on_starting_ending_at_to_metrics_dashboard_annotations.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnStartingEndingAtToMetricsDashboardAnnotations < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_metrics_dashboard_annotations_on_timespan_end' - - disable_ddl_transaction! - - def up - add_concurrent_index :metrics_dashboard_annotations, 'COALESCE(ending_at, starting_at)', name: INDEX_NAME - end - - def down - remove_concurrent_index :metrics_dashboard_annotations, 'COALESCE(ending_at, starting_at)', name: INDEX_NAME - end -end diff --git a/db/post_migrate/20200519171058_update_index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial.rb b/db/post_migrate/20200519171058_update_index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial.rb deleted file mode 100644 index e09ad4bdadf..00000000000 --- a/db/post_migrate/20200519171058_update_index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -class UpdateIndexCiBuildsOnCommitIdAndArtifactsExpireatandidpartial < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - OLD_INDEX_NAME = 'index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial' - NEW_INDEX_NAME = 'index_ci_builds_on_commit_id_artifacts_expired_at_and_id' - - OLD_CLAUSE = "type::text = 'Ci::Build'::text AND (retried = false OR retried IS NULL) AND - (name::text = ANY (ARRAY['sast'::character varying, - 'dependency_scanning'::character varying, - 'sast:container'::character varying, - 'container_scanning'::character varying, - 'dast'::character varying]::text[]))" - - NEW_CLAUSE = "type::text = 'Ci::Build'::text AND (retried = false OR retried IS NULL) AND - (name::text = ANY (ARRAY['sast'::character varying, - 'secret_detection'::character varying, - 'dependency_scanning'::character varying, - 'container_scanning'::character varying, - 'dast'::character varying]::text[]))" - - def up - add_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], name: NEW_INDEX_NAME, where: NEW_CLAUSE - remove_concurrent_index_by_name :ci_builds, OLD_INDEX_NAME - end - - def down - add_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], name: OLD_INDEX_NAME, where: OLD_CLAUSE - remove_concurrent_index_by_name :ci_builds, NEW_INDEX_NAME - end -end diff --git a/db/post_migrate/20200519201128_migrate_vulnerability_dismissal_feedback.rb b/db/post_migrate/20200519201128_migrate_vulnerability_dismissal_feedback.rb deleted file mode 100644 index fee2f59abb5..00000000000 --- a/db/post_migrate/20200519201128_migrate_vulnerability_dismissal_feedback.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -class MigrateVulnerabilityDismissalFeedback < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - MIGRATION = 'UpdateVulnerabilitiesFromDismissalFeedback' - BATCH_SIZE = 500 - DELAY_INTERVAL = 2.minutes.to_i - - class Vulnerability < ActiveRecord::Base - self.table_name = 'vulnerabilities' - self.inheritance_column = :_type_disabled - - include ::EachBatch - end - - def up - return unless Gitlab.ee? - - Vulnerability.select('project_id').group(:project_id).each_batch(of: BATCH_SIZE, column: "project_id") do |project_batch, index| - batch_delay = (index - 1) * BATCH_SIZE * DELAY_INTERVAL - - project_batch.each_with_index do |project, project_batch_index| - project_delay = project_batch_index * DELAY_INTERVAL - migrate_in(batch_delay + project_delay, MIGRATION, project[:project_id]) - end - end - end - - def down - # nothing to do - end -end diff --git a/db/post_migrate/20200525121014_drop_users_ghost_column.rb b/db/post_migrate/20200525121014_drop_users_ghost_column.rb deleted file mode 100644 index 1f80bc74b9d..00000000000 --- a/db/post_migrate/20200525121014_drop_users_ghost_column.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class DropUsersGhostColumn < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name :users, 'index_users_on_ghost' - - with_lock_retries do - remove_column :users, :ghost - end - end - - def down - unless column_exists?(:users, :ghost) - with_lock_retries do - add_column :users, :ghost, :boolean # rubocop:disable Migration/AddColumnsToWideTables - end - end - - execute 'UPDATE users set ghost = TRUE WHERE user_type = 5' - - add_concurrent_index :users, :ghost - end -end diff --git a/db/post_migrate/20200525144525_migrate_stuck_import_jobs_queue_to_stuck_project_import_jobs.rb b/db/post_migrate/20200525144525_migrate_stuck_import_jobs_queue_to_stuck_project_import_jobs.rb deleted file mode 100644 index 57e25c928f1..00000000000 --- a/db/post_migrate/20200525144525_migrate_stuck_import_jobs_queue_to_stuck_project_import_jobs.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class MigrateStuckImportJobsQueueToStuckProjectImportJobs < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'cronjob:stuck_import_jobs', to: 'cronjob:import_stuck_project_import_jobs' - end - - def down - sidekiq_queue_migrate 'cronjob:import_stuck_project_import_jobs', to: 'cronjob:stuck_import_jobs' - end -end diff --git a/db/post_migrate/20200526000407_seed_repository_storages_weighted.rb b/db/post_migrate/20200526000407_seed_repository_storages_weighted.rb deleted file mode 100644 index 979f16e75ed..00000000000 --- a/db/post_migrate/20200526000407_seed_repository_storages_weighted.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class SeedRepositoryStoragesWeighted < ActiveRecord::Migration[6.0] - DOWNTIME = false - - class ApplicationSetting < ActiveRecord::Base - serialize :repository_storages - self.table_name = 'application_settings' - end - - def up - # We need to flush the cache to ensure the newly-added column is loaded - ApplicationSetting.reset_column_information - - # There should only be one row here due to - # 20200420162730_remove_additional_application_settings_rows.rb - ApplicationSetting.all.each do |settings| - storages = Gitlab.config.repositories.storages.keys.collect do |storage| - weight = settings.repository_storages.include?(storage) ? 100 : 0 - [storage.to_sym, weight] - end - - settings.repository_storages_weighted = Hash[storages] - settings.save! - end - end - - def down - end -end diff --git a/db/post_migrate/20200526115436_dedup_mr_metrics.rb b/db/post_migrate/20200526115436_dedup_mr_metrics.rb deleted file mode 100644 index d2660504939..00000000000 --- a/db/post_migrate/20200526115436_dedup_mr_metrics.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true - -class DedupMrMetrics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - TMP_INDEX_NAME = 'tmp_unique_merge_request_metrics_by_merge_request_id' - INDEX_NAME = 'unique_merge_request_metrics_by_merge_request_id' - - disable_ddl_transaction! - - class MergeRequestMetrics < ActiveRecord::Base - self.table_name = 'merge_request_metrics' - - include EachBatch - end - - def up - last_metrics_record_id = MergeRequestMetrics.maximum(:id) || 0 - - # This index will disallow further duplicates while we're deduplicating the data. - add_concurrent_index(:merge_request_metrics, :merge_request_id, where: "id > #{Integer(last_metrics_record_id)}", unique: true, name: TMP_INDEX_NAME) - - MergeRequestMetrics.each_batch do |relation| - duplicated_merge_request_ids = MergeRequestMetrics - .where(merge_request_id: relation.select(:merge_request_id)) - .select(:merge_request_id) - .group(:merge_request_id) - .having('COUNT(merge_request_metrics.merge_request_id) > 1') - .pluck(:merge_request_id) - - duplicated_merge_request_ids.each do |merge_request_id| - deduplicate_item(merge_request_id) - end - end - - add_concurrent_index(:merge_request_metrics, :merge_request_id, unique: true, name: INDEX_NAME) - remove_concurrent_index_by_name(:merge_request_metrics, TMP_INDEX_NAME) - end - - def down - remove_concurrent_index_by_name(:merge_request_metrics, TMP_INDEX_NAME) - remove_concurrent_index_by_name(:merge_request_metrics, INDEX_NAME) - end - - private - - def deduplicate_item(merge_request_id) - merge_request_metrics_records = MergeRequestMetrics.where(merge_request_id: merge_request_id).order(updated_at: :asc).to_a - - attributes = {} - merge_request_metrics_records.each do |merge_request_metrics_record| - params = merge_request_metrics_record.attributes.except('id') - attributes.merge!(params.compact) - end - - ActiveRecord::Base.transaction do - record_to_keep = merge_request_metrics_records.pop - records_to_delete = merge_request_metrics_records - - MergeRequestMetrics.where(id: records_to_delete.map(&:id)).delete_all - record_to_keep.update!(attributes) - end - end -end diff --git a/db/post_migrate/20200527094322_drop_vulnerability_confidence_index.rb b/db/post_migrate/20200527094322_drop_vulnerability_confidence_index.rb deleted file mode 100644 index e9a9dd5eff8..00000000000 --- a/db/post_migrate/20200527094322_drop_vulnerability_confidence_index.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class DropVulnerabilityConfidenceIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - INDEX_NAME = 'index_vulnerability_on_id_and_confidence_eq_zero' - - def up - Gitlab::BackgroundMigration.steal('RemoveUndefinedVulnerabilityConfidenceLevel') - - remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME - end - - def down - add_concurrent_index(:vulnerabilities, :id, where: 'confidence = 0', name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200527095401_drop_vulnerability_occurrence_confidence_index.rb b/db/post_migrate/20200527095401_drop_vulnerability_occurrence_confidence_index.rb deleted file mode 100644 index 99fe4da7686..00000000000 --- a/db/post_migrate/20200527095401_drop_vulnerability_occurrence_confidence_index.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class DropVulnerabilityOccurrenceConfidenceIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - INDEX_NAME = 'index_vulnerability_occurrences_on_id_and_confidence_eq_zero' - - def up - Gitlab::BackgroundMigration.steal('RemoveUndefinedOccurrenceConfidenceLevel') - - remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME - end - - def down - add_concurrent_index(:vulnerability_occurrences, :id, where: 'confidence = 0', name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200528123703_add_merge_request_partial_index_to_events.rb b/db/post_migrate/20200528123703_add_merge_request_partial_index_to_events.rb deleted file mode 100644 index bf2269e77ab..00000000000 --- a/db/post_migrate/20200528123703_add_merge_request_partial_index_to_events.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class AddMergeRequestPartialIndexToEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - INDEX_NAME = 'index_events_on_author_id_and_created_at_merge_requests' - - def up - add_concurrent_index( - :events, - [:author_id, :created_at], - name: INDEX_NAME, - where: "(target_type = 'MergeRequest')" - ) - end - - def down - remove_concurrent_index :events, INDEX_NAME - end -end diff --git a/db/post_migrate/20200601120434_migrate_all_merge_request_user_mentions_to_db.rb b/db/post_migrate/20200601120434_migrate_all_merge_request_user_mentions_to_db.rb deleted file mode 100644 index fc7b9afe5f9..00000000000 --- a/db/post_migrate/20200601120434_migrate_all_merge_request_user_mentions_to_db.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class MigrateAllMergeRequestUserMentionsToDb < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY = 2.minutes.to_i - BATCH_SIZE = 100_000 - MIGRATION = 'UserMentions::CreateResourceUserMention' - - JOIN = "LEFT JOIN merge_request_user_mentions on merge_requests.id = merge_request_user_mentions.merge_request_id" - QUERY_CONDITIONS = "(description LIKE '%@%' OR title LIKE '%@%') AND merge_request_user_mentions.merge_request_id IS NULL" - - disable_ddl_transaction! - - class MergeRequest < ActiveRecord::Base - include EachBatch - end - - def up - delay = DELAY - - MergeRequest.each_batch(of: BATCH_SIZE) do |batch, _| - range = batch.pluck('MIN(merge_requests.id)', 'MAX(merge_requests.id)').first - records_count = MergeRequest.joins(JOIN).where(QUERY_CONDITIONS).where(id: range.first..range.last).count - - if records_count > 0 - migrate_in(delay, MIGRATION, ['MergeRequest', JOIN, QUERY_CONDITIONS, false, *range]) - delay += [DELAY, (records_count / 500 + 1).minutes.to_i].max - end - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200602013900_add_limit_to_designs_filename.rb b/db/post_migrate/20200602013900_add_limit_to_designs_filename.rb deleted file mode 100644 index 88732648965..00000000000 --- a/db/post_migrate/20200602013900_add_limit_to_designs_filename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddLimitToDesignsFilename < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_text_limit(:design_management_designs, :filename, 255, validate: false) - end - - def down - remove_text_limit(:design_management_designs, :filename) - end -end diff --git a/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb b/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb deleted file mode 100644 index 0458481c6bd..00000000000 --- a/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -class CapDesignsFilenameLengthToNewLimit < ActiveRecord::Migration[6.0] - DOWNTIME = false - - CHAR_LENGTH = 255 - MODIFIED_NAME = 'gitlab-modified-' - MODIFIED_EXTENSION = '.jpg' - - def up - arel_table = Arel::Table.new(:design_management_designs) - - # Design filenames larger than the limit will be renamed to "gitlab-modified-{id}.jpg", - # which will be valid and unique. The design file itself will appear broken, as it is - # understood that no designs with filenames that exceed this limit will be legitimate. - # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33565/diffs#note_355789080 - new_value_clause = Arel::Nodes::NamedFunction.new( - 'CONCAT', - [ - Arel::Nodes.build_quoted(MODIFIED_NAME), - arel_table[:id], - Arel::Nodes.build_quoted(MODIFIED_EXTENSION) - ] - ) - where_clause = Arel::Nodes::NamedFunction.new( - 'CHAR_LENGTH', - [arel_table[:filename]] - ).gt(CHAR_LENGTH) - - update_arel = Arel::UpdateManager.new.table(arel_table) - .set([[arel_table[:filename], new_value_clause]]) - .where(where_clause) - - ActiveRecord::Base.connection.execute(update_arel.to_sql) - end - - def down - # no-op : the original filename is lost forever - end -end diff --git a/db/post_migrate/20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb b/db/post_migrate/20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb deleted file mode 100644 index 2b036a8da80..00000000000 --- a/db/post_migrate/20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb +++ /dev/null @@ -1,188 +0,0 @@ -# frozen_string_literal: true - -# This migration adds or updates the routes for all the entities affected by -# post-migration '20200511083541_cleanup_projects_with_missing_namespace' -# - A route is added for the 'lost-and-found' group -# - A route is added for the Ghost user (if not already defined) -# - The routes for all the orphaned projects that were moved under the 'lost-and-found' -# group are updated to reflect the new path -class UpdateRoutesForLostAndFoundGroupAndOrphanedProjects < ActiveRecord::Migration[6.0] - DOWNTIME = false - - class User < ActiveRecord::Base - self.table_name = 'users' - - LOST_AND_FOUND_GROUP = 'lost-and-found' - USER_TYPE_GHOST = 5 - ACCESS_LEVEL_OWNER = 50 - - has_one :namespace, -> { where(type: nil) }, - foreign_key: :owner_id, inverse_of: :owner, autosave: true, - class_name: 'UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace' - - def lost_and_found_group - # Find the 'lost-and-found' group - # There should only be one Group owned by the Ghost user starting with 'lost-and-found' - Group - .joins('INNER JOIN members ON namespaces.id = members.source_id') - .where(namespaces: { type: 'Group' }) - .where(members: { type: 'GroupMember' }) - .where(members: { source_type: 'Namespace' }) - .where(members: { user_id: self.id }) - .where(members: { access_level: ACCESS_LEVEL_OWNER }) - .find_by(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%")) - end - - class << self - # Return the ghost user - def ghost - User.find_by(user_type: USER_TYPE_GHOST) - end - end - end - - # Temporary Concern to not repeat the same methods twice - module HasPath - extend ActiveSupport::Concern - - def full_path - if parent && path - parent.full_path + '/' + path - else - path - end - end - - def full_name - if parent && name - parent.full_name + ' / ' + name - else - name - end - end - end - - class Namespace < ActiveRecord::Base - include HasPath - - self.table_name = 'namespaces' - - belongs_to :owner, class_name: 'UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::User' - belongs_to :parent, class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace" - has_many :children, foreign_key: :parent_id, - class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace" - has_many :projects, class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Project" - - def ensure_route! - unless Route.for_source('Namespace', self.id) - Route.create!( - source_id: self.id, - source_type: 'Namespace', - path: self.full_path, - name: self.full_name - ) - end - end - - def generate_unique_path - # Generate a unique path if there is no route for the namespace - # (an existing route guarantees that the path is already unique) - unless Route.for_source('Namespace', self.id) - self.path = Uniquify.new.string(self.path) do |str| - Route.where(path: str).exists? - end - end - end - end - - class Group < Namespace - # Disable STI to allow us to manually set "type = 'Group'" - # Otherwise rails forces "type = CleanupProjectsWithMissingNamespace::Group" - self.inheritance_column = :_type_disabled - end - - class Route < ActiveRecord::Base - self.table_name = 'routes' - - def self.for_source(source_type, source_id) - Route.find_by(source_type: source_type, source_id: source_id) - end - end - - class Project < ActiveRecord::Base - include HasPath - - self.table_name = 'projects' - - belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id', - class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Group" - belongs_to :namespace, - class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace" - - alias_method :parent, :namespace - alias_attribute :parent_id, :namespace_id - - def ensure_route! - Route.find_or_initialize_by(source_type: 'Project', source_id: self.id).tap do |record| - record.path = self.full_path - record.name = self.full_name - record.save! - end - end - end - - def up - # Reset the column information of all the models that update the database - # to ensure the Active Record's knowledge of the table structure is current - Namespace.reset_column_information - Route.reset_column_information - User.reset_column_information - - # Find the ghost user, its namespace and the "lost and found" group - ghost_user = User.ghost - return unless ghost_user # No reason to continue if there is no Ghost user - - ghost_namespace = ghost_user.namespace - lost_and_found_group = ghost_user.lost_and_found_group - - # No reason to continue if there is no 'lost-and-found' group - # 1. No orphaned projects were found in this instance, or - # 2. The 'lost-and-found' group and the orphaned projects have been already deleted - return unless lost_and_found_group - - # Update the 'lost-and-found' group description to be more self-explanatory - lost_and_found_group.generate_unique_path - lost_and_found_group.description = - 'Group for storing projects that were not properly deleted. '\ - 'It should be considered as a system level Group with non-working '\ - 'projects inside it. The contents may be deleted with a future update. '\ - 'More info: gitlab.com/gitlab-org/gitlab/-/issues/198603' - lost_and_found_group.save! - - # make sure that the ghost namespace has a unique path - ghost_namespace.generate_unique_path - - if ghost_namespace.path_changed? - ghost_namespace.save! - # If the path changed, also update the Ghost User's username to match the new path. - ghost_user.update!(username: ghost_namespace.path) - end - - # Update the routes for the Ghost user, the "lost and found" group - # and all the orphaned projects - ghost_namespace.ensure_route! - lost_and_found_group.ensure_route! - - # The following does a fast index scan by namespace_id - # No reason to process in batches: - # - 66 projects in GitLab.com, less than 1ms execution time to fetch them - # with a constant update time for each - lost_and_found_group.projects.each do |project| - project.ensure_route! - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb b/db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb deleted file mode 100644 index 0566524fa90..00000000000 --- a/db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -class BackfillImportedSnippetRepositories < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY_INTERVAL = 2.minutes.to_i - BATCH_SIZE = 200 - MIGRATION = 'BackfillSnippetRepositories' - - disable_ddl_transaction! - - class Snippet < ActiveRecord::Base - include EachBatch - - self.table_name = 'snippets' - self.inheritance_column = :_type_disabled - end - - class SnippetRepository < ActiveRecord::Base - self.table_name = 'snippet_repositories' - end - - def up - index = 1 - - Snippet.select(:id).where.not(id: SnippetRepository.select(:snippet_id)).each_batch(of: BATCH_SIZE, column: 'id') do |batch| - split_in_consecutive_batches(batch).each do |ids_batch| - migrate_in(index * DELAY_INTERVAL, MIGRATION, [ids_batch.first, ids_batch.last]) - - index += 1 - end - end - end - - def down - # no-op - end - - private - - def split_in_consecutive_batches(relation) - ids = relation.pluck(:id) - - (ids.first..ids.last).to_a.split {|i| !ids.include?(i) }.select(&:present?) - end -end diff --git a/db/post_migrate/20200608075553_add_index_on_user_id_and_created_at_and_source_to_ci_pipelines.rb b/db/post_migrate/20200608075553_add_index_on_user_id_and_created_at_and_source_to_ci_pipelines.rb deleted file mode 100644 index 5df9cacdff6..00000000000 --- a/db/post_migrate/20200608075553_add_index_on_user_id_and_created_at_and_source_to_ci_pipelines.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnUserIdAndCreatedAtAndSourceToCiPipelines < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_pipelines, [:user_id, :created_at, :source] - remove_concurrent_index :ci_pipelines, [:user_id, :created_at] - end - - def down - add_concurrent_index :ci_pipelines, [:user_id, :created_at] - remove_concurrent_index :ci_pipelines, [:user_id, :created_at, :source] - end -end diff --git a/db/post_migrate/20200608195222_set_lock_version_not_null_constraint.rb b/db/post_migrate/20200608195222_set_lock_version_not_null_constraint.rb deleted file mode 100644 index ec72053b307..00000000000 --- a/db/post_migrate/20200608195222_set_lock_version_not_null_constraint.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class SetLockVersionNotNullConstraint < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - TABLES = %i(epics merge_requests issues ci_stages ci_builds ci_pipelines).freeze - - def up - TABLES.each do |table| - add_not_null_constraint table, :lock_version, validate: false - end - end - - def down - TABLES.each do |table| - remove_not_null_constraint table, :lock_version - end - end -end diff --git a/db/post_migrate/20200608203426_set_proper_lock_version_indices.rb b/db/post_migrate/20200608203426_set_proper_lock_version_indices.rb deleted file mode 100644 index 924ca73e6cc..00000000000 --- a/db/post_migrate/20200608203426_set_proper_lock_version_indices.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class SetProperLockVersionIndices < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index :epics, :lock_version, where: "lock_version IS NULL" - remove_concurrent_index :merge_requests, :lock_version, where: "lock_version IS NULL" - remove_concurrent_index :issues, :lock_version, where: "lock_version IS NULL" - - add_concurrent_index :epics, :id, where: "lock_version IS NULL", name: 'index_epics_on_id' - add_concurrent_index :merge_requests, :id, where: "lock_version IS NULL", name: 'index_merge_requests_on_id' - add_concurrent_index :issues, :id, where: "lock_version IS NULL", name: 'index_issues_on_id' - end - - def down - add_concurrent_index :epics, :lock_version, where: "lock_version IS NULL" - add_concurrent_index :merge_requests, :lock_version, where: "lock_version IS NULL" - add_concurrent_index :issues, :lock_version, where: "lock_version IS NULL" - - remove_concurrent_index_by_name :epics, name: 'index_epics_on_id' - remove_concurrent_index_by_name :merge_requests, name: 'index_merge_requests_on_id' - remove_concurrent_index_by_name :issues, name: 'index_issues_on_id' - end -end diff --git a/db/post_migrate/20200608205813_set_lock_version_to_not_null.rb b/db/post_migrate/20200608205813_set_lock_version_to_not_null.rb deleted file mode 100644 index 69f43a8decf..00000000000 --- a/db/post_migrate/20200608205813_set_lock_version_to_not_null.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class SetLockVersionToNotNull < ActiveRecord::Migration[6.0] - DOWNTIME = false - - TABLES = %w(epics merge_requests issues ci_stages ci_builds ci_pipelines).freeze - BATCH_SIZE = 10_000 - - disable_ddl_transaction! - - def declare_class(table) - Class.new(ActiveRecord::Base) do - include EachBatch - - self.table_name = table - self.inheritance_column = :_type_disabled # Disable STI - end - end - - def up - TABLES.each do |table| - declare_class(table).where(lock_version: nil).each_batch(of: BATCH_SIZE) do |batch| - batch.update_all(lock_version: 0) - end - end - end - - def down - # Nothing to do... - end -end diff --git a/db/post_migrate/20200608212030_lock_version_cleanup_for_epics.rb b/db/post_migrate/20200608212030_lock_version_cleanup_for_epics.rb deleted file mode 100644 index aafa6a83200..00000000000 --- a/db/post_migrate/20200608212030_lock_version_cleanup_for_epics.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class LockVersionCleanupForEpics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :epics, :lock_version - remove_concurrent_index_by_name :epics, name: 'index_epics_on_id' - end - - def down - add_concurrent_index :epics, :id, where: "lock_version IS NULL", name: 'index_epics_on_id' - end -end diff --git a/db/post_migrate/20200608212435_lock_version_cleanup_for_merge_requests.rb b/db/post_migrate/20200608212435_lock_version_cleanup_for_merge_requests.rb deleted file mode 100644 index cb8ab86b6a3..00000000000 --- a/db/post_migrate/20200608212435_lock_version_cleanup_for_merge_requests.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class LockVersionCleanupForMergeRequests < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :merge_requests, :lock_version - remove_concurrent_index_by_name :merge_requests, name: 'index_merge_requests_on_id' - end - - def down - add_concurrent_index :merge_requests, :id, where: "lock_version IS NULL", name: 'index_merge_requests_on_id' - end -end diff --git a/db/post_migrate/20200608212549_lock_version_cleanup_for_issues.rb b/db/post_migrate/20200608212549_lock_version_cleanup_for_issues.rb deleted file mode 100644 index ad3fea8b131..00000000000 --- a/db/post_migrate/20200608212549_lock_version_cleanup_for_issues.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class LockVersionCleanupForIssues < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :issues, :lock_version - remove_concurrent_index_by_name :issues, name: 'index_issues_on_id' - end - - def down - add_concurrent_index :issues, :id, where: "lock_version IS NULL", name: 'index_issues_on_id' - end -end diff --git a/db/post_migrate/20200608212652_lock_version_cleanup_for_ci_stages.rb b/db/post_migrate/20200608212652_lock_version_cleanup_for_ci_stages.rb deleted file mode 100644 index 12e2897123e..00000000000 --- a/db/post_migrate/20200608212652_lock_version_cleanup_for_ci_stages.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class LockVersionCleanupForCiStages < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :ci_stages, :lock_version - remove_concurrent_index :ci_stages, :id, where: "lock_version IS NULL", name: "tmp_index_ci_stages_lock_version" - end - - def down - add_concurrent_index :ci_stages, :id, where: "lock_version IS NULL", name: "tmp_index_ci_stages_lock_version" - end -end diff --git a/db/post_migrate/20200608212807_lock_version_cleanup_for_ci_builds.rb b/db/post_migrate/20200608212807_lock_version_cleanup_for_ci_builds.rb deleted file mode 100644 index 0512869971b..00000000000 --- a/db/post_migrate/20200608212807_lock_version_cleanup_for_ci_builds.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class LockVersionCleanupForCiBuilds < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :ci_builds, :lock_version - remove_concurrent_index :ci_builds, :id, where: "lock_version IS NULL", name: "tmp_index_ci_builds_lock_version" - end - - def down - add_concurrent_index :ci_builds, :id, where: "lock_version IS NULL", name: "tmp_index_ci_builds_lock_version" - end -end diff --git a/db/post_migrate/20200608212824_lock_version_cleanup_for_ci_pipelines.rb b/db/post_migrate/20200608212824_lock_version_cleanup_for_ci_pipelines.rb deleted file mode 100644 index 228dd72da8d..00000000000 --- a/db/post_migrate/20200608212824_lock_version_cleanup_for_ci_pipelines.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class LockVersionCleanupForCiPipelines < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :ci_pipelines, :lock_version - remove_concurrent_index :ci_pipelines, :id, where: "lock_version IS NULL", name: "tmp_index_ci_pipelines_lock_version" - end - - def down - add_concurrent_index :ci_pipelines, :id, where: "lock_version IS NULL", name: "tmp_index_ci_pipelines_lock_version" - end -end diff --git a/db/post_migrate/20200609002841_add_partial_index_on_locked_state_id_to_merge_requests.rb b/db/post_migrate/20200609002841_add_partial_index_on_locked_state_id_to_merge_requests.rb deleted file mode 100644 index 7602ad00796..00000000000 --- a/db/post_migrate/20200609002841_add_partial_index_on_locked_state_id_to_merge_requests.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class AddPartialIndexOnLockedStateIdToMergeRequests < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = "idx_merge_requests_on_target_project_id_and_locked_state" - LOCKED_STATE_ID = 4 - - disable_ddl_transaction! - - def up - add_concurrent_index :merge_requests, :target_project_id, where: "(state_id = #{LOCKED_STATE_ID})", name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :merge_requests, INDEX_NAME - end -end diff --git a/db/post_migrate/20200615111857_unconfirm_wrongfully_verified_emails.rb b/db/post_migrate/20200615111857_unconfirm_wrongfully_verified_emails.rb deleted file mode 100644 index 62fdfc783bc..00000000000 --- a/db/post_migrate/20200615111857_unconfirm_wrongfully_verified_emails.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -class UnconfirmWrongfullyVerifiedEmails < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - INTERVAL = 5.minutes.to_i - BATCH_SIZE = 500 - MIGRATION = 'WrongfullyConfirmedEmailUnconfirmer' - EMAIL_INDEX_NAME = 'tmp_index_for_email_unconfirmation_migration' - - class ApplicationSetting < ActiveRecord::Base - self.table_name = 'application_settings' - end - - class Email < ActiveRecord::Base - include EachBatch - end - - def up - add_concurrent_index :emails, :id, where: 'confirmed_at IS NOT NULL', name: EMAIL_INDEX_NAME - - ApplicationSetting.reset_column_information - - setting_record = ApplicationSetting.last - return unless setting_record&.send_user_confirmation_email - - queue_background_migration_jobs_by_range_at_intervals(Email, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - remove_concurrent_index_by_name(:emails, EMAIL_INDEX_NAME) - end -end diff --git a/db/post_migrate/20200617001637_validate_file_store_not_null_constraint_on_lfs_objects.rb b/db/post_migrate/20200617001637_validate_file_store_not_null_constraint_on_lfs_objects.rb deleted file mode 100644 index 27a30b1d696..00000000000 --- a/db/post_migrate/20200617001637_validate_file_store_not_null_constraint_on_lfs_objects.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class ValidateFileStoreNotNullConstraintOnLfsObjects < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_check_constraint(:lfs_objects, :check_eecfc5717d) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200617001848_validate_store_not_null_constraint_uploads.rb b/db/post_migrate/20200617001848_validate_store_not_null_constraint_uploads.rb deleted file mode 100644 index 83cb6cb3e85..00000000000 --- a/db/post_migrate/20200617001848_validate_store_not_null_constraint_uploads.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class ValidateStoreNotNullConstraintUploads < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_check_constraint(:uploads, :check_5e9547379c) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200617002030_validate_file_store_not_null_constraint_on_ci_job_artifacts.rb b/db/post_migrate/20200617002030_validate_file_store_not_null_constraint_on_ci_job_artifacts.rb deleted file mode 100644 index 8e766a508b7..00000000000 --- a/db/post_migrate/20200617002030_validate_file_store_not_null_constraint_on_ci_job_artifacts.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class ValidateFileStoreNotNullConstraintOnCiJobArtifacts < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_check_constraint(:ci_job_artifacts, :check_27f0f6dbab) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200618152212_update_secure_smau_index.rb b/db/post_migrate/20200618152212_update_secure_smau_index.rb deleted file mode 100644 index ba989c279be..00000000000 --- a/db/post_migrate/20200618152212_update_secure_smau_index.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class UpdateSecureSmauIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_secure_ci_builds_on_user_id_created_at' - - disable_ddl_transaction! - - def up - add_concurrent_index( - :ci_builds, - [:user_id, :created_at], - where: "(((type)::text = 'Ci::Build'::text) AND ((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, ('dast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('license_management'::character varying)::text, ('license_scanning'::character varying)::text, ('sast'::character varying)::text, ('secret_detection'::character varying)::text])))", - name: INDEX_NAME - ) - end - - def down - remove_concurrent_index_by_name :ci_builds, INDEX_NAME - end -end diff --git a/db/post_migrate/20200623142159_remove_gitlab_issue_tracker_service_records.rb b/db/post_migrate/20200623142159_remove_gitlab_issue_tracker_service_records.rb deleted file mode 100644 index 743499e7b76..00000000000 --- a/db/post_migrate/20200623142159_remove_gitlab_issue_tracker_service_records.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class RemoveGitlabIssueTrackerServiceRecords < ActiveRecord::Migration[6.0] - DOWNTIME = false - BATCH_SIZE = 5000 - - disable_ddl_transaction! - - class Service < ActiveRecord::Base - include EachBatch - - self.table_name = 'services' - - def self.gitlab_issue_tracker_service - where(type: 'GitlabIssueTrackerService') - end - end - - def up - Service.each_batch(of: BATCH_SIZE) do |services| - services.gitlab_issue_tracker_service.delete_all - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200626060151_add_disable_overriding_approvers_per_merge_request_indices.rb b/db/post_migrate/20200626060151_add_disable_overriding_approvers_per_merge_request_indices.rb deleted file mode 100644 index 6f2db4035e2..00000000000 --- a/db/post_migrate/20200626060151_add_disable_overriding_approvers_per_merge_request_indices.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class AddDisableOverridingApproversPerMergeRequestIndices < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DISABLE_OVERRIDING_APPROVERS_TRUE_INDEX_NAME = "idx_projects_id_created_at_disable_overriding_approvers_true" - DISABLE_OVERRIDING_APPROVERS_FALSE_INDEX_NAME = "idx_projects_id_created_at_disable_overriding_approvers_false" - - disable_ddl_transaction! - - def up - add_concurrent_index :projects, [:id, :created_at], - where: "disable_overriding_approvers_per_merge_request = TRUE", - name: DISABLE_OVERRIDING_APPROVERS_TRUE_INDEX_NAME - - add_concurrent_index :projects, [:id, :created_at], - where: "(disable_overriding_approvers_per_merge_request = FALSE) OR (disable_overriding_approvers_per_merge_request IS NULL)", - name: DISABLE_OVERRIDING_APPROVERS_FALSE_INDEX_NAME - end - - def down - remove_concurrent_index_by_name :projects, DISABLE_OVERRIDING_APPROVERS_TRUE_INDEX_NAME - remove_concurrent_index_by_name :projects, DISABLE_OVERRIDING_APPROVERS_FALSE_INDEX_NAME - end -end diff --git a/db/post_migrate/20200701070435_add_default_value_stream_to_groups_with_group_stages.rb b/db/post_migrate/20200701070435_add_default_value_stream_to_groups_with_group_stages.rb deleted file mode 100644 index 971eb3c489f..00000000000 --- a/db/post_migrate/20200701070435_add_default_value_stream_to_groups_with_group_stages.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -class AddDefaultValueStreamToGroupsWithGroupStages < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Group < ActiveRecord::Base - def self.find_sti_class(typename) - if typename == 'Group' - Group - else - super - end - end - self.table_name = 'namespaces' - has_many :group_value_streams - has_many :group_stages - end - - class GroupValueStream < ActiveRecord::Base - self.table_name = 'analytics_cycle_analytics_group_value_streams' - has_many :group_stages - belongs_to :group - end - - class GroupStage < ActiveRecord::Base - self.table_name = 'analytics_cycle_analytics_group_stages' - belongs_to :group_value_stream - end - - def up - Group.where(type: 'Group').joins(:group_stages).distinct.find_each do |group| - Group.transaction do - group_value_stream = group.group_value_streams.first_or_create!(name: 'default') - group.group_stages.update_all(group_value_stream_id: group_value_stream.id) - end - end - - change_column_null :analytics_cycle_analytics_group_stages, :group_value_stream_id, false - end - - def down - change_column_null :analytics_cycle_analytics_group_stages, :group_value_stream_id, true - - GroupValueStream.where(name: 'default').includes(:group_stages).find_each do |value_stream| - GroupValueStream.transaction do - value_stream.group_stages.update_all(group_value_stream_id: nil) - value_stream.destroy! - end - end - end -end diff --git a/db/post_migrate/20200701091253_validate_foreign_key_on_cycle_analytics_group_stages.rb b/db/post_migrate/20200701091253_validate_foreign_key_on_cycle_analytics_group_stages.rb deleted file mode 100644 index 0a8926ed6de..00000000000 --- a/db/post_migrate/20200701091253_validate_foreign_key_on_cycle_analytics_group_stages.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class ValidateForeignKeyOnCycleAnalyticsGroupStages < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - # same as in db/migrate/20200701064756_add_not_valid_foreign_key_to_cycle_analytics_group_stages.rb - CONSTRAINT_NAME = 'fk_analytics_cycle_analytics_group_stages_group_value_stream_id' - - def up - validate_foreign_key :analytics_cycle_analytics_group_stages, :group_value_stream_id, name: CONSTRAINT_NAME - end - - def down - remove_foreign_key_if_exists :analytics_cycle_analytics_group_stages, column: :group_value_stream_id, name: CONSTRAINT_NAME - add_foreign_key :analytics_cycle_analytics_group_stages, :analytics_cycle_analytics_group_value_streams, - column: :group_value_stream_id, name: CONSTRAINT_NAME, on_delete: :cascade, validate: false - end -end diff --git a/db/post_migrate/20200703064117_generate_missing_routes_for_bots.rb b/db/post_migrate/20200703064117_generate_missing_routes_for_bots.rb deleted file mode 100644 index 1d3f57d3fe6..00000000000 --- a/db/post_migrate/20200703064117_generate_missing_routes_for_bots.rb +++ /dev/null @@ -1,92 +0,0 @@ -# frozen_string_literal: true - -class GenerateMissingRoutesForBots < ActiveRecord::Migration[6.0] - DOWNTIME = false - - disable_ddl_transaction! - - class User < ActiveRecord::Base - self.table_name = 'users' - - USER_TYPES = { - human: nil, - support_bot: 1, - alert_bot: 2, - visual_review_bot: 3, - service_user: 4, - ghost: 5, - project_bot: 6, - migration_bot: 7 - }.with_indifferent_access.freeze - - BOT_USER_TYPES = %w[alert_bot project_bot support_bot visual_review_bot migration_bot].freeze - - scope :bots, -> { where(user_type: USER_TYPES.values_at(*BOT_USER_TYPES)) } - end - - class Route < ActiveRecord::Base - self.table_name = 'routes' - - validates :path, - uniqueness: { case_sensitive: false } - end - - class Namespace < ActiveRecord::Base - self.table_name = 'namespaces' - - belongs_to :owner, class_name: 'GenerateMissingRoutesForBots::User' - - scope :for_user, -> { where(type: nil) } - scope :for_bots, -> { for_user.joins(:owner).merge(GenerateMissingRoutesForBots::User.bots) } - - scope :without_routes, -> do - where( - 'NOT EXISTS ( - SELECT 1 - FROM routes - WHERE source_type = ? - AND source_id = namespaces.id - )', - self.source_type_for_route - ) - end - - def self.source_type_for_route - 'Namespace' - end - - def attributes_for_insert - { - source_type: self.class.source_type_for_route, - source_id: id, - name: name, - path: path - } - end - end - - def up - # Reset the column information of all the models that update the database - # to ensure the Active Record's knowledge of the table structure is current - Route.reset_column_information - - logger = Gitlab::BackgroundMigration::Logger.build - attributes_to_be_logged = %w(id path name) - - GenerateMissingRoutesForBots::Namespace.for_bots.without_routes.each do |namespace| - route = GenerateMissingRoutesForBots::Route.create(namespace.attributes_for_insert) - namespace_details = namespace.as_json.slice(*attributes_to_be_logged) - - if route.persisted? - logger.info namespace_details.merge(message: 'a new route was created for the namespace') - else - errors = route.errors.full_messages.join(',') - logger.info namespace_details.merge(message: 'route creation failed for the namespace', errors: errors) - end - end - end - - def down - # no op - end -end diff --git a/db/post_migrate/20200703125016_backfill_namespace_settings.rb b/db/post_migrate/20200703125016_backfill_namespace_settings.rb deleted file mode 100644 index a7335e2d2b8..00000000000 --- a/db/post_migrate/20200703125016_backfill_namespace_settings.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class BackfillNamespaceSettings < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'BackfillNamespaceSettings' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 10_000 - - disable_ddl_transaction! - - class Namespace < ActiveRecord::Base - include EachBatch - - self.table_name = 'namespaces' - end - - def up - say "Scheduling `#{MIGRATION}` jobs" - - queue_background_migration_jobs_by_range_at_intervals(Namespace, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end - - def down - # NOOP - end -end diff --git a/db/post_migrate/20200703165434_drop_temporary_table_untracked_files_for_uploads_if_exists.rb b/db/post_migrate/20200703165434_drop_temporary_table_untracked_files_for_uploads_if_exists.rb deleted file mode 100644 index 1f34a05227d..00000000000 --- a/db/post_migrate/20200703165434_drop_temporary_table_untracked_files_for_uploads_if_exists.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class DropTemporaryTableUntrackedFilesForUploadsIfExists < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute 'DROP TABLE IF EXISTS untracked_files_for_uploads' - end - - def down - # no-op - this table should not exist - end -end diff --git a/db/post_migrate/20200704143633_add_index_on_user_id_and_created_at_where_source_to_ci_pipelines.rb b/db/post_migrate/20200704143633_add_index_on_user_id_and_created_at_where_source_to_ci_pipelines.rb deleted file mode 100644 index d84b2b4cad3..00000000000 --- a/db/post_migrate/20200704143633_add_index_on_user_id_and_created_at_where_source_to_ci_pipelines.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnUserIdAndCreatedAtWhereSourceToCiPipelines < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_pipelines, [:user_id, :created_at, :config_source] - end - - def down - remove_concurrent_index :ci_pipelines, [:user_id, :created_at, :config_source] - end -end diff --git a/db/post_migrate/20200704161600_add_index_on_id_and_status_and_created_at_to_deployments.rb b/db/post_migrate/20200704161600_add_index_on_id_and_status_and_created_at_to_deployments.rb deleted file mode 100644 index 3aab2fd2949..00000000000 --- a/db/post_migrate/20200704161600_add_index_on_id_and_status_and_created_at_to_deployments.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnIdAndStatusAndCreatedAtToDeployments < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :deployments, [:id, :status, :created_at] - remove_concurrent_index :deployments, [:id, :status] - end - - def down - add_concurrent_index :deployments, [:id, :status] - remove_concurrent_index :deployments, [:id, :status, :created_at] - end -end diff --git a/db/post_migrate/20200706154619_drop_ci_daily_report_results_table.rb b/db/post_migrate/20200706154619_drop_ci_daily_report_results_table.rb deleted file mode 100644 index c6ce52012d6..00000000000 --- a/db/post_migrate/20200706154619_drop_ci_daily_report_results_table.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class DropCiDailyReportResultsTable < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - drop_table :ci_daily_report_results - end - - def down - create_table :ci_daily_report_results do |t| - t.date :date, null: false - t.bigint :project_id, null: false - t.bigint :last_pipeline_id, null: false - t.float :value, null: false - t.integer :param_type, limit: 8, null: false - t.string :ref_path, null: false - t.string :title, null: false - - t.index :last_pipeline_id - t.index [:project_id, :ref_path, :param_type, :date, :title], name: 'index_daily_report_results_unique_columns', unique: true - end - end -end diff --git a/db/post_migrate/20200709101408_schedule_populate_project_snippet_statistics.rb b/db/post_migrate/20200709101408_schedule_populate_project_snippet_statistics.rb deleted file mode 100644 index 28527e67f4a..00000000000 --- a/db/post_migrate/20200709101408_schedule_populate_project_snippet_statistics.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateProjectSnippetStatistics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY_INTERVAL = 2.minutes.to_i - BATCH_SIZE = 500 - MIGRATION = 'PopulateProjectSnippetStatistics' - - disable_ddl_transaction! - - def up - snippets = exec_query <<~SQL - SELECT snippets.id - FROM snippets - INNER JOIN projects ON projects.id = snippets.project_id - WHERE snippets.type = 'ProjectSnippet' - ORDER BY projects.namespace_id ASC, snippets.project_id ASC, snippets.id ASC - SQL - - snippets.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |snippet_ids, index| - migrate_in(index * DELAY_INTERVAL, MIGRATION, [snippet_ids]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200710102418_delete_user_callout_alerts_moved.rb b/db/post_migrate/20200710102418_delete_user_callout_alerts_moved.rb deleted file mode 100644 index ac605ba494e..00000000000 --- a/db/post_migrate/20200710102418_delete_user_callout_alerts_moved.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class DeleteUserCalloutAlertsMoved < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - class UserCallout < ActiveRecord::Base - include EachBatch - - self.table_name = 'user_callouts' - end - - BATCH_SIZE = 1_000 - - # Inlined from Enums::UserCallout.feature_names - FEATURE_NAME_ALERTS_MOVED = 20 - - def up - UserCallout.each_batch(of: BATCH_SIZE, column: :user_id) do |callout| - callout.where(feature_name: FEATURE_NAME_ALERTS_MOVED).delete_all - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200710102846_drop_index_ruby_objects_in_details_on_audit_events.rb b/db/post_migrate/20200710102846_drop_index_ruby_objects_in_details_on_audit_events.rb deleted file mode 100644 index 6869938466a..00000000000 --- a/db/post_migrate/20200710102846_drop_index_ruby_objects_in_details_on_audit_events.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class DropIndexRubyObjectsInDetailsOnAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_audit_events_on_ruby_object_in_details' - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name(:audit_events, INDEX_NAME) - end - - def down - add_concurrent_index(:audit_events, :id, where: "details ~~ '%ruby/object%'", name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20200713071042_confirm_project_bot_users.rb b/db/post_migrate/20200713071042_confirm_project_bot_users.rb deleted file mode 100644 index 0578fc42ef2..00000000000 --- a/db/post_migrate/20200713071042_confirm_project_bot_users.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class ConfirmProjectBotUsers < ActiveRecord::Migration[6.0] - DOWNTIME = false - - disable_ddl_transaction! - - class User < ApplicationRecord - self.table_name = 'users' - - include ::EachBatch - - USER_TYPE_PROJECT_BOT = 6 - - scope :project_bots, -> { where(user_type: USER_TYPE_PROJECT_BOT) } - scope :unconfirmed, -> { where(confirmed_at: nil) } - end - - def up - User.reset_column_information - - User.project_bots.unconfirmed.each_batch do |relation| - relation.update_all('confirmed_at = created_at') - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200714075739_schedule_populate_personal_snippet_statistics.rb b/db/post_migrate/20200714075739_schedule_populate_personal_snippet_statistics.rb deleted file mode 100644 index c3033da24fe..00000000000 --- a/db/post_migrate/20200714075739_schedule_populate_personal_snippet_statistics.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulatePersonalSnippetStatistics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY_INTERVAL = 2.minutes.to_i - BATCH_SIZE = 500 - MIGRATION = 'PopulatePersonalSnippetStatistics' - - disable_ddl_transaction! - - def up - snippets = exec_query <<~SQL - SELECT id - FROM snippets - WHERE type = 'PersonalSnippet' - ORDER BY author_id ASC, id ASC - SQL - - snippets.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |snippet_ids, index| - migrate_in(index * DELAY_INTERVAL, MIGRATION, [snippet_ids]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200716234259_remove_duplicate_labels_from_group.rb b/db/post_migrate/20200716234259_remove_duplicate_labels_from_group.rb deleted file mode 100644 index 114276df875..00000000000 --- a/db/post_migrate/20200716234259_remove_duplicate_labels_from_group.rb +++ /dev/null @@ -1,135 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicateLabelsFromGroup < ActiveRecord::Migration[6.0] - DOWNTIME = false - - CREATE = 1 - RENAME = 2 - - disable_ddl_transaction! - - class BackupLabel < ApplicationRecord - include EachBatch - - self.table_name = 'backup_labels' - end - - class Label < ApplicationRecord - self.table_name = 'labels' - end - - class Group < ApplicationRecord - include EachBatch - - self.table_name = 'namespaces' - end - - BATCH_SIZE = 10_000 - - def up - # Split to smaller chunks - # Loop rather than background job, every 10,000 - # there are ~1,800,000 groups in total (excluding personal namespaces, which can't have labels) - Group.where(type: 'Group').each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - transaction do - remove_full_duplicates(*range) - end - - transaction do - rename_partial_duplicates(*range) - end - end - end - - DOWN_BATCH_SIZE = 1000 - - def down - BackupLabel.where('project_id IS NULL AND group_id IS NOT NULL').each_batch(of: DOWN_BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - restore_renamed_labels(*range) - restore_deleted_labels(*range) - end - end - - def remove_full_duplicates(start_id, stop_id) - # Fields that are considered duplicate: - # group_id title template description type color - - duplicate_labels = ApplicationRecord.connection.execute(<<-SQL.squish) -WITH data AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT labels.*, - row_number() OVER (PARTITION BY labels.group_id, labels.title, labels.template, labels.description, labels.type, labels.color ORDER BY labels.id) AS row_number, - #{CREATE} AS restore_action - FROM labels - WHERE labels.group_id BETWEEN #{start_id} AND #{stop_id} - AND NOT EXISTS (SELECT * FROM board_labels WHERE board_labels.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM label_links WHERE label_links.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM label_priorities WHERE label_priorities.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM lists WHERE lists.label_id = labels.id) - AND NOT EXISTS (SELECT * FROM resource_label_events WHERE resource_label_events.label_id = labels.id) -) SELECT * FROM data WHERE row_number > 1; - SQL - - if duplicate_labels.any? - # create backup records - BackupLabel.insert_all!(duplicate_labels.map { |label| label.except("row_number") }) - - Label.unscoped.where(id: duplicate_labels.pluck("id")).delete_all - end - end - - def rename_partial_duplicates(start_id, stop_id) - # We need to ensure that the new title (with `_duplicate#{ID}`) doesn't exceed the limit. - # Truncate the original title (if needed) to 245 characters minus the length of the ID - # then add `_duplicate#{ID}` - - soft_duplicates = ApplicationRecord.connection.execute(<<-SQL.squish) -WITH data AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT - *, - substring(title from 1 for 245 - length(id::text)) || '_duplicate' || id::text as new_title, - #{RENAME} AS restore_action, - row_number() OVER (PARTITION BY group_id, title ORDER BY id) AS row_number - FROM labels - WHERE group_id BETWEEN #{start_id} AND #{stop_id} -) SELECT * FROM data WHERE row_number > 1; - SQL - - if soft_duplicates.any? - # create backup records - BackupLabel.insert_all!(soft_duplicates.map { |label| label.except("row_number") }) - - ApplicationRecord.connection.execute(<<-SQL.squish) -UPDATE labels SET title = substring(title from 1 for 245 - length(id::text)) || '_duplicate' || id::text -WHERE labels.id IN (#{soft_duplicates.map { |dup| dup["id"] }.join(", ")}); - SQL - end - end - - def restore_renamed_labels(start_id, stop_id) - # the backup label IDs are not incremental, they are copied directly from the Labels table - ApplicationRecord.connection.execute(<<-SQL.squish) -WITH backups AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT id, title - FROM backup_labels - WHERE id BETWEEN #{start_id} AND #{stop_id} - AND restore_action = #{RENAME} -) UPDATE labels SET title = backups.title -FROM backups -WHERE labels.id = backups.id; - SQL - end - - def restore_deleted_labels(start_id, stop_id) - ActiveRecord::Base.connection.execute(<<-SQL.squish) -INSERT INTO labels -SELECT id, title, color, group_id, created_at, updated_at, template, description, description_html, type, cached_markdown_version FROM backup_labels - WHERE backup_labels.id BETWEEN #{start_id} AND #{stop_id} - AND backup_labels.project_id IS NULL AND backup_labels.group_id IS NOT NULL - AND backup_labels.restore_action = #{CREATE} - SQL - end -end diff --git a/db/post_migrate/20200716234518_add_uniqueness_index_to_label_title_and_group.rb b/db/post_migrate/20200716234518_add_uniqueness_index_to_label_title_and_group.rb deleted file mode 100644 index 08bab811c00..00000000000 --- a/db/post_migrate/20200716234518_add_uniqueness_index_to_label_title_and_group.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class AddUniquenessIndexToLabelTitleAndGroup < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - GROUP_AND_TITLE = [:group_id, :title] - - def up - add_concurrent_index :labels, GROUP_AND_TITLE, where: "labels.project_id IS NULL", unique: true, name: "index_labels_on_group_id_and_title_unique" - remove_concurrent_index :labels, GROUP_AND_TITLE, name: "index_labels_on_group_id_and_title" - end - - def down - add_concurrent_index :labels, GROUP_AND_TITLE, where: "labels.project_id IS NULL", unique: false, name: "index_labels_on_group_id_and_title" - remove_concurrent_index :labels, GROUP_AND_TITLE, name: "index_labels_on_group_id_and_title_unique" - end -end diff --git a/db/post_migrate/20200721140507_update_index_for_coverage_fuzzing_telemetry.rb b/db/post_migrate/20200721140507_update_index_for_coverage_fuzzing_telemetry.rb deleted file mode 100644 index 4f884319125..00000000000 --- a/db/post_migrate/20200721140507_update_index_for_coverage_fuzzing_telemetry.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -class UpdateIndexForCoverageFuzzingTelemetry < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - OLD_INDEX_NAME = 'index_security_ci_builds_on_name_and_id' - NEW_INDEX_NAME = 'index_security_ci_builds_on_name_and_id_parser_features' - - OLD_CLAUSE = "((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, - ('dast'::character varying)::text, - ('dependency_scanning'::character varying)::text, - ('license_management'::character varying)::text, - ('sast'::character varying)::text, - ('secret_detection'::character varying)::text, - ('license_scanning'::character varying)::text])) AND ((type)::text = 'Ci::Build'::text)" - - NEW_CLAUSE = "((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, - ('dast'::character varying)::text, - ('dependency_scanning'::character varying)::text, - ('license_management'::character varying)::text, - ('sast'::character varying)::text, - ('secret_detection'::character varying)::text, - ('coverage_fuzzing'::character varying)::text, - ('license_scanning'::character varying)::text])) AND ((type)::text = 'Ci::Build'::text)" - - def up - add_concurrent_index :ci_builds, [:name, :id], name: NEW_INDEX_NAME, where: NEW_CLAUSE - remove_concurrent_index_by_name :ci_builds, OLD_INDEX_NAME - end - - def down - add_concurrent_index :ci_builds, [:name, :id], name: OLD_INDEX_NAME, where: OLD_CLAUSE - remove_concurrent_index_by_name :ci_builds, NEW_INDEX_NAME - end -end diff --git a/db/post_migrate/20200722202318_backfill_partitioned_audit_events.rb b/db/post_migrate/20200722202318_backfill_partitioned_audit_events.rb deleted file mode 100644 index 538aa94e22b..00000000000 --- a/db/post_migrate/20200722202318_backfill_partitioned_audit_events.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class BackfillPartitionedAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::PartitioningMigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - return if ::Gitlab.com? - - enqueue_partitioning_data_migration :audit_events - end - - def down - return if ::Gitlab.com? - - cleanup_partitioning_data_migration :audit_events - end -end diff --git a/db/post_migrate/20200723040950_migrate_incident_issues_to_incident_type.rb b/db/post_migrate/20200723040950_migrate_incident_issues_to_incident_type.rb deleted file mode 100644 index 0f562630381..00000000000 --- a/db/post_migrate/20200723040950_migrate_incident_issues_to_incident_type.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -class MigrateIncidentIssuesToIncidentType < ActiveRecord::Migration[6.0] - DOWNTIME = false - BATCH_SIZE = 100 - - disable_ddl_transaction! - - LABEL_PROPERTIES = { - title: 'incident' - }.freeze - - class Issue < ActiveRecord::Base - include EachBatch - - self.table_name = 'issues' - - scope :incident_labelled, -> do - joins("INNER JOIN label_links ON label_links.target_type = 'Issue' AND label_links.target_id = issues.id") - .joins("INNER JOIN labels ON labels.id = label_links.label_id") - .where(labels: LABEL_PROPERTIES) - end - - enum issue_type: { - issue: 0, - incident: 1 - } - - scope :incident_typed, -> { where(issue_type: :incident) } - end - - def up - incident_issues = Issue.incident_labelled - - incident_issues.each_batch(of: BATCH_SIZE) do |batch| - batch.update_all(issue_type: :incident) - end - end - - def down - incident_issues = Issue.incident_typed - - incident_issues.each_batch(of: BATCH_SIZE) do |batch| - batch.update_all(issue_type: :issue) - end - end -end diff --git a/db/post_migrate/20200723132258_schedule_copy_of_mr_target_project_id_to_mr_metrics.rb b/db/post_migrate/20200723132258_schedule_copy_of_mr_target_project_id_to_mr_metrics.rb deleted file mode 100644 index bca703121bc..00000000000 --- a/db/post_migrate/20200723132258_schedule_copy_of_mr_target_project_id_to_mr_metrics.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class ScheduleCopyOfMrTargetProjectIdToMrMetrics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 2.minutes.to_i - BATCH_SIZE = 5_000 - MIGRATION = 'CopyMergeRequestTargetProjectToMergeRequestMetrics' - - disable_ddl_transaction! - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - end - - def up - MergeRequest.reset_column_information - - queue_background_migration_jobs_by_range_at_intervals( - MergeRequest, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE - ) - end - - def down - # noop - end -end diff --git a/db/post_migrate/20200724100421_remove_updated_at_from_audit_events.rb b/db/post_migrate/20200724100421_remove_updated_at_from_audit_events.rb deleted file mode 100644 index 0dc02491db5..00000000000 --- a/db/post_migrate/20200724100421_remove_updated_at_from_audit_events.rb +++ /dev/null @@ -1,119 +0,0 @@ -# frozen_string_literal: true - -class RemoveUpdatedAtFromAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::SchemaHelpers - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - SOURCE_TABLE_NAME = 'audit_events' - PARTITIONED_TABLE_NAME = 'audit_events_part_5fc467ac26' - TRIGGER_FUNCTION_NAME = 'table_sync_function_2be879775d' - - def up - with_lock_retries do - remove_column SOURCE_TABLE_NAME, :updated_at - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - type = NEW.type, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - type, - entity_id, - entity_type, - details, - ip_address, - author_name, - entity_path, - target_details, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.type, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - - remove_column PARTITIONED_TABLE_NAME, :updated_at - end - end - - def down - with_lock_retries do - add_column SOURCE_TABLE_NAME, :updated_at, :datetime # rubocop:disable Migration/Datetime - add_column PARTITIONED_TABLE_NAME, :updated_at, :datetime # rubocop:disable Migration/Datetime - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - type = NEW.type, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - updated_at = NEW.updated_at, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - type, - entity_id, - entity_type, - details, - updated_at, - ip_address, - author_name, - entity_path, - target_details, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.type, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.updated_at, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - end - end -end diff --git a/db/post_migrate/20200724130639_backfill_designs_relative_position.rb b/db/post_migrate/20200724130639_backfill_designs_relative_position.rb deleted file mode 100644 index ef8b38bf90c..00000000000 --- a/db/post_migrate/20200724130639_backfill_designs_relative_position.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -# This migration is not needed anymore and was disabled, because we're now -# also backfilling design positions immediately before moving a design. -# -# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39555 -class BackfillDesignsRelativePosition < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - # no-op - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200727100631_remove_again_gitlab_issue_tracker_service_records.rb b/db/post_migrate/20200727100631_remove_again_gitlab_issue_tracker_service_records.rb deleted file mode 100644 index b61da82aef8..00000000000 --- a/db/post_migrate/20200727100631_remove_again_gitlab_issue_tracker_service_records.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class RemoveAgainGitlabIssueTrackerServiceRecords < ActiveRecord::Migration[6.0] - DOWNTIME = false - BATCH_SIZE = 5000 - - disable_ddl_transaction! - - class Service < ActiveRecord::Base - include EachBatch - - self.table_name = 'services' - - def self.gitlab_issue_tracker_service - where(type: 'GitlabIssueTrackerService') - end - end - - def up - Service.each_batch(of: BATCH_SIZE) do |services| - services.gitlab_issue_tracker_service.delete_all - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200727114147_remove_title_and_description_from_services.rb b/db/post_migrate/20200727114147_remove_title_and_description_from_services.rb deleted file mode 100644 index 0c908e17438..00000000000 --- a/db/post_migrate/20200727114147_remove_title_and_description_from_services.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class RemoveTitleAndDescriptionFromServices < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def change - remove_column :services, :title, :string - remove_column :services, :description, :string, limit: 500 - end -end diff --git a/db/post_migrate/20200730133730_remove_table_vulnerability_export_verification_status.rb b/db/post_migrate/20200730133730_remove_table_vulnerability_export_verification_status.rb deleted file mode 100644 index 9aa15fa7d1a..00000000000 --- a/db/post_migrate/20200730133730_remove_table_vulnerability_export_verification_status.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class RemoveTableVulnerabilityExportVerificationStatus < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - return unless table_exists?(:vulnerability_export_verification_status) - - drop_table :vulnerability_export_verification_status - end - - def down - # no-op because `vulnerability_export_verification_status` table should not - # be created, see https://gitlab.com/gitlab-org/gitlab/-/issues/232977 - end -end diff --git a/db/post_migrate/20200804035230_add_partial_index_on_id_to_merge_request_diffs.rb b/db/post_migrate/20200804035230_add_partial_index_on_id_to_merge_request_diffs.rb deleted file mode 100644 index 94b939eb811..00000000000 --- a/db/post_migrate/20200804035230_add_partial_index_on_id_to_merge_request_diffs.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddPartialIndexOnIdToMergeRequestDiffs < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_merge_request_diffs_external_diff_store_is_null' - - disable_ddl_transaction! - - def up - add_concurrent_index :merge_request_diffs, :id, where: 'external_diff_store IS NULL', name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :merge_request_diffs, INDEX_NAME - end -end diff --git a/db/post_migrate/20200804041930_add_not_null_constraint_on_external_diff_store_to_merge_request_diffs.rb b/db/post_migrate/20200804041930_add_not_null_constraint_on_external_diff_store_to_merge_request_diffs.rb deleted file mode 100644 index c33e790b37b..00000000000 --- a/db/post_migrate/20200804041930_add_not_null_constraint_on_external_diff_store_to_merge_request_diffs.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintOnExternalDiffStoreToMergeRequestDiffs < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint(:merge_request_diffs, :external_diff_store, validate: false) - end - - def down - remove_not_null_constraint(:merge_request_diffs, :external_diff_store) - end -end diff --git a/db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb b/db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb deleted file mode 100644 index e42f23d8fae..00000000000 --- a/db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -class MigrateNullExternalDiffStoreToLocalValue < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - JOB_INTERVAL = 2.minutes + 5.seconds - BATCH_SIZE = 5_000 - MIGRATION = 'SetNullExternalDiffStoreToLocalValue' - - disable_ddl_transaction! - - class MergeRequestDiff < ActiveRecord::Base - self.table_name = 'merge_request_diffs' - - include ::EachBatch - end - - def up - # On GitLab.com, 19M of 93M rows have NULL external_diff_store. - # - # With batches of 5000 and a background migration job interval of 2m 5s, - # 3.8K jobs are scheduled over 5.5 days. - # - # The index `index_merge_request_diffs_external_diff_store_is_null` is - # expected to be used here and in the jobs. - # - # queue_background_migration_jobs_by_range_at_intervals is not used because - # it would enqueue 18.6K jobs and we have an index for getting these ranges. - MergeRequestDiff.where(external_diff_store: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql("MIN(id)"), Arel.sql("MAX(id)")).first - delay = index * JOB_INTERVAL - - migrate_in(delay.seconds, MIGRATION, [*range]) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20200806004742_add_not_null_constraint_on_file_store_to_package_files.rb b/db/post_migrate/20200806004742_add_not_null_constraint_on_file_store_to_package_files.rb deleted file mode 100644 index 7b7250fef9a..00000000000 --- a/db/post_migrate/20200806004742_add_not_null_constraint_on_file_store_to_package_files.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintOnFileStoreToPackageFiles < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint(:packages_package_files, :file_store, validate: false) - end - - def down - remove_not_null_constraint(:packages_package_files, :file_store) - end -end diff --git a/db/post_migrate/20200806172909_add_partial_index_on_id_to_package_files.rb b/db/post_migrate/20200806172909_add_partial_index_on_id_to_package_files.rb deleted file mode 100644 index 7904574f890..00000000000 --- a/db/post_migrate/20200806172909_add_partial_index_on_id_to_package_files.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddPartialIndexOnIdToPackageFiles < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_packages_package_files_file_store_is_null' - - disable_ddl_transaction! - - def up - add_concurrent_index :packages_package_files, :id, where: 'file_store IS NULL', name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :packages_package_files, INDEX_NAME - end -end diff --git a/db/post_migrate/20200806173633_migrate_null_package_files_file_store_to_local_value.rb b/db/post_migrate/20200806173633_migrate_null_package_files_file_store_to_local_value.rb deleted file mode 100644 index 088b85dd5da..00000000000 --- a/db/post_migrate/20200806173633_migrate_null_package_files_file_store_to_local_value.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -class MigrateNullPackageFilesFileStoreToLocalValue < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - JOB_INTERVAL = 2.minutes + 5.seconds - BATCH_SIZE = 5_000 - MIGRATION = 'SetNullPackageFilesFileStoreToLocalValue' - - disable_ddl_transaction! - - class PackageFile < ActiveRecord::Base - self.table_name = 'packages_package_files' - - include ::EachBatch - end - - def up - # On GitLab.com, there are 2M package files. None have NULL file_store - # because they are all object stored. This is a no-op for GitLab.com. - # - # If a customer had 2M package files with NULL file_store, with batches of - # 5000 and a background migration job interval of 2m 5s, then 400 jobs would - # be scheduled over 14 hours. - # - # The index `index_packages_package_files_file_store_is_null` is - # expected to be used here and in the jobs. - # - # queue_background_migration_jobs_by_range_at_intervals is not used because - # it would enqueue 18.6K jobs and we have an index for getting these ranges. - PackageFile.where(file_store: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql("MIN(id)"), Arel.sql("MAX(id)")).first - delay = index * JOB_INTERVAL - - migrate_in(delay.seconds, MIGRATION, [*range]) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20200807110237_add_migration_index_to_vulnerabilities_occurrences.rb b/db/post_migrate/20200807110237_add_migration_index_to_vulnerabilities_occurrences.rb deleted file mode 100644 index e806a337f8f..00000000000 --- a/db/post_migrate/20200807110237_add_migration_index_to_vulnerabilities_occurrences.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class AddMigrationIndexToVulnerabilitiesOccurrences < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :vulnerability_occurrences, - "project_id, report_type, encode(project_fingerprint, 'hex'::text)", - name: 'index_vulnerability_occurrences_for_issue_links_migration' - end - - def down - remove_concurrent_index_by_name :vulnerability_occurrences, - :index_vulnerability_occurrences_for_issue_links_migration - end -end diff --git a/db/post_migrate/20200807152315_backfill_merge_request_diffs_files_counts.rb b/db/post_migrate/20200807152315_backfill_merge_request_diffs_files_counts.rb deleted file mode 100644 index bc7e4712d19..00000000000 --- a/db/post_migrate/20200807152315_backfill_merge_request_diffs_files_counts.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class BackfillMergeRequestDiffsFilesCounts < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - # There are ~72 million records on GitLab.com at time of writing, so go fast - BATCH_SIZE = 10_000 - DELAY_INTERVAL = 2.minutes.to_i - MIGRATION = 'SetMergeRequestDiffFilesCount' - - disable_ddl_transaction! - - class MergeRequestDiff < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_request_diffs' - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - MergeRequestDiff, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE - ) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200808221641_add_index_for_license_compliance_artifacts.rb b/db/post_migrate/20200808221641_add_index_for_license_compliance_artifacts.rb deleted file mode 100644 index fce4ee095bd..00000000000 --- a/db/post_migrate/20200808221641_add_index_for_license_compliance_artifacts.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddIndexForLicenseComplianceArtifacts < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_ci_job_artifacts_on_license_compliance_file_types' - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_job_artifacts, [:job_id, :file_type], where: 'file_type = 10 OR file_type = 101', name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :ci_job_artifacts, name: INDEX_NAME - end -end diff --git a/db/post_migrate/20200809221641_migrate_license_management_artifacts_to_license_scanning.rb b/db/post_migrate/20200809221641_migrate_license_management_artifacts_to_license_scanning.rb deleted file mode 100644 index 66ef4b35dfa..00000000000 --- a/db/post_migrate/20200809221641_migrate_license_management_artifacts_to_license_scanning.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -class MigrateLicenseManagementArtifactsToLicenseScanning < ActiveRecord::Migration[6.0] - DOWNTIME = false - LICENSE_MANAGEMENT_FILE_TYPE = 10 - LICENSE_SCANNING_FILE_TYPE = 101 - - disable_ddl_transaction! - - class JobArtifact < ActiveRecord::Base - include EachBatch - - self.table_name = 'ci_job_artifacts' - end - - # We're updating file_type of ci artifacts from license_management to license_scanning - # But before that we need to delete "rogue" artifacts for CI builds that have associated with them - # both license_scanning and license_management artifacts. It's an edge case and usually, we don't have - # such builds in the database. - def up - return unless Gitlab.ee? - - JobArtifact - .where("file_type = 10 OR file_type = 101") - .each_batch(column: :job_id, of: 1000) do |relation| - min, max = relation.pluck('MIN(job_id)', 'MAX(job_id)').flatten - - ActiveRecord::Base.connection.execute <<~SQL - WITH ci_job_artifacts_with_row_number as #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT job_id, id, ROW_NUMBER() OVER (PARTITION BY job_id ORDER BY id ASC) as row_number - FROM ci_job_artifacts - WHERE (file_type = #{LICENSE_SCANNING_FILE_TYPE} OR file_type = #{LICENSE_MANAGEMENT_FILE_TYPE}) - AND job_id >= #{Integer(min)} AND job_id < #{Integer(max)} - ) - DELETE FROM ci_job_artifacts - WHERE ci_job_artifacts.id IN (SELECT id from ci_job_artifacts_with_row_number WHERE ci_job_artifacts_with_row_number.row_number > 1) - SQL - end - - JobArtifact.where(file_type: LICENSE_MANAGEMENT_FILE_TYPE).each_batch(column: :job_id, of: 1000) do |relation| - relation.update_all(file_type: LICENSE_SCANNING_FILE_TYPE) - end - end - - def down - # no-op - # we're deleting duplicating artifacts and updating file_type for license_management artifacts - end -end diff --git a/db/post_migrate/20200810100921_add_target_type_to_audit_event.rb b/db/post_migrate/20200810100921_add_target_type_to_audit_event.rb deleted file mode 100644 index 8dde5945f0d..00000000000 --- a/db/post_migrate/20200810100921_add_target_type_to_audit_event.rb +++ /dev/null @@ -1,121 +0,0 @@ -# frozen_string_literal: true - -class AddTargetTypeToAuditEvent < ActiveRecord::Migration[6.0] - include Gitlab::Database::SchemaHelpers - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - SOURCE_TABLE_NAME = 'audit_events' - PARTITIONED_TABLE_NAME = 'audit_events_part_5fc467ac26' - TRIGGER_FUNCTION_NAME = 'table_sync_function_2be879775d' - - def up - with_lock_retries do - # rubocop:disable Migration/AddLimitToTextColumns - add_column('audit_events', :target_type, :text) - add_column('audit_events_part_5fc467ac26', :target_type, :text) - # rubocop:enable Migration/AddLimitToTextColumns - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - type = NEW.type, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - target_type = NEW.target_type, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - type, - entity_id, - entity_type, - details, - ip_address, - author_name, - entity_path, - target_details, - target_type, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.type, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.target_type, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - end - end - - def down - with_lock_retries do - remove_column SOURCE_TABLE_NAME, :target_type - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - type = NEW.type, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - type, - entity_id, - entity_type, - details, - ip_address, - author_name, - entity_path, - target_details, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.type, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - - remove_column PARTITIONED_TABLE_NAME, :target_type - end - end -end diff --git a/db/post_migrate/20200810101029_add_text_limit_to_audit_event_target_type.rb b/db/post_migrate/20200810101029_add_text_limit_to_audit_event_target_type.rb deleted file mode 100644 index 2a5ea9cd245..00000000000 --- a/db/post_migrate/20200810101029_add_text_limit_to_audit_event_target_type.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class AddTextLimitToAuditEventTargetType < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - DOWNTIME = false - SOURCE_TABLE_NAME = 'audit_events' - PARTITIONED_TABLE_NAME = 'audit_events_part_5fc467ac26' - - disable_ddl_transaction! - - def up - add_text_limit(SOURCE_TABLE_NAME, :target_type, 255) - add_text_limit(PARTITIONED_TABLE_NAME, :target_type, 255) - end - - def down - remove_text_limit(SOURCE_TABLE_NAME, :target_type) - remove_text_limit(PARTITIONED_TABLE_NAME, :target_type) - end -end diff --git a/db/post_migrate/20200810160355_add_not_null_constraint_to_ci_pipeline_artifact_file.rb b/db/post_migrate/20200810160355_add_not_null_constraint_to_ci_pipeline_artifact_file.rb deleted file mode 100644 index 0c233d44313..00000000000 --- a/db/post_migrate/20200810160355_add_not_null_constraint_to_ci_pipeline_artifact_file.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintToCiPipelineArtifactFile < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint :ci_pipeline_artifacts, :file, validate: true - end - - def down - remove_not_null_constraint :ci_pipeline_artifacts, :file - end -end diff --git a/db/post_migrate/20200810191256_remove_pipeline_id_from_test_reports.rb b/db/post_migrate/20200810191256_remove_pipeline_id_from_test_reports.rb deleted file mode 100644 index f99629a921e..00000000000 --- a/db/post_migrate/20200810191256_remove_pipeline_id_from_test_reports.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemovePipelineIdFromTestReports < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - remove_column :requirements_management_test_reports, :pipeline_id - end - - def down - add_column :requirements_management_test_reports, :pipeline_id, :integer - - with_lock_retries do - add_foreign_key :requirements_management_test_reports, :ci_pipelines, column: :pipeline_id, on_delete: :nullify - end - end -end diff --git a/db/post_migrate/20200811130000_create_index_vulnerabilities_feedback_issue_id_not_null.rb b/db/post_migrate/20200811130000_create_index_vulnerabilities_feedback_issue_id_not_null.rb deleted file mode 100644 index 118076eb254..00000000000 --- a/db/post_migrate/20200811130000_create_index_vulnerabilities_feedback_issue_id_not_null.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class CreateIndexVulnerabilitiesFeedbackIssueIdNotNull < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :vulnerability_feedback, :id, where: 'issue_id IS NOT NULL', - name: "index_vulnerability_feedback_on_issue_id_not_null" - end - - def down - remove_concurrent_index_by_name :vulnerability_feedback, - :index_vulnerability_feedback_on_issue_id_not_null - end -end diff --git a/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb b/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb deleted file mode 100644 index 031d9ea49e2..00000000000 --- a/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -class CreateMissingVulnerabilitiesIssueLinks < ActiveRecord::Migration[6.0] - class VulnerabilitiesFeedback < ActiveRecord::Base - include EachBatch - self.table_name = 'vulnerability_feedback' - end - - class VulnerabilitiesIssueLink < ActiveRecord::Base - self.table_name = 'vulnerability_issue_links' - LINK_TYPE_CREATED = 2 - end - - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - VulnerabilitiesFeedback.where.not(issue_id: nil).each_batch do |relation| - timestamp = Time.now - issue_links = relation - .joins("JOIN vulnerability_occurrences vo ON vo.project_id = vulnerability_feedback.project_id AND vo.report_type = vulnerability_feedback.category AND encode(vo.project_fingerprint, 'hex') = vulnerability_feedback.project_fingerprint") - .where.not('vo.vulnerability_id' => nil) - .pluck(:vulnerability_id, :issue_id) - .map do |v_id, i_id| - { - vulnerability_id: v_id, - issue_id: i_id, - link_type: VulnerabilitiesIssueLink::LINK_TYPE_CREATED, - created_at: timestamp, - updated_at: timestamp - } - end - - next if issue_links.empty? - - VulnerabilitiesIssueLink.insert_all( - issue_links, - returning: false - ) - end - end - - def down - end -end diff --git a/db/post_migrate/20200811211536_add_index_to_ci_job_artifacts_for_terraform_reports_id.rb b/db/post_migrate/20200811211536_add_index_to_ci_job_artifacts_for_terraform_reports_id.rb deleted file mode 100644 index 6042f90cf85..00000000000 --- a/db/post_migrate/20200811211536_add_index_to_ci_job_artifacts_for_terraform_reports_id.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddIndexToCiJobArtifactsForTerraformReportsId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_ci_job_artifacts_id_for_terraform_reports' - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_job_artifacts, :id, where: 'file_type = 18', name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME - end -end diff --git a/db/post_migrate/20200813153434_import_latest_common_metrics.rb b/db/post_migrate/20200813153434_import_latest_common_metrics.rb deleted file mode 100644 index 203e495674f..00000000000 --- a/db/post_migrate/20200813153434_import_latest_common_metrics.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class ImportLatestCommonMetrics < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - # The common_metrics queries were updated to work with K8s versions that - # use the pod/container label names as well as K8s versions that use the - # older pod_name/container_name convention. - ::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute - end - - def down - # no-op - # The import cannot be reversed since we do not know the state that the - # common metrics in the PrometheusMetric table were in before the import. - - # To manually revert this migration. - # 1. Go back to the previous version of the config/prometheus/common_metrics.yml file. (git checkout 74447f11349617ed8b273196d6a5781d9a67a613) - # 2. Execute `rails runner '::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute'` - end -end diff --git a/db/post_migrate/20200817070126_update_index_secure_for_coverage_fuzzing_telemetry.rb b/db/post_migrate/20200817070126_update_index_secure_for_coverage_fuzzing_telemetry.rb deleted file mode 100644 index d9aa7314115..00000000000 --- a/db/post_migrate/20200817070126_update_index_secure_for_coverage_fuzzing_telemetry.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class UpdateIndexSecureForCoverageFuzzingTelemetry < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - OLD_SECURE_INDEX_NAME = 'index_secure_ci_builds_on_user_id_created_at' - NEW_SECURE_INDEX_NAME = 'index_secure_ci_builds_on_user_id_created_at_parser_features' - - def up - add_concurrent_index(:ci_builds, - [:user_id, :created_at], - where: "(((type)::text = 'Ci::Build'::text) AND ((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, ('dast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('license_management'::character varying)::text, ('license_scanning'::character varying)::text, ('sast'::character varying)::text, ('coverage_fuzzing'::character varying)::text, ('secret_detection'::character varying)::text])))", - name: NEW_SECURE_INDEX_NAME) - remove_concurrent_index_by_name :ci_builds, OLD_SECURE_INDEX_NAME - end - - def down - add_concurrent_index(:ci_builds, - [:user_id, :created_at], - where: "(((type)::text = 'Ci::Build'::text) AND ((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, ('dast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('license_management'::character varying)::text, ('license_scanning'::character varying)::text, ('sast'::character varying)::text, ('secret_detection'::character varying)::text])))", - name: OLD_SECURE_INDEX_NAME) - remove_concurrent_index_by_name :ci_builds, NEW_SECURE_INDEX_NAME - end -end diff --git a/db/post_migrate/20200817100710_add_section_and_created_at_codeowner_approval_merge_request_index.rb b/db/post_migrate/20200817100710_add_section_and_created_at_codeowner_approval_merge_request_index.rb deleted file mode 100644 index 33de4f1f790..00000000000 --- a/db/post_migrate/20200817100710_add_section_and_created_at_codeowner_approval_merge_request_index.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class AddSectionAndCreatedAtCodeownerApprovalMergeRequestIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - SECTION_CREATED_AT_ON_CODEOWNER_APPROVAL_MERGE_REQUEST_RULES = "index_created_at_on_codeowner_approval_merge_request_rules" - RULE_TYPE_CODEOWNERS = 2 - CODEOWNER_SECTION_DEFAULT = 'codeowners' - - disable_ddl_transaction! - - def up - add_concurrent_index :approval_merge_request_rules, :created_at, - where: "rule_type = #{RULE_TYPE_CODEOWNERS} AND section != '#{CODEOWNER_SECTION_DEFAULT}'::text", - name: SECTION_CREATED_AT_ON_CODEOWNER_APPROVAL_MERGE_REQUEST_RULES - end - - def down - remove_concurrent_index_by_name :approval_merge_request_rules, SECTION_CREATED_AT_ON_CODEOWNER_APPROVAL_MERGE_REQUEST_RULES - end -end diff --git a/db/post_migrate/20200819082334_remove_default_from_services.rb b/db/post_migrate/20200819082334_remove_default_from_services.rb deleted file mode 100644 index 2a990016c95..00000000000 --- a/db/post_migrate/20200819082334_remove_default_from_services.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveDefaultFromServices < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - with_lock_retries do - remove_column :services, :default, :boolean - end - end - - def down - with_lock_retries do - add_column :services, :default, :boolean, default: false - end - end -end diff --git a/db/post_migrate/20200819113644_add_target_id_to_audit_events.rb b/db/post_migrate/20200819113644_add_target_id_to_audit_events.rb deleted file mode 100644 index c2d9aff928b..00000000000 --- a/db/post_migrate/20200819113644_add_target_id_to_audit_events.rb +++ /dev/null @@ -1,125 +0,0 @@ -# frozen_string_literal: true - -class AddTargetIdToAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::SchemaHelpers - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - SOURCE_TABLE_NAME = 'audit_events' - PARTITIONED_TABLE_NAME = 'audit_events_part_5fc467ac26' - TRIGGER_FUNCTION_NAME = 'table_sync_function_2be879775d' - - def up - with_lock_retries do - add_column(SOURCE_TABLE_NAME, :target_id, :bigint) - add_column(PARTITIONED_TABLE_NAME, :target_id, :bigint) - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - type = NEW.type, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - target_type = NEW.target_type, - target_id = NEW.target_id, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - type, - entity_id, - entity_type, - details, - ip_address, - author_name, - entity_path, - target_details, - target_type, - target_id, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.type, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.target_type, - NEW.target_id, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - end - end - - def down - with_lock_retries do - remove_column SOURCE_TABLE_NAME, :target_id - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - type = NEW.type, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - target_type = NEW.target_type, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - type, - entity_id, - entity_type, - details, - ip_address, - author_name, - entity_path, - target_details, - target_type, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.type, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.target_type, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - - remove_column PARTITIONED_TABLE_NAME, :target_id - end - end -end diff --git a/db/post_migrate/20200819202048_remove_orphaned_emails.rb b/db/post_migrate/20200819202048_remove_orphaned_emails.rb deleted file mode 100644 index 82cba244ad6..00000000000 --- a/db/post_migrate/20200819202048_remove_orphaned_emails.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class RemoveOrphanedEmails < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute <<~SQL - DELETE FROM emails - WHERE not exists ( - SELECT 1 FROM users WHERE users.id = emails.user_id - ); - SQL - - execute 'DELETE FROM emails WHERE user_id IS NULL;' - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200819202222_validate_emails_user_id_foreign_key.rb b/db/post_migrate/20200819202222_validate_emails_user_id_foreign_key.rb deleted file mode 100644 index 4f7f9deb540..00000000000 --- a/db/post_migrate/20200819202222_validate_emails_user_id_foreign_key.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class ValidateEmailsUserIdForeignKey < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - CONSTRAINT_NAME = 'fk_emails_user_id' - - def up - validate_foreign_key :emails, :user_id, name: CONSTRAINT_NAME - end - - def down - # no op - end -end diff --git a/db/post_migrate/20200821224343_schedule_populate_vulnerability_historical_statistics.rb b/db/post_migrate/20200821224343_schedule_populate_vulnerability_historical_statistics.rb deleted file mode 100644 index f3a57ab78ef..00000000000 --- a/db/post_migrate/20200821224343_schedule_populate_vulnerability_historical_statistics.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateVulnerabilityHistoricalStatistics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY_INTERVAL = 2.minutes.to_i - BATCH_SIZE = 50 - MIGRATION = 'PopulateVulnerabilityHistoricalStatistics' - - disable_ddl_transaction! - - class Vulnerability < ActiveRecord::Base - self.table_name = 'vulnerabilities' - - include ::EachBatch - end - - def up - return unless Gitlab.ee? - - Vulnerability.select('project_id').distinct.each_batch(of: BATCH_SIZE, column: 'project_id') do |project_batch, index| - migrate_in(index * DELAY_INTERVAL, MIGRATION, [project_batch.pluck(:project_id)]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200824130028_remove_index_on_users_bio.rb b/db/post_migrate/20200824130028_remove_index_on_users_bio.rb deleted file mode 100644 index d41734eb9ce..00000000000 --- a/db/post_migrate/20200824130028_remove_index_on_users_bio.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class RemoveIndexOnUsersBio < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BACKGROUND_MIGRATION_CLASS = 'MigrateUsersBioToUserDetails' - INDEX_NAME = 'tmp_idx_on_user_id_where_bio_is_filled' - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal(BACKGROUND_MIGRATION_CLASS) - remove_concurrent_index_by_name(:users, INDEX_NAME) - end - - def down - add_concurrent_index :users, :id, where: "(COALESCE(bio, '') IS DISTINCT FROM '')", name: INDEX_NAME - end -end diff --git a/db/post_migrate/20200824130447_remove_users_bio_column.rb b/db/post_migrate/20200824130447_remove_users_bio_column.rb deleted file mode 100644 index cb630ec7fd5..00000000000 --- a/db/post_migrate/20200824130447_remove_users_bio_column.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveUsersBioColumn < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - with_lock_retries do - remove_column :users, :bio - end - end - - def down - with_lock_retries do - add_column :users, :bio, :string # rubocop: disable Migration/AddColumnsToWideTables - end - end -end diff --git a/db/post_migrate/20200826053152_add_index_on_ci_pipelines_source_for_on_demand_dast.rb b/db/post_migrate/20200826053152_add_index_on_ci_pipelines_source_for_on_demand_dast.rb deleted file mode 100644 index 6249adc9798..00000000000 --- a/db/post_migrate/20200826053152_add_index_on_ci_pipelines_source_for_on_demand_dast.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnCiPipelinesSourceForOnDemandDast < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - INDEX_NAME = 'index_ci_pipelines_for_ondemand_dast_scans' - - SOURCE_ONDEMAND_DAST_SCAN_PIPELINE = 13 - - disable_ddl_transaction! - - def up - add_concurrent_index( - :ci_pipelines, :id, - where: "source = #{SOURCE_ONDEMAND_DAST_SCAN_PIPELINE}", - name: INDEX_NAME - ) - end - - def down - remove_concurrent_index( - :ci_pipelines, :id, - where: "source = #{SOURCE_ONDEMAND_DAST_SCAN_PIPELINE}", - name: INDEX_NAME - ) - end -end diff --git a/db/post_migrate/20200826121552_remove_ci_job_artifacts_locked.rb b/db/post_migrate/20200826121552_remove_ci_job_artifacts_locked.rb deleted file mode 100644 index 21c7acca7ac..00000000000 --- a/db/post_migrate/20200826121552_remove_ci_job_artifacts_locked.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveCiJobArtifactsLocked < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - with_lock_retries do - remove_column :ci_job_artifacts, :locked - end - end - - def down - with_lock_retries do - add_column :ci_job_artifacts, :locked, :boolean - end - end -end diff --git a/db/post_migrate/20200826220745_add_compound_index_on_vulnerabilities_for_background_migration.rb b/db/post_migrate/20200826220745_add_compound_index_on_vulnerabilities_for_background_migration.rb deleted file mode 100644 index da95f708cf9..00000000000 --- a/db/post_migrate/20200826220745_add_compound_index_on_vulnerabilities_for_background_migration.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddCompoundIndexOnVulnerabilitiesForBackgroundMigration < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_vulnerabilities_on_project_id_and_id' - - disable_ddl_transaction! - - def up - add_concurrent_index :vulnerabilities, [:project_id, :id], name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME - end -end diff --git a/db/post_migrate/20200826220746_schedule_populate_resolved_on_default_branch_column.rb b/db/post_migrate/20200826220746_schedule_populate_resolved_on_default_branch_column.rb deleted file mode 100644 index 6faa4fc8101..00000000000 --- a/db/post_migrate/20200826220746_schedule_populate_resolved_on_default_branch_column.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateResolvedOnDefaultBranchColumn < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 100 - DELAY_INTERVAL = 5.minutes.to_i - MIGRATION_CLASS = 'PopulateResolvedOnDefaultBranchColumn' - - disable_ddl_transaction! - - def up - return unless Gitlab.ee? - - EE::Gitlab::BackgroundMigration::PopulateResolvedOnDefaultBranchColumn::Vulnerability.distinct.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index| - project_ids = batch.pluck(:project_id) - migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, project_ids) - end - end - - def down - # no-op - # This migration schedules background tasks to populate - # `resolved_on_default_branch` column of `vulnerabilities` - # table so there is no rollback operation needed for this. - end -end diff --git a/db/post_migrate/20200831065320_add_not_valid_not_null_constraint_to_mr_metrics.rb b/db/post_migrate/20200831065320_add_not_valid_not_null_constraint_to_mr_metrics.rb deleted file mode 100644 index 35bfabc0358..00000000000 --- a/db/post_migrate/20200831065320_add_not_valid_not_null_constraint_to_mr_metrics.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotValidNotNullConstraintToMrMetrics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint :merge_request_metrics, :target_project_id, validate: false - end - - def down - remove_not_null_constraint :merge_request_metrics, :target_project_id - end -end diff --git a/db/post_migrate/20200831065322_add_tmp_index_to_target_project_id.rb b/db/post_migrate/20200831065322_add_tmp_index_to_target_project_id.rb deleted file mode 100644 index 5d6d098ebfe..00000000000 --- a/db/post_migrate/20200831065322_add_tmp_index_to_target_project_id.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddTmpIndexToTargetProjectId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - TMP_INDEX_NAME = 'tmp_index_on_mr_metrics_target_project_id_null' - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :merge_request_metrics, :id, where: 'target_project_id IS NULL', name: TMP_INDEX_NAME - end - - def down - remove_concurrent_index_by_name :merge_request_metrics, name: TMP_INDEX_NAME - end -end diff --git a/db/post_migrate/20200831065705_ensure_target_project_id_is_filled.rb b/db/post_migrate/20200831065705_ensure_target_project_id_is_filled.rb deleted file mode 100644 index 8693dca0000..00000000000 --- a/db/post_migrate/20200831065705_ensure_target_project_id_is_filled.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -class EnsureTargetProjectIdIsFilled < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - BACKGROUND_MIGRATION_CLASS = 'CopyMergeRequestTargetProjectToMergeRequestMetrics' - BATCH_SIZE = 1_000 - DOWNTIME = false - - disable_ddl_transaction! - - class MergeRequest < ActiveRecord::Base - self.table_name = 'merge_requests' - end - - class MergeRequestMetrics < ActiveRecord::Base - include EachBatch - - belongs_to :merge_request - - self.table_name = 'merge_request_metrics' - end - - def up - Gitlab::BackgroundMigration.steal(BACKGROUND_MIGRATION_CLASS) - - # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low. - MergeRequestMetrics.where(target_project_id: nil).each_batch do |scope| - query_for_cte = scope.joins(:merge_request).select( - MergeRequestMetrics.arel_table[:id].as('id'), - MergeRequest.arel_table[:target_project_id].as('target_project_id') - ) - - MergeRequestMetrics.connection.execute <<-SQL - WITH target_project_id_and_metrics_id as #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - #{query_for_cte.to_sql} - ) - UPDATE #{MergeRequestMetrics.connection.quote_table_name(MergeRequestMetrics.table_name)} - SET target_project_id = target_project_id_and_metrics_id.target_project_id - FROM target_project_id_and_metrics_id - WHERE merge_request_metrics.id = target_project_id_and_metrics_id.id - SQL - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200831074356_validate_not_null_constraint_on_mr_metrics.rb b/db/post_migrate/20200831074356_validate_not_null_constraint_on_mr_metrics.rb deleted file mode 100644 index 8fd54186db3..00000000000 --- a/db/post_migrate/20200831074356_validate_not_null_constraint_on_mr_metrics.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class ValidateNotNullConstraintOnMrMetrics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - TMP_INDEX_NAME = 'tmp_index_on_mr_metrics_target_project_id_null' - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :merge_request_metrics, :target_project_id - - remove_concurrent_index_by_name :merge_request_metrics, name: TMP_INDEX_NAME - end - - def down - add_concurrent_index :merge_request_metrics, :id, where: 'target_project_id IS NULL', name: TMP_INDEX_NAME - end -end diff --git a/db/post_migrate/20200831224343_populate_vulnerability_historical_statistics_for_year.rb b/db/post_migrate/20200831224343_populate_vulnerability_historical_statistics_for_year.rb deleted file mode 100644 index 3f4fbfbebde..00000000000 --- a/db/post_migrate/20200831224343_populate_vulnerability_historical_statistics_for_year.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class PopulateVulnerabilityHistoricalStatisticsForYear < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY_INTERVAL = 5.minutes.to_i - BATCH_SIZE = 50 - MIGRATION = 'PopulateVulnerabilityHistoricalStatistics' - - disable_ddl_transaction! - - class Vulnerability < ActiveRecord::Base - self.table_name = 'vulnerabilities' - - include ::EachBatch - end - - def up - return unless Gitlab.ee? - - Vulnerability.select('project_id').distinct.each_batch(of: BATCH_SIZE, column: 'project_id') do |project_batch, index| - migrate_in(index * DELAY_INTERVAL, MIGRATION, [project_batch.pluck(:project_id), 365]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200901170135_backfill_modified_column_for_approval_merge_request_rules.rb b/db/post_migrate/20200901170135_backfill_modified_column_for_approval_merge_request_rules.rb deleted file mode 100644 index 9a9866f38ec..00000000000 --- a/db/post_migrate/20200901170135_backfill_modified_column_for_approval_merge_request_rules.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class BackfillModifiedColumnForApprovalMergeRequestRules < ActiveRecord::Migration[6.0] - include Gitlab::Database::Migrations::BackgroundMigrationHelpers - - disable_ddl_transaction! - - class ApprovalMergeRequestRule < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'approval_merge_request_rules' - end - - def change - queue_background_migration_jobs_by_range_at_intervals(ApprovalMergeRequestRule, 'AddModifiedToApprovalMergeRequestRule', 2.minutes, batch_size: 10_000) - end -end diff --git a/db/post_migrate/20200901212304_drop_code_owner_column_from_approval_merge_request_rule.rb b/db/post_migrate/20200901212304_drop_code_owner_column_from_approval_merge_request_rule.rb deleted file mode 100644 index 7524ae8e15b..00000000000 --- a/db/post_migrate/20200901212304_drop_code_owner_column_from_approval_merge_request_rule.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -class DropCodeOwnerColumnFromApprovalMergeRequestRule < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - def up - with_lock_retries do - remove_column :approval_merge_request_rules, :code_owner - end - end - - def down - unless column_exists?(:approval_merge_request_rules, :code_owner) - with_lock_retries do - add_column :approval_merge_request_rules, :code_owner, :boolean, default: false, null: false - end - end - - add_concurrent_index( - :approval_merge_request_rules, - [:merge_request_id, :code_owner, :name], - unique: true, - where: "code_owner = true AND section IS NULL", - name: "approval_rule_name_index_for_code_owners" - ) - - add_concurrent_index( - :approval_merge_request_rules, - [:merge_request_id, :code_owner], - name: "index_approval_merge_request_rules_1" - ) - end -end diff --git a/db/post_migrate/20200903064431_add_created_at_index_to_audit_events.rb b/db/post_migrate/20200903064431_add_created_at_index_to_audit_events.rb deleted file mode 100644 index 94dc2cb7adf..00000000000 --- a/db/post_migrate/20200903064431_add_created_at_index_to_audit_events.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class AddCreatedAtIndexToAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - INDEX_NAME = 'idx_audit_events_on_entity_id_desc_author_id_created_at' - OLD_INDEX_NAME = 'index_audit_events_on_entity_id_entity_type_id_desc_author_id' - - def up - add_concurrent_index(:audit_events, [:entity_id, :entity_type, :id, :author_id, :created_at], order: { id: :desc }, name: INDEX_NAME) - remove_concurrent_index_by_name(:audit_events, OLD_INDEX_NAME) - end - - def down - add_concurrent_index(:audit_events, [:entity_id, :entity_type, :id, :author_id], order: { id: :desc }, name: OLD_INDEX_NAME) - remove_concurrent_index_by_name(:audit_events, INDEX_NAME) - end -end diff --git a/db/post_migrate/20200904174901_backfill_cleanup_for_partitioned_audit_events.rb b/db/post_migrate/20200904174901_backfill_cleanup_for_partitioned_audit_events.rb deleted file mode 100644 index 1d8240012d1..00000000000 --- a/db/post_migrate/20200904174901_backfill_cleanup_for_partitioned_audit_events.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class BackfillCleanupForPartitionedAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::PartitioningMigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - finalize_backfilling_partitioned_table :audit_events - end - - def down - # no op - end -end diff --git a/db/post_migrate/20200907092715_add_not_null_constraint_to_user_on_group_import_states.rb b/db/post_migrate/20200907092715_add_not_null_constraint_to_user_on_group_import_states.rb deleted file mode 100644 index 4f2edad43d8..00000000000 --- a/db/post_migrate/20200907092715_add_not_null_constraint_to_user_on_group_import_states.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintToUserOnGroupImportStates < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint :group_import_states, :user_id, validate: false - end - - def down - remove_not_null_constraint :group_import_states, :user_id - end -end diff --git a/db/post_migrate/20200907124300_complete_namespace_settings_migration.rb b/db/post_migrate/20200907124300_complete_namespace_settings_migration.rb deleted file mode 100644 index 5881869ee3c..00000000000 --- a/db/post_migrate/20200907124300_complete_namespace_settings_migration.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -class CompleteNamespaceSettingsMigration < ActiveRecord::Migration[5.2] - DOWNTIME = false - BATCH_SIZE = 10000 - - class Namespace < ActiveRecord::Base - include EachBatch - - self.table_name = 'namespaces' - end - - def up - Gitlab::BackgroundMigration.steal('BackfillNamespaceSettings') - - ensure_data_migration - end - - def down - # no-op - end - - private - - def ensure_data_migration - Namespace.each_batch(of: BATCH_SIZE) do |query| - missing_count = query.where("NOT EXISTS (SELECT 1 FROM namespace_settings WHERE namespace_settings.namespace_id=namespaces.id)").limit(1).size - if missing_count > 0 - min, max = query.pluck("MIN(id), MAX(id)").flatten - # we expect low record count so inline execution is fine. - Gitlab::BackgroundMigration::BackfillNamespaceSettings.new.perform(min, max) - end - end - end -end diff --git a/db/post_migrate/20200908064229_add_partial_index_to_ci_builds_table_on_user_id_name.rb b/db/post_migrate/20200908064229_add_partial_index_to_ci_builds_table_on_user_id_name.rb deleted file mode 100644 index 433fa957c38..00000000000 --- a/db/post_migrate/20200908064229_add_partial_index_to_ci_builds_table_on_user_id_name.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class AddPartialIndexToCiBuildsTableOnUserIdName < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - INDEX_NAME = 'index_partial_ci_builds_on_user_id_name_parser_features' - FILTER_CONDITION = <<~SQL - (((type)::text = 'Ci::Build'::text) AND - ((name)::text = ANY ( - ARRAY[ - ('container_scanning'::character varying)::text, - ('dast'::character varying)::text, - ('dependency_scanning'::character varying)::text, - ('license_management'::character varying)::text, - ('license_scanning'::character varying)::text, - ('sast'::character varying)::text, - ('coverage_fuzzing'::character varying)::text, - ('secret_detection'::character varying)::text - ] - )) - ) - SQL - - def up - add_concurrent_index(:ci_builds, - [:user_id, :name], - where: FILTER_CONDITION, - name: INDEX_NAME) - end - - def down - remove_concurrent_index_by_name :ci_builds, INDEX_NAME - end -end diff --git a/db/post_migrate/20200908095446_update_location_fingerprint_column_for_cs.rb b/db/post_migrate/20200908095446_update_location_fingerprint_column_for_cs.rb deleted file mode 100644 index fc2b7116ed1..00000000000 --- a/db/post_migrate/20200908095446_update_location_fingerprint_column_for_cs.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class UpdateLocationFingerprintColumnForCs < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - BATCH_SIZE = 1_000 - INTERVAL = 2.minutes - - # 883_152 records - def up - return unless Gitlab.ee? - - migration = Gitlab::BackgroundMigration::UpdateLocationFingerprintForContainerScanningFindings - migration_name = migration.to_s.demodulize - relation = migration::Finding.container_scanning - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - # intentionally blank - end -end diff --git a/db/post_migrate/20200909161624_cleanup_group_import_states_with_null_user_id.rb b/db/post_migrate/20200909161624_cleanup_group_import_states_with_null_user_id.rb deleted file mode 100644 index f956da81528..00000000000 --- a/db/post_migrate/20200909161624_cleanup_group_import_states_with_null_user_id.rb +++ /dev/null @@ -1,80 +0,0 @@ -# frozen_string_literal: true - -class CleanupGroupImportStatesWithNullUserId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - # With BATCH_SIZE=1000 and group_import_states.count=600 on GitLab.com - # - 1 iteration will be run - # - each batch requires on average ~2500ms - # - 600 rows require on average ~1500ms - # Expected total run time: ~2500ms - BATCH_SIZE = 1000 - - disable_ddl_transaction! - - class User < ActiveRecord::Base - self.table_name = 'users' - end - - class Namespace < ActiveRecord::Base - self.table_name = 'namespaces' - - belongs_to :owner, class_name: 'CleanupGroupImportStatesWithNullUserId::User' - end - - class Member < ActiveRecord::Base - self.table_name = 'members' - self.inheritance_column = :_type_disabled - - belongs_to :user, class_name: 'CleanupGroupImportStatesWithNullUserId::User' - end - - class Group < Namespace - OWNER = 50 - - self.inheritance_column = :_type_disabled - - def default_owner - owners.first || parent&.default_owner || owner - end - - def parent - Group.find_by_id(parent_id) - end - - def owners - Member.where(type: 'GroupMember', source_type: 'Namespace', source_id: id, requested_at: nil, access_level: OWNER).map(&:user) - end - end - - class GroupImportState < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'group_import_states' - - belongs_to :group, class_name: 'CleanupGroupImportStatesWithNullUserId::Group' - belongs_to :user, class_name: 'CleanupGroupImportStatesWithNullUserId::User' - end - - def up - User.reset_column_information - Namespace.reset_column_information - Member.reset_column_information - Group.reset_column_information - GroupImportState.reset_column_information - - GroupImportState.each_batch(of: BATCH_SIZE) do |batch| - batch.each do |group_import_state| - owner_id = Group.find_by_id(group_import_state.group_id)&.default_owner&.id - - group_import_state.update!(user_id: owner_id) if owner_id - end - end - - GroupImportState.where(user_id: nil).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/20200909194014_change_pypi_python_version_type_cleanup.rb b/db/post_migrate/20200909194014_change_pypi_python_version_type_cleanup.rb deleted file mode 100644 index c94f745e762..00000000000 --- a/db/post_migrate/20200909194014_change_pypi_python_version_type_cleanup.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class ChangePypiPythonVersionTypeCleanup < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_type_change(:packages_pypi_metadata, :required_python) - end - - def down - execute('UPDATE packages_pypi_metadata SET required_python = substring(required_python from 1 for 50)') - change_column_type_concurrently :packages_pypi_metadata, :required_python, 'varchar(50)', batch_column_name: :package_id - end -end diff --git a/db/post_migrate/20200909194524_increase_pypi_version_size.rb b/db/post_migrate/20200909194524_increase_pypi_version_size.rb deleted file mode 100644 index 0273d49bba9..00000000000 --- a/db/post_migrate/20200909194524_increase_pypi_version_size.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class IncreasePypiVersionSize < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_text_limit :packages_pypi_metadata, :required_python, 255 - end - - def down - remove_text_limit :packages_pypi_metadata, :required_python - end -end diff --git a/db/post_migrate/20200910131217_tmp_index_for_fixing_inconsistent_vulnerability_occurrences.rb b/db/post_migrate/20200910131217_tmp_index_for_fixing_inconsistent_vulnerability_occurrences.rb deleted file mode 100644 index 1985b8f1b67..00000000000 --- a/db/post_migrate/20200910131217_tmp_index_for_fixing_inconsistent_vulnerability_occurrences.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class TmpIndexForFixingInconsistentVulnerabilityOccurrences < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'tmp_index_for_fixing_inconsistent_vulnerability_occurrences' - disable_ddl_transaction! - - def up - # report_type: 2 container scanning - add_concurrent_index(:vulnerability_occurrences, :id, - where: "LENGTH(location_fingerprint) = 40 AND report_type = 2", - name: INDEX_NAME) - end - - def down - remove_concurrent_index_by_name(:vulnerability_occurrences, INDEX_NAME) - end -end diff --git a/db/post_migrate/20200910131218_remove_duplicated_cs_findings.rb b/db/post_migrate/20200910131218_remove_duplicated_cs_findings.rb deleted file mode 100644 index c5bfddfd265..00000000000 --- a/db/post_migrate/20200910131218_remove_duplicated_cs_findings.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicatedCsFindings < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - BATCH_SIZE = 1_000 - INTERVAL = 2.minutes - - # 23_893 records will be updated - # 23_893 records will be deleted - def up - return unless Gitlab.com? - - migration = Gitlab::BackgroundMigration::RemoveDuplicateCsFindings - migration_name = migration.to_s.demodulize - relation = migration::Finding.container_scanning.where("LENGTH(location_fingerprint) = 40") - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - # intentionally blank - end -end diff --git a/db/post_migrate/20200910155617_backfill_jira_tracker_deployment_type.rb b/db/post_migrate/20200910155617_backfill_jira_tracker_deployment_type.rb deleted file mode 100644 index 9c978a20d25..00000000000 --- a/db/post_migrate/20200910155617_backfill_jira_tracker_deployment_type.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class BackfillJiraTrackerDeploymentType < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - # no-op - # this migration was reverted - # in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/45205 - # due to https://gitlab.com/gitlab-com/gl-infra/production/-/issues/2820 - end - - def down - # no-op - # intentionally blank - end -end diff --git a/db/post_migrate/20200910170908_ensure_filled_external_diff_store_on_merge_request_diffs.rb b/db/post_migrate/20200910170908_ensure_filled_external_diff_store_on_merge_request_diffs.rb deleted file mode 100644 index 5070bd1c2f5..00000000000 --- a/db/post_migrate/20200910170908_ensure_filled_external_diff_store_on_merge_request_diffs.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class EnsureFilledExternalDiffStoreOnMergeRequestDiffs < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - BACKGROUND_MIGRATION_CLASS = 'SetNullExternalDiffStoreToLocalValue' - BATCH_SIZE = 5_000 - LOCAL_STORE = 1 # equal to ObjectStorage::Store::LOCAL - DOWNTIME = false - - disable_ddl_transaction! - - class MergeRequestDiff < ActiveRecord::Base - self.table_name = 'merge_request_diffs' - - include ::EachBatch - end - - def up - Gitlab::BackgroundMigration.steal(BACKGROUND_MIGRATION_CLASS) - - # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low. - MergeRequestDiff.where(external_diff_store: nil).each_batch(of: BATCH_SIZE) do |batch, index| - batch.update_all(external_diff_store: LOCAL_STORE) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200910175553_validate_not_null_external_diff_store_on_merge_request_diffs.rb b/db/post_migrate/20200910175553_validate_not_null_external_diff_store_on_merge_request_diffs.rb deleted file mode 100644 index 4dc8ac96a4c..00000000000 --- a/db/post_migrate/20200910175553_validate_not_null_external_diff_store_on_merge_request_diffs.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class ValidateNotNullExternalDiffStoreOnMergeRequestDiffs < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - # Remove index which was only added to fill external_diff_store - INDEX_NAME = 'index_merge_request_diffs_external_diff_store_is_null' - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :merge_request_diffs, :external_diff_store - - remove_concurrent_index_by_name :merge_request_diffs, INDEX_NAME - end - - def down - add_concurrent_index :merge_request_diffs, :id, where: 'external_diff_store IS NULL', name: INDEX_NAME - end -end diff --git a/db/post_migrate/20200912153218_cleanup_admin_notification_email_application_setting_rename.rb b/db/post_migrate/20200912153218_cleanup_admin_notification_email_application_setting_rename.rb deleted file mode 100644 index 35c54b64ddf..00000000000 --- a/db/post_migrate/20200912153218_cleanup_admin_notification_email_application_setting_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupAdminNotificationEmailApplicationSettingRename < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :application_settings, :admin_notification_email, :abuse_notification_email - end - - def down - undo_cleanup_concurrent_column_rename :application_settings, :admin_notification_email, :abuse_notification_email - end -end diff --git a/db/post_migrate/20200915044225_schedule_migration_to_hashed_storage.rb b/db/post_migrate/20200915044225_schedule_migration_to_hashed_storage.rb deleted file mode 100644 index 553d060dc58..00000000000 --- a/db/post_migrate/20200915044225_schedule_migration_to_hashed_storage.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class ScheduleMigrationToHashedStorage < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - DOWNTIME = false - MIGRATION = 'MigrateToHashedStorage' - - disable_ddl_transaction! - - def up - migrate_async(MIGRATION) - end - - def down - # NO-OP - end -end diff --git a/db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb b/db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb deleted file mode 100644 index ec6f6df27bc..00000000000 --- a/db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class EnsureFilledFileStoreOnPackageFiles < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - BACKGROUND_MIGRATION_CLASS = 'SetNullPackageFilesFileStoreToLocalValue' - BATCH_SIZE = 5_000 - LOCAL_STORE = 1 # equal to ObjectStorage::Store::LOCAL - DOWNTIME = false - - disable_ddl_transaction! - - module Packages - class PackageFile < ActiveRecord::Base - self.table_name = 'packages_package_files' - - include ::EachBatch - end - end - - def up - Gitlab::BackgroundMigration.steal(BACKGROUND_MIGRATION_CLASS) - - # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low. - Packages::PackageFile.where(file_store: nil).each_batch(of: BATCH_SIZE) do |batch, index| - batch.update_all(file_store: LOCAL_STORE) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200915191156_validate_not_null_file_store_on_package_files.rb b/db/post_migrate/20200915191156_validate_not_null_file_store_on_package_files.rb deleted file mode 100644 index 5e6db9cec3f..00000000000 --- a/db/post_migrate/20200915191156_validate_not_null_file_store_on_package_files.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class ValidateNotNullFileStoreOnPackageFiles < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - # Remove index which was only added to fill file_store - INDEX_NAME = 'index_packages_package_files_file_store_is_null' - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_not_null_constraint :packages_package_files, :file_store - - remove_concurrent_index_by_name :packages_package_files, INDEX_NAME - end - - def down - add_concurrent_index :packages_package_files, :id, where: 'file_store IS NULL', name: INDEX_NAME - end -end diff --git a/db/post_migrate/20200916081749_remove_cycle_analytics_total_stage_data.rb b/db/post_migrate/20200916081749_remove_cycle_analytics_total_stage_data.rb deleted file mode 100644 index 94c218c0c57..00000000000 --- a/db/post_migrate/20200916081749_remove_cycle_analytics_total_stage_data.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class RemoveCycleAnalyticsTotalStageData < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute("DELETE FROM analytics_cycle_analytics_group_stages WHERE name='production'") - execute("DELETE FROM analytics_cycle_analytics_project_stages WHERE name='production'") - end - - def down - # Migration is irreversible - end -end diff --git a/db/post_migrate/20200917135802_remove_duplicated_cs_findings_without_vulnerability_id.rb b/db/post_migrate/20200917135802_remove_duplicated_cs_findings_without_vulnerability_id.rb deleted file mode 100644 index 0e161b5de78..00000000000 --- a/db/post_migrate/20200917135802_remove_duplicated_cs_findings_without_vulnerability_id.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicatedCsFindingsWithoutVulnerabilityId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - BATCH_SIZE = 1_000 - - INTERVAL = 2.minutes - - # 1_500 records will be deleted - def up - return unless Gitlab.com? - - migration = Gitlab::BackgroundMigration::RemoveDuplicatedCsFindingsWithoutVulnerabilityId - migration_name = migration.to_s.demodulize - relation = migration::Finding.container_scanning.with_broken_fingerprint.where(vulnerability_id: nil) - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20200917165525_update_index_on_namespaces_for_type_and_id.rb b/db/post_migrate/20200917165525_update_index_on_namespaces_for_type_and_id.rb deleted file mode 100644 index 35b72b4f160..00000000000 --- a/db/post_migrate/20200917165525_update_index_on_namespaces_for_type_and_id.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class UpdateIndexOnNamespacesForTypeAndId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - OLD_INDEX_NAME = 'index_namespaces_on_type_partial' - NEW_INDEX_NAME = 'index_namespaces_on_type_and_id_partial' - - def up - add_concurrent_index(:namespaces, [:type, :id], where: 'type IS NOT NULL', name: NEW_INDEX_NAME) - - remove_concurrent_index_by_name(:namespaces, OLD_INDEX_NAME) - end - - def down - add_concurrent_index(:namespaces, :type, where: 'type IS NOT NULL', name: OLD_INDEX_NAME) - - remove_concurrent_index_by_name(:namespaces, NEW_INDEX_NAME) - end -end diff --git a/db/post_migrate/20200922054642_drop_snowplow_iglu_registry_url_from_application_settings.rb b/db/post_migrate/20200922054642_drop_snowplow_iglu_registry_url_from_application_settings.rb deleted file mode 100644 index d3e64f1f4c2..00000000000 --- a/db/post_migrate/20200922054642_drop_snowplow_iglu_registry_url_from_application_settings.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class DropSnowplowIgluRegistryUrlFromApplicationSettings < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def change - remove_column :application_settings, :snowplow_iglu_registry_url, :string, limit: 255 - end -end diff --git a/db/post_migrate/20200922095954_remove_instance_statistics_visibility_private_from_application_settings.rb b/db/post_migrate/20200922095954_remove_instance_statistics_visibility_private_from_application_settings.rb deleted file mode 100644 index 1d01e54013d..00000000000 --- a/db/post_migrate/20200922095954_remove_instance_statistics_visibility_private_from_application_settings.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class RemoveInstanceStatisticsVisibilityPrivateFromApplicationSettings < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - remove_column :application_settings, :instance_statistics_visibility_private - end - - def down - add_column :application_settings, :instance_statistics_visibility_private, :boolean, default: false, null: false - end -end diff --git a/db/post_migrate/20200922170907_change_index_on_pipeline_status.rb b/db/post_migrate/20200922170907_change_index_on_pipeline_status.rb deleted file mode 100644 index 61648788d7f..00000000000 --- a/db/post_migrate/20200922170907_change_index_on_pipeline_status.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class ChangeIndexOnPipelineStatus < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - OLD_INDEX_NAME = 'index_ci_pipelines_on_status' - NEW_INDEX_NAME = 'index_ci_pipelines_on_status_and_id' - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_pipelines, [:status, :id], name: NEW_INDEX_NAME - remove_concurrent_index_by_name :ci_pipelines, name: OLD_INDEX_NAME - end - - def down - add_concurrent_index :ci_pipelines, :status, name: OLD_INDEX_NAME - remove_concurrent_index_by_name :ci_pipelines, name: NEW_INDEX_NAME - end -end diff --git a/db/post_migrate/20200922231755_remove_created_by_user_id_from_cluster_providers_aws.rb b/db/post_migrate/20200922231755_remove_created_by_user_id_from_cluster_providers_aws.rb deleted file mode 100644 index 02cc9676202..00000000000 --- a/db/post_migrate/20200922231755_remove_created_by_user_id_from_cluster_providers_aws.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class RemoveCreatedByUserIdFromClusterProvidersAws < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_cluster_providers_aws_on_created_by_user_id' - - disable_ddl_transaction! - - def up - with_lock_retries do - remove_column :cluster_providers_aws, :created_by_user_id - end - end - - def down - unless column_exists?(:cluster_providers_aws, :created_by_user_id) - add_column :cluster_providers_aws, :created_by_user_id, :integer - end - - add_concurrent_index :cluster_providers_aws, :created_by_user_id, name: INDEX_NAME - - add_concurrent_foreign_key :cluster_providers_aws, :users, column: :created_by_user_id, on_delete: :nullify - end -end diff --git a/db/post_migrate/20200929052138_create_initial_versions_for_pre_versioning_terraform_states.rb b/db/post_migrate/20200929052138_create_initial_versions_for_pre_versioning_terraform_states.rb deleted file mode 100644 index eff6ebfe5b4..00000000000 --- a/db/post_migrate/20200929052138_create_initial_versions_for_pre_versioning_terraform_states.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class CreateInitialVersionsForPreVersioningTerraformStates < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - execute <<-SQL - INSERT INTO terraform_state_versions (terraform_state_id, created_at, updated_at, version, file_store, file) - SELECT id, NOW(), NOW(), 0, file_store, file - FROM terraform_states - WHERE versioning_enabled = FALSE - ON CONFLICT (terraform_state_id, version) DO NOTHING - SQL - end - - def down - end -end diff --git a/db/post_migrate/20200929113254_remove_type_from_audit_events.rb b/db/post_migrate/20200929113254_remove_type_from_audit_events.rb deleted file mode 100644 index 000dc0d2865..00000000000 --- a/db/post_migrate/20200929113254_remove_type_from_audit_events.rb +++ /dev/null @@ -1,125 +0,0 @@ -# frozen_string_literal: true - -class RemoveTypeFromAuditEvents < ActiveRecord::Migration[6.0] - include Gitlab::Database::SchemaHelpers - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - SOURCE_TABLE_NAME = 'audit_events' - PARTITIONED_TABLE_NAME = 'audit_events_part_5fc467ac26' - TRIGGER_FUNCTION_NAME = 'table_sync_function_2be879775d' - - def up - with_lock_retries do - remove_column SOURCE_TABLE_NAME, :type - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - target_type = NEW.target_type, - target_id = NEW.target_id, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - entity_id, - entity_type, - details, - ip_address, - author_name, - entity_path, - target_details, - target_type, - target_id, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.target_type, - NEW.target_id, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - - remove_column PARTITIONED_TABLE_NAME, :type - end - end - - def down - with_lock_retries do - add_column SOURCE_TABLE_NAME, :type, :string - add_column PARTITIONED_TABLE_NAME, :type, :string - - create_trigger_function(TRIGGER_FUNCTION_NAME, replace: true) do - <<~SQL - IF (TG_OP = 'DELETE') THEN - DELETE FROM #{PARTITIONED_TABLE_NAME} where id = OLD.id; - ELSIF (TG_OP = 'UPDATE') THEN - UPDATE #{PARTITIONED_TABLE_NAME} - SET author_id = NEW.author_id, - type = NEW.type, - entity_id = NEW.entity_id, - entity_type = NEW.entity_type, - details = NEW.details, - ip_address = NEW.ip_address, - author_name = NEW.author_name, - entity_path = NEW.entity_path, - target_details = NEW.target_details, - target_type = NEW.target_type, - target_id = NEW.target_id, - created_at = NEW.created_at - WHERE #{PARTITIONED_TABLE_NAME}.id = NEW.id; - ELSIF (TG_OP = 'INSERT') THEN - INSERT INTO #{PARTITIONED_TABLE_NAME} (id, - author_id, - type, - entity_id, - entity_type, - details, - ip_address, - author_name, - entity_path, - target_details, - target_type, - target_id, - created_at) - VALUES (NEW.id, - NEW.author_id, - NEW.type, - NEW.entity_id, - NEW.entity_type, - NEW.details, - NEW.ip_address, - NEW.author_name, - NEW.entity_path, - NEW.target_details, - NEW.target_type, - NEW.target_id, - NEW.created_at); - END IF; - RETURN NULL; - SQL - end - end - end -end diff --git a/db/post_migrate/20200929114107_schedule_migrate_u2f_webauthn.rb b/db/post_migrate/20200929114107_schedule_migrate_u2f_webauthn.rb deleted file mode 100644 index b118ed271a2..00000000000 --- a/db/post_migrate/20200929114107_schedule_migrate_u2f_webauthn.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class ScheduleMigrateU2fWebauthn < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - INTERVAL = 2.minutes.to_i - DOWNTIME = false - MIGRATION = 'MigrateU2fWebauthn' - BATCH_SIZE = 1_000 - - disable_ddl_transaction! - - class U2fRegistration < ActiveRecord::Base - include EachBatch - - self.table_name = 'u2f_registrations' - end - - def up - say "Scheduling #{MIGRATION} background migration jobs" - - queue_background_migration_jobs_by_range_at_intervals(U2fRegistration, MIGRATION, INTERVAL, batch_size: BATCH_SIZE) - end - - def down - # no-op - # There is no real way back here, because - # a) The U2fMigrator of webauthn_ruby gem only works in one way - # b) This migration only pushes jobs to Sidekiq - end -end diff --git a/db/post_migrate/20200930144340_set_job_waiter_ttl.rb b/db/post_migrate/20200930144340_set_job_waiter_ttl.rb deleted file mode 100644 index 347fa4be5a0..00000000000 --- a/db/post_migrate/20200930144340_set_job_waiter_ttl.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class SetJobWaiterTtl < ActiveRecord::Migration[6.0] - DOWNTIME = false - - SCRIPT = <<~LUA - if redis.call("ttl", KEYS[1]) < 0 then - redis.call("expire", KEYS[1], 21600) - end - LUA - - def up - Gitlab::Redis::SharedState.with do |redis| - cursor_init = '0' - cursor = cursor_init - - loop do - cursor, keys = redis.scan(cursor, match: 'gitlab:job_waiter:*') - - redis.pipelined do |redis| - keys.each { |k| redis.eval(SCRIPT, keys: [k]) } - end - - break if cursor == cursor_init - end - end - end - - def down - end -end diff --git a/db/post_migrate/20201001022100_validate_designs_filename_text_limit.rb b/db/post_migrate/20201001022100_validate_designs_filename_text_limit.rb deleted file mode 100644 index 35ed8c20671..00000000000 --- a/db/post_migrate/20201001022100_validate_designs_filename_text_limit.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class ValidateDesignsFilenameTextLimit < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - DOWNTIME = false - - disable_ddl_transaction! - - def up - validate_text_limit :design_management_designs, :filename - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201001101136_remove_index_on_issues_relative_position.rb b/db/post_migrate/20201001101136_remove_index_on_issues_relative_position.rb deleted file mode 100644 index 605a167c0d5..00000000000 --- a/db/post_migrate/20201001101136_remove_index_on_issues_relative_position.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class RemoveIndexOnIssuesRelativePosition < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - INDEX_NAME = 'index_issues_on_relative_position' - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name(:issues, INDEX_NAME) - end - - def down - add_concurrent_index(:issues, :relative_position, name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20201002094617_remove_container_scanning_report_type_index.rb b/db/post_migrate/20201002094617_remove_container_scanning_report_type_index.rb deleted file mode 100644 index a591fc185c4..00000000000 --- a/db/post_migrate/20201002094617_remove_container_scanning_report_type_index.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class RemoveContainerScanningReportTypeIndex < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'idx_container_scanning_findings' - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name(:vulnerability_occurrences, INDEX_NAME) - end - - def down - # report_type: 2 container scanning - add_concurrent_index( - :vulnerability_occurrences, - :id, - where: 'report_type = 2', - name: INDEX_NAME - ) - end -end diff --git a/db/post_migrate/20201002175953_add_index_for_merged_merge_requests.rb b/db/post_migrate/20201002175953_add_index_for_merged_merge_requests.rb deleted file mode 100644 index cd663f3da89..00000000000 --- a/db/post_migrate/20201002175953_add_index_for_merged_merge_requests.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class AddIndexForMergedMergeRequests < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'idx_merge_requests_on_merged_state' - - disable_ddl_transaction! - - def up - add_concurrent_index :merge_requests, - :id, - where: 'state_id = 3', - name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :merge_requests, INDEX_NAME - end -end diff --git a/db/post_migrate/20201005094331_migrate_compliance_framework_enum_to_database_framework_record.rb b/db/post_migrate/20201005094331_migrate_compliance_framework_enum_to_database_framework_record.rb deleted file mode 100644 index a5fab8576e4..00000000000 --- a/db/post_migrate/20201005094331_migrate_compliance_framework_enum_to_database_framework_record.rb +++ /dev/null @@ -1,102 +0,0 @@ -# frozen_string_literal: true - -class MigrateComplianceFrameworkEnumToDatabaseFrameworkRecord < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class TmpComplianceFramework < ActiveRecord::Base - self.table_name = 'compliance_management_frameworks' - end - - class TmpProjectSettings < ActiveRecord::Base - # Maps data between ComplianceManagement::ComplianceFramework::FRAMEWORKS(enum) and new ComplianceManagement::Framework model - ENUM_FRAMEWORK_MAPPING = { - 1 => { - name: 'GDPR', - description: 'General Data Protection Regulation', - color: '#1aaa55' - }.freeze, - 2 => { - name: 'HIPAA', - description: 'Health Insurance Portability and Accountability Act', - color: '#1f75cb' - }.freeze, - 3 => { - name: 'PCI-DSS', - description: 'Payment Card Industry-Data Security Standard', - color: '#6666c4' - }.freeze, - 4 => { - name: 'SOC 2', - description: 'Service Organization Control 2', - color: '#dd2b0e' - }.freeze, - 5 => { - name: 'SOX', - description: 'Sarbanes-Oxley', - color: '#fc9403' - }.freeze - }.freeze - - self.table_name = 'project_compliance_framework_settings' - - include EachBatch - - def raw_compliance_framework - # Because we have an `enum` definition in ComplianceManagement::ComplianceFramework::ProjectSettings, this is very unlikely to fail. - ENUM_FRAMEWORK_MAPPING.fetch(framework).merge(namespace_id: root_namespace_id) - end - end - - def up - TmpComplianceFramework.reset_column_information - TmpProjectSettings.reset_column_information - - # This is our standard recursive namespace query, we use it to determine the root_namespace_id in the same query. - lateral_join = <<~SQL - INNER JOIN LATERAL ( - WITH RECURSIVE "base_and_ancestors" AS ( - ( - SELECT "ns".* FROM "namespaces" as ns WHERE "ns"."id" = projects.namespace_id - ) UNION - ( - SELECT "ns".* FROM "namespaces" as ns, "base_and_ancestors" WHERE "ns"."id" = "base_and_ancestors"."parent_id" - ) - ) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE parent_id IS NULL LIMIT 1) AS root_namespaces ON TRUE - SQL - - TmpProjectSettings.each_batch(of: 100) do |query| - project_settings_with_root_group = query - .select(:project_id, :framework, 'root_namespaces.id as root_namespace_id') - .from("(SELECT * FROM project_compliance_framework_settings) as project_compliance_framework_settings") # this is needed for the LATERAL JOIN - .joins("INNER JOIN projects on projects.id = project_compliance_framework_settings.project_id") - .joins(lateral_join) - .to_a - - ActiveRecord::Base.transaction do - raw_frameworks = project_settings_with_root_group.map(&:raw_compliance_framework) - TmpComplianceFramework.insert_all(raw_frameworks.uniq) # Create compliance frameworks per group - - unique_namespace_ids = project_settings_with_root_group.map(&:root_namespace_id).uniq - - framework_records = TmpComplianceFramework.select(:id, :namespace_id, :name).where(namespace_id: unique_namespace_ids) - - project_settings_with_root_group.each do |project_setting| - framework = framework_records.find do |record| - # name is unique within a group - record.name == project_setting.raw_compliance_framework[:name] && record[:namespace_id] == project_setting.raw_compliance_framework[:namespace_id] - end - - project_setting.update_column(:framework_id, framework.id) - end - end - end - end - - def down - # data migration, no-op - end -end diff --git a/db/post_migrate/20201005153955_add_not_null_constraint_to_compliance_project_settings.rb b/db/post_migrate/20201005153955_add_not_null_constraint_to_compliance_project_settings.rb deleted file mode 100644 index 6d47cbe9f08..00000000000 --- a/db/post_migrate/20201005153955_add_not_null_constraint_to_compliance_project_settings.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullConstraintToComplianceProjectSettings < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint(:project_compliance_framework_settings, :framework_id) - - change_column_null(:compliance_management_frameworks, :namespace_id, false) - end - - def down - change_column_null(:compliance_management_frameworks, :namespace_id, true) - - remove_not_null_constraint(:project_compliance_framework_settings, :framework_id) - end -end diff --git a/db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb b/db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb deleted file mode 100644 index 30a8ea591da..00000000000 --- a/db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -require 'set' - -class ScheduleSyncBlockingIssuesCount < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - BATCH_SIZE = 50 - DELAY_INTERVAL = 120.seconds.to_i - MIGRATION = 'SyncBlockingIssuesCount' - - disable_ddl_transaction! - - class TmpIssueLink < ActiveRecord::Base - self.table_name = 'issue_links' - - include EachBatch - end - - def up - return unless Gitlab.ee? - - issue_link_ids = SortedSet.new - - TmpIssueLink.distinct.select(:source_id).where(link_type: 1).each_batch(of: 1000, column: :source_id) do |query| - issue_link_ids.merge(query.pluck(:source_id)) - end - - TmpIssueLink.distinct.select(:target_id).where(link_type: 2).each_batch(of: 1000, column: :target_id) do |query| - issue_link_ids.merge(query.pluck(:target_id)) - end - - issue_link_ids.each_slice(BATCH_SIZE).with_index do |items, index| - start_id, *, end_id = items - - arguments = [start_id, end_id] - - final_delay = DELAY_INTERVAL * (index + 1) - migrate_in(final_delay, MIGRATION, arguments) - end - end - - def down - # NO OP - end -end diff --git a/db/post_migrate/20201015073808_schedule_blocked_by_links_replacement.rb b/db/post_migrate/20201015073808_schedule_blocked_by_links_replacement.rb deleted file mode 100644 index dd8cbb57136..00000000000 --- a/db/post_migrate/20201015073808_schedule_blocked_by_links_replacement.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class ScheduleBlockedByLinksReplacement < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 2.minutes - # at the time of writing there were 47600 blocked_by issues: - # estimated time is 48 batches * 2 minutes -> 100 minutes - BATCH_SIZE = 1000 - MIGRATION = 'ReplaceBlockedByLinks' - - disable_ddl_transaction! - - class IssueLink < ActiveRecord::Base - include EachBatch - - self.table_name = 'issue_links' - end - - def up - # no-op - # superseded by db/post_migrate/20201102073808_schedule_blocked_by_links_replacement_second_try.rb - end - - def down - end -end diff --git a/db/post_migrate/20201015154527_add_index_on_services_for_usage_data.rb b/db/post_migrate/20201015154527_add_index_on_services_for_usage_data.rb deleted file mode 100644 index f85ab97420b..00000000000 --- a/db/post_migrate/20201015154527_add_index_on_services_for_usage_data.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnServicesForUsageData < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_services_on_type_id_when_active_and_project_id_not_null' - - disable_ddl_transaction! - - def up - add_concurrent_index :services, [:type, :id], where: 'active = TRUE AND project_id IS NOT NULL', name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :services, INDEX_NAME - end -end diff --git a/db/post_migrate/20201019094741_rename_sitemap_root_namespaces.rb b/db/post_migrate/20201019094741_rename_sitemap_root_namespaces.rb deleted file mode 100644 index 20812a53bfb..00000000000 --- a/db/post_migrate/20201019094741_rename_sitemap_root_namespaces.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class RenameSitemapRootNamespaces < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - include Gitlab::Database::RenameReservedPathsMigration::V1 - - DOWNTIME = false - - disable_ddl_transaction! - - # We're taking over the /sitemap.xml and /sitemap.xml.gz namespaces - # since they're necessary for the default behavior of Sitemaps - def up - disable_statement_timeout do - rename_root_paths(['sitemap.xml', 'sitemap.xml.gz']) - end - end - - def down - disable_statement_timeout do - revert_renames - end - end -end diff --git a/db/post_migrate/20201020102551_remove_index_service_for_usage_data.rb b/db/post_migrate/20201020102551_remove_index_service_for_usage_data.rb deleted file mode 100644 index a0d39ecd2c1..00000000000 --- a/db/post_migrate/20201020102551_remove_index_service_for_usage_data.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class RemoveIndexServiceForUsageData < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_services_on_type_id_when_active_not_instance_not_template' - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name :services, INDEX_NAME - end - - def down - add_concurrent_index :services, [:type, :id], where: 'active = TRUE AND instance = FALSE AND template = FALSE', name: INDEX_NAME - end -end diff --git a/db/post_migrate/20201026051643_remove_scanned_resources_count_from_security_scans.rb b/db/post_migrate/20201026051643_remove_scanned_resources_count_from_security_scans.rb deleted file mode 100644 index 208448e2278..00000000000 --- a/db/post_migrate/20201026051643_remove_scanned_resources_count_from_security_scans.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class RemoveScannedResourcesCountFromSecurityScans < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - remove_column :security_scans, :scanned_resources_count - end - - def down - add_column :security_scans, :scanned_resources_count, :integer - end -end diff --git a/db/post_migrate/20201026182253_schedule_populate_vulnerability_feedback_pipeline_id.rb b/db/post_migrate/20201026182253_schedule_populate_vulnerability_feedback_pipeline_id.rb deleted file mode 100644 index 2df475ab2a8..00000000000 --- a/db/post_migrate/20201026182253_schedule_populate_vulnerability_feedback_pipeline_id.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateVulnerabilityFeedbackPipelineId < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 2.minutes.to_i - BATCH_SIZE = 100 - MIGRATION = 'PopulateVulnerabilityFeedbackPipelineId' - - disable_ddl_transaction! - - def up - return unless Gitlab.ee? - - vulnerability_feedback = exec_query <<~SQL - SELECT DISTINCT "vulnerability_feedback"."project_id" - FROM "vulnerability_feedback" - WHERE "vulnerability_feedback"."pipeline_id" IS NULL - ORDER BY "vulnerability_feedback"."project_id" ASC - SQL - - return if vulnerability_feedback.rows.blank? - - vulnerability_feedback.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |project_ids, index| - migrate_in(index * INTERVAL, MIGRATION, [project_ids]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201026185514_ensure_u2f_registrations_migrated.rb b/db/post_migrate/20201026185514_ensure_u2f_registrations_migrated.rb deleted file mode 100644 index bb1ac3dee4c..00000000000 --- a/db/post_migrate/20201026185514_ensure_u2f_registrations_migrated.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class EnsureU2fRegistrationsMigrated < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - BACKGROUND_MIGRATION_CLASS = 'MigrateU2fWebauthn' - BATCH_SIZE = 100 - DOWNTIME = false - - disable_ddl_transaction! - - class U2fRegistration < ActiveRecord::Base - include EachBatch - - self.table_name = 'u2f_registrations' - end - - def up - Gitlab::BackgroundMigration.steal(BACKGROUND_MIGRATION_CLASS) - - # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low. - U2fRegistration - .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 (we can't "unsteal" migrations) - end -end diff --git a/db/post_migrate/20201028160832_schedule_populate_missing_dismissal_information_for_vulnerabilities.rb b/db/post_migrate/20201028160832_schedule_populate_missing_dismissal_information_for_vulnerabilities.rb deleted file mode 100644 index f358ea863db..00000000000 --- a/db/post_migrate/20201028160832_schedule_populate_missing_dismissal_information_for_vulnerabilities.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateMissingDismissalInformationForVulnerabilities < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - DELAY_INTERVAL = 3.minutes.to_i - MIGRATION_CLASS = 'PopulateMissingVulnerabilityDismissalInformation' - - disable_ddl_transaction! - - def up - ::Gitlab::BackgroundMigration::PopulateMissingVulnerabilityDismissalInformation::Vulnerability.broken.each_batch(of: BATCH_SIZE) do |batch, index| - vulnerability_ids = batch.pluck(:id) - migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, vulnerability_ids) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201028182809_backfill_jira_tracker_deployment_type2.rb b/db/post_migrate/20201028182809_backfill_jira_tracker_deployment_type2.rb deleted file mode 100644 index 63a0554433c..00000000000 --- a/db/post_migrate/20201028182809_backfill_jira_tracker_deployment_type2.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class BackfillJiraTrackerDeploymentType2 < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'BackfillJiraTrackerDeploymentType2' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 1000 - - disable_ddl_transaction! - - class JiraTrackerData < ActiveRecord::Base - include EachBatch - - self.table_name = 'jira_tracker_data' - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - JiraTrackerData.where(deployment_type: 0), - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - track_jobs: true) - end - - def down - # NOOP - end -end diff --git a/db/post_migrate/20201029052241_migrate_geo_blob_verification_primary_worker_sidekiq_queue.rb b/db/post_migrate/20201029052241_migrate_geo_blob_verification_primary_worker_sidekiq_queue.rb deleted file mode 100644 index 64d22863389..00000000000 --- a/db/post_migrate/20201029052241_migrate_geo_blob_verification_primary_worker_sidekiq_queue.rb +++ /dev/null @@ -1,18 +0,0 @@ -# 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 MigrateGeoBlobVerificationPrimaryWorkerSidekiqQueue < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'geo:geo_blob_verification_primary', to: 'geo:geo_verification' - end - - def down - sidekiq_queue_migrate 'geo:geo_verification', to: 'geo:geo_blob_verification_primary' - end -end diff --git a/db/post_migrate/20201029144157_cleanup_application_settings_to_allow_deny_rename.rb b/db/post_migrate/20201029144157_cleanup_application_settings_to_allow_deny_rename.rb deleted file mode 100644 index bb6fe4258c5..00000000000 --- a/db/post_migrate/20201029144157_cleanup_application_settings_to_allow_deny_rename.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class CleanupApplicationSettingsToAllowDenyRename < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :application_settings, :domain_blacklist_enabled, :domain_denylist_enabled - cleanup_concurrent_column_rename :application_settings, :domain_blacklist, :domain_denylist - cleanup_concurrent_column_rename :application_settings, :domain_whitelist, :domain_allowlist - end - - def down - undo_cleanup_concurrent_column_rename :application_settings, :domain_blacklist_enabled, :domain_denylist_enabled - undo_cleanup_concurrent_column_rename :application_settings, :domain_blacklist, :domain_denylist - undo_cleanup_concurrent_column_rename :application_settings, :domain_whitelist, :domain_allowlist - end -end diff --git a/db/post_migrate/20201030121314_schedule_update_existing_users_that_require_two_factor_auth.rb b/db/post_migrate/20201030121314_schedule_update_existing_users_that_require_two_factor_auth.rb deleted file mode 100644 index 6a031c28ed7..00000000000 --- a/db/post_migrate/20201030121314_schedule_update_existing_users_that_require_two_factor_auth.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# # frozen_string_literal: true - -class ScheduleUpdateExistingUsersThatRequireTwoFactorAuth < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'UpdateExistingUsersThatRequireTwoFactorAuth' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 1000 - INDEX_NAME = 'index_users_on_require_two_factor_authentication_from_group' - - disable_ddl_transaction! - - class User < ActiveRecord::Base - include EachBatch - - self.table_name = 'users' - end - - def up - add_concurrent_index :users, - :require_two_factor_authentication_from_group, - where: 'require_two_factor_authentication_from_group = TRUE', - name: INDEX_NAME - - relation = User.where(require_two_factor_authentication_from_group: true) - - queue_background_migration_jobs_by_range_at_intervals( - relation, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end - - def down - remove_concurrent_index_by_name :users, INDEX_NAME - end -end diff --git a/db/post_migrate/20201030203854_backfill_design_iids.rb b/db/post_migrate/20201030203854_backfill_design_iids.rb deleted file mode 100644 index 7acca6ad93d..00000000000 --- a/db/post_migrate/20201030203854_backfill_design_iids.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class BackfillDesignIids < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Designs < ActiveRecord::Base - include EachBatch - - self.table_name = 'design_management_designs' - end - - def up - backfill = ::Gitlab::BackgroundMigration::BackfillDesignInternalIds.new(Designs) - - Designs.select(:project_id).distinct.each_batch(of: 100, column: :project_id) do |relation| - backfill.perform(relation) - end - end - - def down - # NOOP - end -end diff --git a/db/post_migrate/20201102073808_schedule_blocked_by_links_replacement_second_try.rb b/db/post_migrate/20201102073808_schedule_blocked_by_links_replacement_second_try.rb deleted file mode 100644 index 217d4f81d26..00000000000 --- a/db/post_migrate/20201102073808_schedule_blocked_by_links_replacement_second_try.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class ScheduleBlockedByLinksReplacementSecondTry < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 2.minutes - # at the time of writing there were 12931 blocked_by issues: - # estimated time is 13 batches * 2 minutes -> 26 minutes - BATCH_SIZE = 1000 - MIGRATION = 'ReplaceBlockedByLinks' - - disable_ddl_transaction! - - class IssueLink < ActiveRecord::Base - include EachBatch - - self.table_name = 'issue_links' - end - - def up - relation = IssueLink.where(link_type: 2) - - queue_background_migration_jobs_by_range_at_intervals( - relation, MIGRATION, INTERVAL, batch_size: BATCH_SIZE) - end - - def down - end -end diff --git a/db/post_migrate/20201102112206_rename_sitemap_namespace.rb b/db/post_migrate/20201102112206_rename_sitemap_namespace.rb deleted file mode 100644 index b2e610d68db..00000000000 --- a/db/post_migrate/20201102112206_rename_sitemap_namespace.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class RenameSitemapNamespace < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - include Gitlab::Database::RenameReservedPathsMigration::V1 - - DOWNTIME = false - - disable_ddl_transaction! - - # We're taking over the /sitemap namespace - # since it's necessary for the default behavior of Sitemaps - def up - disable_statement_timeout do - rename_root_paths(['sitemap']) - end - end - - def down - disable_statement_timeout do - revert_renames - end - end -end diff --git a/db/post_migrate/20201102114018_remove_storage_size_limit_from_application_settings.rb b/db/post_migrate/20201102114018_remove_storage_size_limit_from_application_settings.rb deleted file mode 100644 index 6646cf2ad0c..00000000000 --- a/db/post_migrate/20201102114018_remove_storage_size_limit_from_application_settings.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class RemoveStorageSizeLimitFromApplicationSettings < ActiveRecord::Migration[6.0] - DOWNTIME = false - - def up - remove_column :application_settings, :namespace_storage_size_limit - end - - def down - add_column :application_settings, :namespace_storage_size_limit, :bigint, default: 0 - end -end diff --git a/db/post_migrate/20201102152554_add_not_null_check_on_iid_on_design_manangement_designs.rb b/db/post_migrate/20201102152554_add_not_null_check_on_iid_on_design_manangement_designs.rb deleted file mode 100644 index 861a0c3c27a..00000000000 --- a/db/post_migrate/20201102152554_add_not_null_check_on_iid_on_design_manangement_designs.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddNotNullCheckOnIidOnDesignManangementDesigns < ActiveRecord::Migration[6.0] - include ::Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_not_null_constraint(:design_management_designs, :iid) - end - - def down - remove_not_null_constraint(:design_management_designs, :iid) - end -end diff --git a/db/post_migrate/20201102152945_truncate_security_findings_table.rb b/db/post_migrate/20201102152945_truncate_security_findings_table.rb deleted file mode 100644 index 8bfaa31f0de..00000000000 --- a/db/post_migrate/20201102152945_truncate_security_findings_table.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class TruncateSecurityFindingsTable < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - return unless Gitlab.dev_env_or_com? - - with_lock_retries do - connection.execute('TRUNCATE security_findings RESTART IDENTITY') - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201103013242_remove_terraform_state_verification_columns.rb b/db/post_migrate/20201103013242_remove_terraform_state_verification_columns.rb deleted file mode 100644 index b1cd9790ead..00000000000 --- a/db/post_migrate/20201103013242_remove_terraform_state_verification_columns.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class RemoveTerraformStateVerificationColumns < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - transaction do - remove_column :terraform_states, :verification_retry_at, :datetime_with_timezone - remove_column :terraform_states, :verified_at, :datetime_with_timezone - remove_column :terraform_states, :verification_retry_count, :integer, limit: 2 - remove_column :terraform_states, :verification_checksum, :binary, using: 'verification_checksum::bytea' - remove_column :terraform_states, :verification_failure, :text - end - end - - def down - add_column(:terraform_states, :verification_retry_at, :datetime_with_timezone) unless column_exists?(:terraform_states, :verification_retry_at) - add_column(:terraform_states, :verified_at, :datetime_with_timezone) unless column_exists?(:terraform_states, :verified_at) - add_column(:terraform_states, :verification_retry_count, :integer, limit: 2) unless column_exists?(:terraform_states, :verification_retry_count) - add_column(:terraform_states, :verification_checksum, :binary, using: 'verification_checksum::bytea') unless column_exists?(:terraform_states, :verification_checksum) - add_column(:terraform_states, :verification_failure, :text) unless column_exists?(:terraform_states, :verification_failure) - - add_text_limit :terraform_states, :verification_failure, 255 - end -end diff --git a/db/post_migrate/20201103110018_schedule_merge_request_cleanup_schedules_backfill.rb b/db/post_migrate/20201103110018_schedule_merge_request_cleanup_schedules_backfill.rb deleted file mode 100644 index 77057205b09..00000000000 --- a/db/post_migrate/20201103110018_schedule_merge_request_cleanup_schedules_backfill.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class ScheduleMergeRequestCleanupSchedulesBackfill < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'BackfillMergeRequestCleanupSchedules' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 10_000 - TEMP_INDEX_NAME = 'merge_requests_state_id_temp_index' - - disable_ddl_transaction! - - def up - add_concurrent_index :merge_requests, :id, name: TEMP_INDEX_NAME, where: "state_id IN (2, 3)" - - eligible_mrs = Gitlab::BackgroundMigration::BackfillMergeRequestCleanupSchedules::MergeRequest.eligible - - queue_background_migration_jobs_by_range_at_intervals( - eligible_mrs, - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - end - - def down - remove_concurrent_index_by_name :merge_requests, TEMP_INDEX_NAME - end -end diff --git a/db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb b/db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb deleted file mode 100644 index bed90af09dc..00000000000 --- a/db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateHasVulnerabilities < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - DELAY_INTERVAL = 2.minutes - MIGRATION_CLASS = 'PopulateHasVulnerabilities' - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration::PopulateHasVulnerabilities::Vulnerability.distinct.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index| - project_ids = batch.pluck(:project_id) - - migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, project_ids) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb b/db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb deleted file mode 100644 index 08f92d21f44..00000000000 --- a/db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -class EnsureNamespaceSettingsCreation < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10000 - MIGRATION = 'BackfillNamespaceSettings' - DELAY_INTERVAL = 2.minutes.to_i - - disable_ddl_transaction! - - class Namespace < ActiveRecord::Base - include EachBatch - - self.table_name = 'namespaces' - end - - def up - ensure_data_migration - end - - def down - # no-op - end - - private - - def ensure_data_migration - Namespace.each_batch(of: BATCH_SIZE) do |query, index| - missing_count = query.where("NOT EXISTS (SELECT 1 FROM namespace_settings WHERE namespace_settings.namespace_id=namespaces.id)").limit(1).size - - if missing_count > 0 - ids_range = query.pluck("MIN(id), MAX(id)").flatten - - migrate_in(index * DELAY_INTERVAL, MIGRATION, ids_range) - end - end - end -end diff --git a/db/post_migrate/20201106082723_add_merge_request_jira_reference_indexes.rb b/db/post_migrate/20201106082723_add_merge_request_jira_reference_indexes.rb deleted file mode 100644 index d69f57c6088..00000000000 --- a/db/post_migrate/20201106082723_add_merge_request_jira_reference_indexes.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -class AddMergeRequestJiraReferenceIndexes < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - DESCRIPTION_INDEX_NAME = 'index_merge_requests_on_target_project_id_iid_jira_description' - TITLE_INDEX_NAME = 'index_merge_requests_on_target_project_id_and_iid_jira_title' - - JIRA_KEY_REGEX = '[A-Z][A-Z_0-9]+-\d+' - - disable_ddl_transaction! - - def up - add_concurrent_index( - :merge_requests, - [:target_project_id, :iid], - name: TITLE_INDEX_NAME, - using: :btree, - where: "(merge_requests.title)::text ~ '#{JIRA_KEY_REGEX}'::text" - ) - - add_concurrent_index( - :merge_requests, - [:target_project_id, :iid], - name: DESCRIPTION_INDEX_NAME, - using: :btree, - where: "(merge_requests.description)::text ~ '#{JIRA_KEY_REGEX}'::text" - ) - end - - def down - remove_concurrent_index_by_name( - :merge_requests, - TITLE_INDEX_NAME - ) - - remove_concurrent_index_by_name( - :merge_requests, - DESCRIPTION_INDEX_NAME - ) - end -end diff --git a/db/post_migrate/20201106134950_deduplicate_epic_iids.rb b/db/post_migrate/20201106134950_deduplicate_epic_iids.rb deleted file mode 100644 index 8fddc81057b..00000000000 --- a/db/post_migrate/20201106134950_deduplicate_epic_iids.rb +++ /dev/null @@ -1,121 +0,0 @@ -# frozen_string_literal: true - -class DeduplicateEpicIids < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_epics_on_group_id_and_iid' - - disable_ddl_transaction! - - class Epic < ActiveRecord::Base - end - - class InternalId < ActiveRecord::Base - class << self - def generate_next(subject, scope, usage, init) - InternalIdGenerator.new(subject, scope, usage, init).generate - end - end - - # Increments #last_value and saves the record - # - # The operation locks the record and gathers a `ROW SHARE` lock (in PostgreSQL). - # As such, the increment is atomic and safe to be called concurrently. - def increment_and_save! - update_and_save { self.last_value = (last_value || 0) + 1 } - end - - private - - def update_and_save(&block) - lock! - yield - save! - last_value - end - end - - # See app/models/internal_id - class InternalIdGenerator - attr_reader :subject, :scope, :scope_attrs, :usage, :init - - def initialize(subject, scope, usage, init = nil) - @subject = subject - @scope = scope - @usage = usage - @init = init - - raise ArgumentError, 'Scope is not well-defined, need at least one column for scope (given: 0)' if scope.empty? || usage.to_s != 'epics' - end - - # Generates next internal id and returns it - # init: Block that gets called to initialize InternalId record if not present - # Make sure to not throw exceptions in the absence of records (if this is expected). - def generate - subject.transaction do - # Create a record in internal_ids if one does not yet exist - # and increment its last value - # - # Note this will acquire a ROW SHARE lock on the InternalId record - record.increment_and_save! - end - end - - def record - @record ||= (lookup || create_record) - end - - def lookup - InternalId.find_by(**scope, usage: usage_value) - end - - def usage_value - 4 # see Enums::InternalId - this is the value for epics - end - - # Create InternalId record for (scope, usage) combination, if it doesn't exist - # - # We blindly insert without synchronization. If another process - # was faster in doing this, we'll realize once we hit the unique key constraint - # violation. We can safely roll-back the nested transaction and perform - # a lookup instead to retrieve the record. - def create_record - raise ArgumentError, 'Cannot initialize without init!' unless init - - instance = subject.is_a?(::Class) ? nil : subject - - subject.transaction(requires_new: true) do # rubocop:disable Performance/ActiveRecordSubtransactions - InternalId.create!( - **scope, - usage: usage_value, - last_value: init.call(instance, scope) || 0 - ) - end - rescue ActiveRecord::RecordNotUnique - lookup - end - end - - def up - duplicate_epic_ids = ApplicationRecord.connection.execute('SELECT iid, group_id, COUNT(*) FROM epics GROUP BY iid, group_id HAVING COUNT(*) > 1;') - - duplicate_epic_ids.each do |dup| - Epic.where(iid: dup['iid'], group_id: dup['group_id']).last(dup['count'] - 1).each do |epic| - new_iid = InternalId.generate_next(epic, - { namespace_id: epic.group_id }, - :epics, ->(instance, _) { instance.class.where(group_id: epic.group_id).maximum(:iid) } - ) - - epic.update!(iid: new_iid) - end - end - - add_concurrent_index :epics, [:group_id, :iid], unique: true, name: INDEX_NAME - end - - def down - # only remove the index, as we do not want to create the duplicates back - remove_concurrent_index :epics, [:group_id, :iid], name: INDEX_NAME - end -end diff --git a/db/post_migrate/20201109114603_schedule_remove_inaccessible_epic_todos.rb b/db/post_migrate/20201109114603_schedule_remove_inaccessible_epic_todos.rb deleted file mode 100644 index 13d12675a28..00000000000 --- a/db/post_migrate/20201109114603_schedule_remove_inaccessible_epic_todos.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRemoveInaccessibleEpicTodos < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 2.minutes - BATCH_SIZE = 10 - MIGRATION = 'RemoveInaccessibleEpicTodos' - - disable_ddl_transaction! - - class Epic < ActiveRecord::Base - include EachBatch - end - - def up - return unless Gitlab.ee? - - relation = Epic.where(confidential: true) - - queue_background_migration_jobs_by_range_at_intervals( - relation, MIGRATION, INTERVAL, batch_size: BATCH_SIZE) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201110161542_cleanup_transfered_projects_shared_runners.rb b/db/post_migrate/20201110161542_cleanup_transfered_projects_shared_runners.rb deleted file mode 100644 index 5e907092e83..00000000000 --- a/db/post_migrate/20201110161542_cleanup_transfered_projects_shared_runners.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class CleanupTransferedProjectsSharedRunners < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 25_000 - INTERVAL = 3.minutes - MIGRATION = 'ResetSharedRunnersForTransferredProjects' - - disable_ddl_transaction! - - class Namespace < ActiveRecord::Base - include EachBatch - - self.table_name = 'namespaces' - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Namespace, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - # This migration fixes an inconsistent database state resulting from https://gitlab.com/gitlab-org/gitlab/-/issues/271728 - # and as such does not require a down migration - end -end diff --git a/db/post_migrate/20201112130710_schedule_remove_duplicate_vulnerabilities_findings.rb b/db/post_migrate/20201112130710_schedule_remove_duplicate_vulnerabilities_findings.rb deleted file mode 100644 index d05516bd255..00000000000 --- a/db/post_migrate/20201112130710_schedule_remove_duplicate_vulnerabilities_findings.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRemoveDuplicateVulnerabilitiesFindings < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - INDEX_NAME = 'tmp_idx_deduplicate_vulnerability_occurrences' - - 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 - add_concurrent_index :vulnerability_occurrences, - %i[project_id report_type location_fingerprint primary_identifier_id id], - name: INDEX_NAME - - say "Scheduling #{MIGRATION} jobs" - queue_background_migration_jobs_by_range_at_intervals( - VulnerabilitiesFinding, - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - end - - def down - remove_concurrent_index_by_name(:vulnerability_occurrences, INDEX_NAME) - 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 deleted file mode 100644 index 7bb97a39bda..00000000000 --- a/db/post_migrate/20201112130715_schedule_recalculate_uuid_on_vulnerabilities_occurrences.rb +++ /dev/null @@ -1,37 +0,0 @@ -# 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/20201112145311_add_index_on_sha_for_initial_deployments.rb b/db/post_migrate/20201112145311_add_index_on_sha_for_initial_deployments.rb deleted file mode 100644 index 15debddb9cc..00000000000 --- a/db/post_migrate/20201112145311_add_index_on_sha_for_initial_deployments.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnShaForInitialDeployments < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - NEW_INDEX_NAME = 'index_deployments_on_environment_status_sha' - OLD_INDEX_NAME = 'index_deployments_on_environment_id_and_status' - - disable_ddl_transaction! - - def up - add_concurrent_index :deployments, %i[environment_id status sha], name: NEW_INDEX_NAME - remove_concurrent_index_by_name :deployments, OLD_INDEX_NAME - end - - def down - add_concurrent_index :deployments, %i[environment_id status], name: OLD_INDEX_NAME - remove_concurrent_index_by_name :services, NEW_INDEX_NAME - end -end diff --git a/db/post_migrate/20201113105000_update_index_secure_for_api_fuzzing_telemetry.rb b/db/post_migrate/20201113105000_update_index_secure_for_api_fuzzing_telemetry.rb deleted file mode 100644 index 9e8313f79f8..00000000000 --- a/db/post_migrate/20201113105000_update_index_secure_for_api_fuzzing_telemetry.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class UpdateIndexSecureForApiFuzzingTelemetry < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - OLD_SECURE_INDEX_NAME = 'index_secure_ci_builds_on_user_id_created_at_parser_features' - NEW_SECURE_INDEX_NAME = 'index_secure_ci_builds_on_user_id_name_created_at' - - def up - add_concurrent_index(:ci_builds, - [:user_id, :name, :created_at], - where: "(((type)::text = 'Ci::Build'::text) AND ((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, ('dast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('license_management'::character varying)::text, ('license_scanning'::character varying)::text, ('sast'::character varying)::text, ('coverage_fuzzing'::character varying)::text, ('apifuzzer_fuzz'::character varying)::text, ('apifuzzer_fuzz_dnd'::character varying)::text, ('secret_detection'::character varying)::text])))", - name: NEW_SECURE_INDEX_NAME) - remove_concurrent_index_by_name :ci_builds, OLD_SECURE_INDEX_NAME - end - - def down - add_concurrent_index(:ci_builds, - [:user_id, :created_at], - where: "(((type)::text = 'Ci::Build'::text) AND ((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, ('dast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('license_management'::character varying)::text, ('license_scanning'::character varying)::text, ('sast'::character varying)::text, ('secret_detection'::character varying)::text])))", - name: OLD_SECURE_INDEX_NAME) - remove_concurrent_index_by_name :ci_builds, NEW_SECURE_INDEX_NAME - end -end diff --git a/db/post_migrate/20201119092319_schedule_repopulate_historical_vulnerability_statistics.rb b/db/post_migrate/20201119092319_schedule_repopulate_historical_vulnerability_statistics.rb deleted file mode 100644 index 598cc4d93d0..00000000000 --- a/db/post_migrate/20201119092319_schedule_repopulate_historical_vulnerability_statistics.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRepopulateHistoricalVulnerabilityStatistics < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 50 - DELAY_INTERVAL = 5.minutes - MIGRATION_CLASS = 'PopulateVulnerabilityHistoricalStatistics' - DAY_COUNT = 365 - - disable_ddl_transaction! - - class ProjectSetting < ActiveRecord::Base - include EachBatch - - self.table_name = 'project_settings' - - scope :has_vulnerabilities, -> { where('has_vulnerabilities IS TRUE') } - end - - def up - ProjectSetting.has_vulnerabilities.each_batch(of: BATCH_SIZE) do |batch, index| - migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, [batch.pluck(:project_id), DAY_COUNT]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201120071303_drop_feature_filter_type_from_user_preferences.rb b/db/post_migrate/20201120071303_drop_feature_filter_type_from_user_preferences.rb deleted file mode 100644 index b00ea0aba76..00000000000 --- a/db/post_migrate/20201120071303_drop_feature_filter_type_from_user_preferences.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class DropFeatureFilterTypeFromUserPreferences < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - with_lock_retries do - remove_column :user_preferences, :feature_filter_type - end - end - - def down - with_lock_retries do - add_column :user_preferences, :feature_filter_type, :bigint - end - end -end diff --git a/db/post_migrate/20201120140210_add_runner_id_and_id_desc_index_to_ci_builds.rb b/db/post_migrate/20201120140210_add_runner_id_and_id_desc_index_to_ci_builds.rb deleted file mode 100644 index 5eda0e25dbe..00000000000 --- a/db/post_migrate/20201120140210_add_runner_id_and_id_desc_index_to_ci_builds.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class AddRunnerIdAndIdDescIndexToCiBuilds < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - NEW_INDEX = 'index_ci_builds_on_runner_id_and_id_desc' - OLD_INDEX = 'index_ci_builds_on_runner_id' - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_builds, %i[runner_id id], name: NEW_INDEX, order: { id: :desc } - remove_concurrent_index_by_name :ci_builds, OLD_INDEX - end - - def down - add_concurrent_index :ci_builds, %i[runner_id], name: OLD_INDEX - remove_concurrent_index_by_name :ci_builds, NEW_INDEX - end -end diff --git a/db/post_migrate/20201124122817_populate_remaining_missing_dismissal_information_for_vulnerabilities.rb b/db/post_migrate/20201124122817_populate_remaining_missing_dismissal_information_for_vulnerabilities.rb deleted file mode 100644 index 9dc41d17231..00000000000 --- a/db/post_migrate/20201124122817_populate_remaining_missing_dismissal_information_for_vulnerabilities.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class PopulateRemainingMissingDismissalInformationForVulnerabilities < ActiveRecord::Migration[6.0] - DOWNTIME = false - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal('PopulateMissingVulnerabilityDismissalInformation') - - ::Gitlab::BackgroundMigration::PopulateMissingVulnerabilityDismissalInformation::Vulnerability.broken.each_batch(of: 100) do |batch, index| - vulnerability_ids = batch.pluck(:id) - - ::Gitlab::BackgroundMigration::PopulateMissingVulnerabilityDismissalInformation.new.perform(*vulnerability_ids) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201124185639_remove_unused_indexes.rb b/db/post_migrate/20201124185639_remove_unused_indexes.rb deleted file mode 100644 index c4b0d8a84cc..00000000000 --- a/db/post_migrate/20201124185639_remove_unused_indexes.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class RemoveUnusedIndexes < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name :packages_package_files, "packages_packages_verification_failure_partial" - remove_concurrent_index_by_name :packages_package_files, "packages_packages_verification_checksum_partial" - remove_concurrent_index_by_name :snippet_repositories, 'snippet_repositories_verification_failure_partial' - remove_concurrent_index_by_name :snippet_repositories, 'snippet_repositories_verification_checksum_partial' - remove_concurrent_index_by_name :terraform_state_versions, 'terraform_state_versions_verification_failure_partial' - remove_concurrent_index_by_name :terraform_state_versions, 'terraform_state_versions_verification_checksum_partial' - end - - def down - add_concurrent_index :packages_package_files, :verification_failure, where: "(verification_failure IS NOT NULL)", name: "packages_packages_verification_failure_partial" - add_concurrent_index :packages_package_files, :verification_checksum, where: "(verification_checksum IS NOT NULL)", name: "packages_packages_verification_checksum_partial" - add_concurrent_index :snippet_repositories, :verification_failure, where: "(verification_failure IS NOT NULL)", name: 'snippet_repositories_verification_failure_partial' - add_concurrent_index :snippet_repositories, :verification_checksum, where: "(verification_checksum IS NOT NULL)", name: 'snippet_repositories_verification_checksum_partial' - add_concurrent_index :terraform_state_versions, :verification_failure, where: "(verification_failure IS NOT NULL)", name: 'terraform_state_versions_verification_failure_partial' - add_concurrent_index :terraform_state_versions, :verification_checksum, where: "(verification_checksum IS NOT NULL)", name: 'terraform_state_versions_verification_checksum_partial' - end -end diff --git a/db/post_migrate/20201128210234_schedule_populate_issue_email_participants.rb b/db/post_migrate/20201128210234_schedule_populate_issue_email_participants.rb deleted file mode 100644 index 6fea683944c..00000000000 --- a/db/post_migrate/20201128210234_schedule_populate_issue_email_participants.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateIssueEmailParticipants < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - DELAY_INTERVAL = 2.minutes - MIGRATION = 'PopulateIssueEmailParticipants' - - disable_ddl_transaction! - - class Issue < ActiveRecord::Base - include EachBatch - - self.table_name = 'issues' - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - Issue.where.not(service_desk_reply_to: nil), - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201130103926_schedule_populate_dismissed_state_for_vulnerabilities.rb b/db/post_migrate/20201130103926_schedule_populate_dismissed_state_for_vulnerabilities.rb deleted file mode 100644 index 5e8da532251..00000000000 --- a/db/post_migrate/20201130103926_schedule_populate_dismissed_state_for_vulnerabilities.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -class SchedulePopulateDismissedStateForVulnerabilities < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - TMP_INDEX_NAME = 'tmp_index_on_vulnerabilities_non_dismissed' - - DOWNTIME = false - BATCH_SIZE = 1_000 - VULNERABILITY_BATCH_SIZE = 5_000 - DELAY_INTERVAL = 3.minutes.to_i - MIGRATION_CLASS = 'PopulateDismissedStateForVulnerabilities' - - VULNERABILITY_JOIN_CONDITION = 'JOIN "vulnerability_occurrences" ON "vulnerability_occurrences"."vulnerability_id" = "vulnerabilities"."id"' - FEEDBACK_WHERE_CONDITION = <<~SQL - EXISTS (SELECT 1 FROM vulnerability_feedback - WHERE "vulnerability_occurrences"."project_id" = "vulnerability_feedback"."project_id" - AND "vulnerability_occurrences"."report_type" = "vulnerability_feedback"."category" - AND ENCODE("vulnerability_occurrences"."project_fingerprint", 'hex') = "vulnerability_feedback"."project_fingerprint" - AND "vulnerability_feedback"."feedback_type" = 0 - ) - SQL - - class Vulnerability < ActiveRecord::Base # rubocop:disable Style/Documentation - include EachBatch - - self.table_name = 'vulnerabilities' - end - - disable_ddl_transaction! - - def up - add_concurrent_index(:vulnerabilities, :id, where: 'state <> 2', name: TMP_INDEX_NAME) - - batch = [] - index = 1 - - Vulnerability.where('state <> 2').each_batch(of: VULNERABILITY_BATCH_SIZE) do |relation| - ids = relation - .joins(VULNERABILITY_JOIN_CONDITION) - .where(FEEDBACK_WHERE_CONDITION) - .pluck('vulnerabilities.id') - - ids.each do |id| - batch << id - - if batch.size == BATCH_SIZE - migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, batch) - index += 1 - - batch.clear - end - end - end - - migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, batch) unless batch.empty? - end - - def down - remove_concurrent_index_by_name(:vulnerabilities, TMP_INDEX_NAME) - end -end diff --git a/db/post_migrate/20201203123201_remove_orphan_service_hooks.rb b/db/post_migrate/20201203123201_remove_orphan_service_hooks.rb deleted file mode 100644 index c430e2205c2..00000000000 --- a/db/post_migrate/20201203123201_remove_orphan_service_hooks.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class RemoveOrphanServiceHooks < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - class WebHook < ActiveRecord::Base - include EachBatch - - self.table_name = 'web_hooks' - - def self.service_hooks - where(type: 'ServiceHook') - end - end - - class Service < ActiveRecord::Base - self.table_name = 'services' - end - - def up - WebHook.service_hooks.where.not(service_id: Service.select(:id)).where.not(service_id: nil).each_batch do |relation| - relation.delete_all - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20201207151651_truncate_security_findings_table_2.rb b/db/post_migrate/20201207151651_truncate_security_findings_table_2.rb deleted file mode 100644 index 2ac6941be6d..00000000000 --- a/db/post_migrate/20201207151651_truncate_security_findings_table_2.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -require_relative Rails.root.join('db', 'post_migrate', '20201102152945_truncate_security_findings_table.rb') - -# This is the second time we are truncating this table -# so the migration class name has choosen like this for this reason. -class TruncateSecurityFindingsTable2 < TruncateSecurityFindingsTable; end diff --git a/db/post_migrate/20201207165956_remove_duplicate_services.rb b/db/post_migrate/20201207165956_remove_duplicate_services.rb deleted file mode 100644 index 1659b9a2095..00000000000 --- a/db/post_migrate/20201207165956_remove_duplicate_services.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicateServices < ActiveRecord::Migration[6.0] - DOWNTIME = false - - disable_ddl_transaction! - - def up - # noop, replaced by 20210112143418_remove_duplicate_services.rb - end - - def down - end -end diff --git a/db/post_migrate/20201208175117_schedule_backfilling_artifact_expiry_migration.rb b/db/post_migrate/20201208175117_schedule_backfilling_artifact_expiry_migration.rb deleted file mode 100644 index 56db148afe6..00000000000 --- a/db/post_migrate/20201208175117_schedule_backfilling_artifact_expiry_migration.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -class ScheduleBackfillingArtifactExpiryMigration < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - SWITCH_DATE = Time.utc(2020, 6, 22).freeze - INDEX_NAME = 'expired_artifacts_temp_index' - INDEX_CONDITION = "expire_at IS NULL AND created_at < '#{SWITCH_DATE}'" - - disable_ddl_transaction! - - class JobArtifact < ActiveRecord::Base - include EachBatch - - self.table_name = 'ci_job_artifacts' - - scope :without_expiry_date, -> { where(expire_at: nil) } - scope :before_switch, -> { where('created_at < ?', SWITCH_DATE) } - end - - def up - # Create temporary index for expired artifacts - # Needs to be removed in a later migration - add_concurrent_index(:ci_job_artifacts, %i(id created_at), where: INDEX_CONDITION, name: INDEX_NAME) - - # queue_background_migration_jobs_by_range_at_intervals( - # JobArtifact.without_expiry_date.before_switch, - # ::Gitlab::BackgroundMigration::BackfillArtifactExpiryDate, - # 2.minutes, - # batch_size: 200_000 - # ) - # The scheduling code was using the full class symbol - # (`::Gitlab::BackgroundMigration::BackfillArtifactExpiryDate`) instead of a - # string with the class name (`BackfillArtifactExpiryDate`) by mistake, - # which resulted in an error. It is commented out so it's a no-op to prevent - # errors and will be reintroduced with - # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51822. - end - - def down - remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME - end -end diff --git a/db/post_migrate/20210622041846_finalize_push_event_payloads_bigint_conversion.rb b/db/post_migrate/20210622041846_finalize_push_event_payloads_bigint_conversion.rb index 38b081e3e5e..f37c446f66c 100644 --- a/db/post_migrate/20210622041846_finalize_push_event_payloads_bigint_conversion.rb +++ b/db/post_migrate/20210622041846_finalize_push_event_payloads_bigint_conversion.rb @@ -49,7 +49,7 @@ class FinalizePushEventPayloadsBigintConversion < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:event_id, :event_id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:event_id, :event_id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb b/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb index b99a61e8e63..715bc392c68 100644 --- a/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb +++ b/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb @@ -60,7 +60,7 @@ class FinalizeEventsBigintConversion < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:id, :id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:id, :id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210701033622_finalize_ci_builds_needs_bigint_conversion.rb b/db/post_migrate/20210701033622_finalize_ci_builds_needs_bigint_conversion.rb index baee9fb3848..89a39660a04 100644 --- a/db/post_migrate/20210701033622_finalize_ci_builds_needs_bigint_conversion.rb +++ b/db/post_migrate/20210701033622_finalize_ci_builds_needs_bigint_conversion.rb @@ -47,7 +47,7 @@ class FinalizeCiBuildsNeedsBigintConversion < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:build_id, :build_id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb b/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb index a8a9fe037ec..161366590be 100644 --- a/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb +++ b/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb @@ -46,7 +46,7 @@ class FinalizeCiBuildsStageIdBigintConversion < ActiveRecord::Migration[6.1] execute "ALTER TABLE #{quoted_table_name} RENAME COLUMN #{quote_column_name(temporary_name)} TO #{quote_column_name(:stage_id_convert_to_bigint)}" # Reset the function so PG drops the plan cache for the incorrect integer type - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection) .name([:id, :stage_id], [:id_convert_to_bigint, :stage_id_convert_to_bigint]) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" diff --git a/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb b/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb index 40977277bd1..11045348672 100644 --- a/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb +++ b/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb @@ -58,7 +58,7 @@ class FinalizeCiJobArtifactsBigintConversion < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name([:id, :job_id], [:id_convert_to_bigint, :job_id_convert_to_bigint]) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name([:id, :job_id], [:id_convert_to_bigint, :job_id_convert_to_bigint]) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb b/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb index 2e294a0b2e3..dbefbeb26cb 100644 --- a/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb +++ b/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb @@ -53,7 +53,7 @@ class FinalizeCiStagesBigintConversion < ActiveRecord::Migration[6.1] execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_convert_to_bigint_name} TO #{id_name}" execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{temp_name} TO #{id_convert_to_bigint_name}" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:id, :id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:id, :id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb b/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb index f75df04ba48..c2444ccbc6c 100644 --- a/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb +++ b/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb @@ -53,8 +53,8 @@ class FinalizeCiBuildsMetadataBigintConversion < Gitlab::Database::Migration[1.0 # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - execute "ALTER FUNCTION #{quote_table_name(Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:id, :id_convert_to_bigint))} RESET ALL" - execute "ALTER FUNCTION #{quote_table_name(Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:build_id, :build_id_convert_to_bigint))} RESET ALL" + execute "ALTER FUNCTION #{quote_table_name(Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:id, :id_convert_to_bigint))} RESET ALL" + execute "ALTER FUNCTION #{quote_table_name(Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint))} RESET ALL" # Swap defaults for PK execute "ALTER SEQUENCE ci_builds_metadata_id_seq OWNED BY #{TABLE_NAME}.id" diff --git a/db/post_migrate/20210713042153_finalize_ci_sources_pipelines_bigint_conversion.rb b/db/post_migrate/20210713042153_finalize_ci_sources_pipelines_bigint_conversion.rb index 938c8c172a3..38b7852b320 100644 --- a/db/post_migrate/20210713042153_finalize_ci_sources_pipelines_bigint_conversion.rb +++ b/db/post_migrate/20210713042153_finalize_ci_sources_pipelines_bigint_conversion.rb @@ -47,7 +47,7 @@ class FinalizeCiSourcesPipelinesBigintConversion < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:source_job_id, :source_job_id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:source_job_id, :source_job_id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # No need to swap defaults, both columns have no default value diff --git a/db/post_migrate/20210714015537_finalize_ci_build_trace_chunks_bigint_conversion.rb b/db/post_migrate/20210714015537_finalize_ci_build_trace_chunks_bigint_conversion.rb index 9195b662776..af17b35d47d 100644 --- a/db/post_migrate/20210714015537_finalize_ci_build_trace_chunks_bigint_conversion.rb +++ b/db/post_migrate/20210714015537_finalize_ci_build_trace_chunks_bigint_conversion.rb @@ -45,7 +45,7 @@ class FinalizeCiBuildTraceChunksBigintConversion < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:build_id, :build_id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210722155635_finalize_convert_geo_job_artifact_deleted_events_bigint.rb b/db/post_migrate/20210722155635_finalize_convert_geo_job_artifact_deleted_events_bigint.rb index 7d3809a9dbe..5bf6a9e7911 100644 --- a/db/post_migrate/20210722155635_finalize_convert_geo_job_artifact_deleted_events_bigint.rb +++ b/db/post_migrate/20210722155635_finalize_convert_geo_job_artifact_deleted_events_bigint.rb @@ -44,7 +44,7 @@ class FinalizeConvertGeoJobArtifactDeletedEventsBigint < ActiveRecord::Migration change_column_default TABLE_NAME, COLUMN_NAME, nil change_column_default TABLE_NAME, COLUMN_NAME_CONVERTED, 0 - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(COLUMN_NAME, COLUMN_NAME_CONVERTED) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(COLUMN_NAME, COLUMN_NAME_CONVERTED) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" execute "DROP INDEX #{old_index_name}" diff --git a/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb b/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb index 4b825ae72ba..6dab29e10d4 100644 --- a/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb +++ b/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb @@ -61,7 +61,7 @@ class FinalizePushEventPayloadsBigintConversion3 < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:event_id, :event_id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:event_id, :event_id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210802131812_finalize_convert_deployments_bigint.rb b/db/post_migrate/20210802131812_finalize_convert_deployments_bigint.rb index 31afb7e0a29..067b7166cf3 100644 --- a/db/post_migrate/20210802131812_finalize_convert_deployments_bigint.rb +++ b/db/post_migrate/20210802131812_finalize_convert_deployments_bigint.rb @@ -35,7 +35,7 @@ class FinalizeConvertDeploymentsBigint < ActiveRecord::Migration[6.1] execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(COLUMN_NAME_BIGINT)} TO #{quote_column_name(COLUMN_NAME)}" execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(COLUMN_NAME_BIGINT)}" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(COLUMN_NAME, COLUMN_NAME_BIGINT) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(COLUMN_NAME, COLUMN_NAME_BIGINT) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" execute "DROP INDEX #{old_index_name}" diff --git a/db/post_migrate/20210805131510_finalize_ci_builds_runner_session_bigint_conversion.rb b/db/post_migrate/20210805131510_finalize_ci_builds_runner_session_bigint_conversion.rb index 9706f0036f3..5e18450f465 100644 --- a/db/post_migrate/20210805131510_finalize_ci_builds_runner_session_bigint_conversion.rb +++ b/db/post_migrate/20210805131510_finalize_ci_builds_runner_session_bigint_conversion.rb @@ -44,7 +44,7 @@ class FinalizeCiBuildsRunnerSessionBigintConversion < ActiveRecord::Migration[6. # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:build_id, :build_id_convert_to_bigint) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210806131706_finalize_taggins_bigint_conversion.rb b/db/post_migrate/20210806131706_finalize_taggins_bigint_conversion.rb index bd76466d43a..5f094e48ed4 100644 --- a/db/post_migrate/20210806131706_finalize_taggins_bigint_conversion.rb +++ b/db/post_migrate/20210806131706_finalize_taggins_bigint_conversion.rb @@ -60,7 +60,7 @@ class FinalizeTagginsBigintConversion < ActiveRecord::Migration[6.1] # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name([:id, :taggable_id], [:id_convert_to_bigint, :taggable_id_convert_to_bigint]) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name([:id, :taggable_id], [:id_convert_to_bigint, :taggable_id_convert_to_bigint]) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210809143931_finalize_job_id_conversion_to_bigint_for_ci_job_artifacts.rb b/db/post_migrate/20210809143931_finalize_job_id_conversion_to_bigint_for_ci_job_artifacts.rb index bb12045b1de..5cec6fa30b8 100644 --- a/db/post_migrate/20210809143931_finalize_job_id_conversion_to_bigint_for_ci_job_artifacts.rb +++ b/db/post_migrate/20210809143931_finalize_job_id_conversion_to_bigint_for_ci_job_artifacts.rb @@ -55,7 +55,7 @@ class FinalizeJobIdConversionToBigintForCiJobArtifacts < ActiveRecord::Migration # We need to update the trigger function in order to make PostgreSQL to # regenerate the execution plan for it. This is to avoid type mismatch errors like # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name([:id, :job_id], [:id_convert_to_bigint, :job_id_convert_to_bigint]) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name([:id, :job_id], [:id_convert_to_bigint, :job_id_convert_to_bigint]) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" # Swap defaults diff --git a/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb b/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb index 0a0fda7e870..f63645b4ffa 100644 --- a/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb +++ b/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb @@ -42,7 +42,7 @@ class PrepareCiBuildsMetadataAndCiBuildAsyncIndexes < ActiveRecord::Migration[6. return if index_name_exists?(table_name, index_name) - async_index = Gitlab::Database::AsyncIndexes::PostgresAsyncIndex.safe_find_or_create_by!(name: index_name) do |rec| + async_index = Gitlab::Database::AsyncIndexes::PostgresAsyncIndex.find_or_create_by!(name: index_name) do |rec| rec.table_name = table_name rec.definition = definition end diff --git a/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb b/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb index 02f98833703..7544842c196 100644 --- a/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb +++ b/db/post_migrate/20210907211557_finalize_ci_builds_bigint_conversion.rb @@ -136,7 +136,7 @@ class FinalizeCiBuildsBigintConversion < Gitlab::Database::Migration[1.0] execute "ALTER TABLE #{quoted_table_name} RENAME COLUMN #{quote_column_name(temporary_name)} TO #{quote_column_name(:id_convert_to_bigint)}" # Reset the function so PG drops the plan cache for the incorrect integer type - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME) + function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection) .name([:id, :stage_id], [:id_convert_to_bigint, :stage_id_convert_to_bigint]) execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" diff --git a/db/post_migrate/20210923192648_remove_foreign_keys_from_open_project_data_table.rb b/db/post_migrate/20210923192648_remove_foreign_keys_from_open_project_data_table.rb new file mode 100644 index 00000000000..1da5aad0fab --- /dev/null +++ b/db/post_migrate/20210923192648_remove_foreign_keys_from_open_project_data_table.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveForeignKeysFromOpenProjectDataTable < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key :open_project_tracker_data, column: :service_id + end + end + + def down + with_lock_retries do + add_foreign_key :open_project_tracker_data, :integrations, column: :service_id, on_delete: :cascade + end + end +end diff --git a/db/post_migrate/20210923192649_remove_open_project_data_table.rb b/db/post_migrate/20210923192649_remove_open_project_data_table.rb new file mode 100644 index 00000000000..252d7e07261 --- /dev/null +++ b/db/post_migrate/20210923192649_remove_open_project_data_table.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class RemoveOpenProjectDataTable < Gitlab::Database::Migration[1.0] + def up + drop_table :open_project_tracker_data + end + + def down + create_table :open_project_tracker_data do |t| + t.integer :service_id, index: { name: 'index_open_project_tracker_data_on_service_id' }, null: false + t.timestamps_with_timezone + t.string :encrypted_url, limit: 255 + t.string :encrypted_url_iv, limit: 255 + t.string :encrypted_api_url, limit: 255 + t.string :encrypted_api_url_iv, limit: 255 + t.string :encrypted_token, limit: 255 + t.string :encrypted_token_iv, limit: 255 + t.string :closed_status_id, limit: 5 + t.string :project_identifier_code, limit: 100 + end + end +end diff --git a/db/post_migrate/20210930211936_backfill_user_namespace.rb b/db/post_migrate/20210930211936_backfill_user_namespace.rb new file mode 100644 index 00000000000..c5dd170f18e --- /dev/null +++ b/db/post_migrate/20210930211936_backfill_user_namespace.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class BackfillUserNamespace < Gitlab::Database::Migration[1.0] + MIGRATION = 'BackfillUserNamespace' + INTERVAL = 2.minutes + BATCH_SIZE = 1_000 + SUB_BATCH_SIZE = 200 + DOWNTIME = false + + def up + queue_batched_background_migration( + MIGRATION, + :namespaces, + :id, + job_interval: INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + Gitlab::Database::BackgroundMigration::BatchedMigration + .for_configuration(MIGRATION, :namespaces, :id, []) + .delete_all + end +end diff --git a/db/post_migrate/20211004120135_schedule_add_primary_email_to_emails_if_user_confirmed.rb b/db/post_migrate/20211004120135_schedule_add_primary_email_to_emails_if_user_confirmed.rb new file mode 100644 index 00000000000..d7b213b384a --- /dev/null +++ b/db/post_migrate/20211004120135_schedule_add_primary_email_to_emails_if_user_confirmed.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class ScheduleAddPrimaryEmailToEmailsIfUserConfirmed < Gitlab::Database::Migration[1.0] + INTERVAL = 2.minutes.to_i + BATCH_SIZE = 10_000 + MIGRATION = 'AddPrimaryEmailToEmailsIfUserConfirmed' + + disable_ddl_transaction! + + class User < ActiveRecord::Base + include ::EachBatch + + self.table_name = 'users' + self.inheritance_column = :_type_disabled + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + User, + MIGRATION, + INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # intentionally blank + end +end diff --git a/db/post_migrate/20211005194425_schedule_requirements_migration.rb b/db/post_migrate/20211005194425_schedule_requirements_migration.rb new file mode 100644 index 00000000000..56211989b8e --- /dev/null +++ b/db/post_migrate/20211005194425_schedule_requirements_migration.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class ScheduleRequirementsMigration < Gitlab::Database::Migration[1.0] + DOWNTIME = false + + # 2021-10-05 requirements count: ~12500 + # + # Using 30 as batch size and 120 seconds default interval will produce: + # ~420 jobs - taking ~14 hours to perform + BATCH_SIZE = 30 + + MIGRATION = 'MigrateRequirementsToWorkItems' + + disable_ddl_transaction! + + class Requirement < ActiveRecord::Base + include EachBatch + + self.table_name = 'requirements' + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + Requirement.where(issue_id: nil), + MIGRATION, + 2.minutes, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # NO OP + end +end diff --git a/db/post_migrate/20211011104843_add_new_loose_fk_index.rb b/db/post_migrate/20211011104843_add_new_loose_fk_index.rb new file mode 100644 index 00000000000..710d0917d7f --- /dev/null +++ b/db/post_migrate/20211011104843_add_new_loose_fk_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddNewLooseFkIndex < Gitlab::Database::Migration[1.0] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_loose_foreign_keys_deleted_records_for_loading_records' + + def up + add_concurrent_partitioned_index :loose_foreign_keys_deleted_records, + %I[fully_qualified_table_name id primary_key_value partition], + where: 'status = 1', + name: INDEX_NAME + end + + def down + remove_concurrent_partitioned_index_by_name :loose_foreign_keys_deleted_records, INDEX_NAME + end +end diff --git a/db/post_migrate/20211012051221_add_index_btree_namespaces_traversal_ids.rb b/db/post_migrate/20211012051221_add_index_btree_namespaces_traversal_ids.rb new file mode 100644 index 00000000000..882351ab974 --- /dev/null +++ b/db/post_migrate/20211012051221_add_index_btree_namespaces_traversal_ids.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexBtreeNamespacesTraversalIds < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_btree_namespaces_traversal_ids' + + disable_ddl_transaction! + + def up + add_concurrent_index :namespaces, :traversal_ids, using: :btree, name: INDEX_NAME + end + + def down + remove_concurrent_index :namespaces, :traversal_ids, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211012143815_remove_merge_request_diff_commit_columns.rb b/db/post_migrate/20211012143815_remove_merge_request_diff_commit_columns.rb new file mode 100644 index 00000000000..80ed834903c --- /dev/null +++ b/db/post_migrate/20211012143815_remove_merge_request_diff_commit_columns.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class RemoveMergeRequestDiffCommitColumns < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + COLUMNS = %i[author_name author_email committer_name committer_email].freeze + + def change + COLUMNS.each do |column| + remove_column(:merge_request_diff_commits, column, :text) + end + end +end diff --git a/db/post_migrate/20211013125341_create_index_security_ci_builds_on_name_and_id_parser_features.rb b/db/post_migrate/20211013125341_create_index_security_ci_builds_on_name_and_id_parser_features.rb new file mode 100644 index 00000000000..2efbfad6c56 --- /dev/null +++ b/db/post_migrate/20211013125341_create_index_security_ci_builds_on_name_and_id_parser_features.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class CreateIndexSecurityCiBuildsOnNameAndIdParserFeatures < Gitlab::Database::Migration[1.0] + TABLE = "ci_builds" + COLUMNS = %i[name id] + INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features" + CONSTRAINTS = "(name::text = ANY (ARRAY['container_scanning'::character varying::text, + 'dast'::character varying::text, + 'dependency_scanning'::character varying::text, + 'license_management'::character varying::text, + 'sast'::character varying::text, + 'secret_detection'::character varying::text, + 'coverage_fuzzing'::character varying::text, + 'license_scanning'::character varying::text]) + ) AND type::text = 'Ci::Build'::text" + + disable_ddl_transaction! + + def up + add_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS) + end + + def down + remove_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS) + end +end diff --git a/db/post_migrate/20211018101552_add_index_to_tmp_project_id_column_on_namespaces_table.rb b/db/post_migrate/20211018101552_add_index_to_tmp_project_id_column_on_namespaces_table.rb new file mode 100644 index 00000000000..b50b7fa21a5 --- /dev/null +++ b/db/post_migrate/20211018101552_add_index_to_tmp_project_id_column_on_namespaces_table.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexToTmpProjectIdColumnOnNamespacesTable < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'tmp_index_on_tmp_project_id_on_namespaces' + + def up + add_concurrent_index :namespaces, :tmp_project_id, name: INDEX_NAME, unique: true + end + + def down + remove_concurrent_index_by_name :namespaces, INDEX_NAME + end +end diff --git a/db/post_migrate/20211018101852_add_fk_to_tmp_project_id_column_on_namespaces_table.rb b/db/post_migrate/20211018101852_add_fk_to_tmp_project_id_column_on_namespaces_table.rb new file mode 100644 index 00000000000..f2772389d02 --- /dev/null +++ b/db/post_migrate/20211018101852_add_fk_to_tmp_project_id_column_on_namespaces_table.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddFkToTmpProjectIdColumnOnNamespacesTable < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :namespaces, :projects, column: :tmp_project_id + end + + def down + remove_foreign_key :namespaces, column: :tmp_project_id + end +end diff --git a/db/post_migrate/20211018102252_add_index_to_group_id_column_on_webhooks_table.rb b/db/post_migrate/20211018102252_add_index_to_group_id_column_on_webhooks_table.rb new file mode 100644 index 00000000000..d5fac373ca4 --- /dev/null +++ b/db/post_migrate/20211018102252_add_index_to_group_id_column_on_webhooks_table.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexToGroupIdColumnOnWebhooksTable < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_on_group_id_on_webhooks' + + def up + add_concurrent_index :web_hooks, :group_id, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :web_hooks, INDEX_NAME + end +end diff --git a/db/post_migrate/20211018123316_remove_not_null_constraint_and_default_for_public_email.rb b/db/post_migrate/20211018123316_remove_not_null_constraint_and_default_for_public_email.rb new file mode 100644 index 00000000000..72a5970b6d7 --- /dev/null +++ b/db/post_migrate/20211018123316_remove_not_null_constraint_and_default_for_public_email.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveNotNullConstraintAndDefaultForPublicEmail < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def up + change_column_null :users, :public_email, true + change_column_default :users, :public_email, from: '', to: nil + end + + def down + # There may now be nulls in the table, so we cannot re-add the constraint here. + change_column_default :users, :public_email, from: nil, to: '' + end +end diff --git a/db/post_migrate/20211018152654_schedule_remove_duplicate_vulnerabilities_findings3.rb b/db/post_migrate/20211018152654_schedule_remove_duplicate_vulnerabilities_findings3.rb new file mode 100644 index 00000000000..ecad4466c53 --- /dev/null +++ b/db/post_migrate/20211018152654_schedule_remove_duplicate_vulnerabilities_findings3.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class ScheduleRemoveDuplicateVulnerabilitiesFindings3 < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'RemoveDuplicateVulnerabilitiesFindings' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 5_000 + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('vulnerability_occurrences'), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211021131217_add_deployments_environment_id_and_ref_index.rb b/db/post_migrate/20211021131217_add_deployments_environment_id_and_ref_index.rb new file mode 100644 index 00000000000..8014c006f35 --- /dev/null +++ b/db/post_migrate/20211021131217_add_deployments_environment_id_and_ref_index.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddDeploymentsEnvironmentIdAndRefIndex < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_deployments_on_environment_id_and_ref' + + disable_ddl_transaction! + + def up + add_concurrent_index :deployments, [:environment_id, :ref], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :deployments, INDEX_NAME + end +end diff --git a/db/post_migrate/20211021140426_remove_geo_upload_deprecated_fields.rb b/db/post_migrate/20211021140426_remove_geo_upload_deprecated_fields.rb new file mode 100644 index 00000000000..7d0033c0ab9 --- /dev/null +++ b/db/post_migrate/20211021140426_remove_geo_upload_deprecated_fields.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class RemoveGeoUploadDeprecatedFields < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_column :geo_event_log, :upload_deleted_event_id, :bigint + end + end + + def down + with_lock_retries do + add_column(:geo_event_log, :upload_deleted_event_id, :bigint) unless column_exists?(:geo_event_log, :upload_deleted_event_id) + end + + add_concurrent_foreign_key :geo_event_log, :geo_upload_deleted_events, + column: :upload_deleted_event_id, + name: 'fk_c1f241c70d', + on_delete: :cascade + + add_concurrent_index :geo_event_log, + :upload_deleted_event_id, + name: 'index_geo_event_log_on_upload_deleted_event_id', + where: "(upload_deleted_event_id IS NOT NULL)" + end +end diff --git a/db/post_migrate/20211021141930_drop_geo_upload_deleted_events_table.rb b/db/post_migrate/20211021141930_drop_geo_upload_deleted_events_table.rb new file mode 100644 index 00000000000..b6987e68fb1 --- /dev/null +++ b/db/post_migrate/20211021141930_drop_geo_upload_deleted_events_table.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DropGeoUploadDeletedEventsTable < Gitlab::Database::Migration[1.0] + def up + drop_table :geo_upload_deleted_events + end + + def down + create_table :geo_upload_deleted_events, id: :bigserial do |t| + t.integer :upload_id, null: false, index: true + t.string :file_path, null: false + t.integer :model_id, null: false + t.string :model_type, null: false + t.string :uploader, null: false + end + end +end diff --git a/db/post_migrate/20211022112202_add_cluster_id_location_index_to_vulnerability_occurrences.rb b/db/post_migrate/20211022112202_add_cluster_id_location_index_to_vulnerability_occurrences.rb new file mode 100644 index 00000000000..9c40e81f527 --- /dev/null +++ b/db/post_migrate/20211022112202_add_cluster_id_location_index_to_vulnerability_occurrences.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddClusterIdLocationIndexToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_vulnerability_occurrences_on_location_cluster_id' + + def up + add_concurrent_index :vulnerability_occurrences, "(location -> 'cluster_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/20211022113000_drop_index_security_ci_builds_on_name_and_id_parser_features_broken.rb b/db/post_migrate/20211022113000_drop_index_security_ci_builds_on_name_and_id_parser_features_broken.rb new file mode 100644 index 00000000000..9ee1b10a072 --- /dev/null +++ b/db/post_migrate/20211022113000_drop_index_security_ci_builds_on_name_and_id_parser_features_broken.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class DropIndexSecurityCiBuildsOnNameAndIdParserFeaturesBroken < Gitlab::Database::Migration[1.0] + TABLE = "ci_builds" + COLUMNS = %i[name id] + INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features_broken" + CONSTRAINTS = "(name::text = ANY (ARRAY['container_scanning'::character varying::text, + 'dast'::character varying::text, + 'dependency_scanning'::character varying::text, + 'license_management'::character varying::text, + 'sast'::character varying::text, + 'secret_detection'::character varying::text, + 'coverage_fuzzing'::character varying::text, + 'license_scanning'::character varying::text]) + ) AND type::text = 'Ci::Build'::text" + + disable_ddl_transaction! + + def up + remove_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS) + end + + def down + add_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS) + end +end diff --git a/db/post_migrate/20211022160154_remove_outdated_fields_from_geo_node_status.rb b/db/post_migrate/20211022160154_remove_outdated_fields_from_geo_node_status.rb new file mode 100644 index 00000000000..5b117f9e4b8 --- /dev/null +++ b/db/post_migrate/20211022160154_remove_outdated_fields_from_geo_node_status.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class RemoveOutdatedFieldsFromGeoNodeStatus < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + remove_column :geo_node_statuses, :attachments_count, :integer + remove_column :geo_node_statuses, :attachments_synced_count, :integer + remove_column :geo_node_statuses, :attachments_failed_count, :integer + remove_column :geo_node_statuses, :attachments_synced_missing_on_primary_count, :integer + end +end diff --git a/db/post_migrate/20211027064021_track_deletions_in_ci_runners.rb b/db/post_migrate/20211027064021_track_deletions_in_ci_runners.rb new file mode 100644 index 00000000000..14cf305fb2e --- /dev/null +++ b/db/post_migrate/20211027064021_track_deletions_in_ci_runners.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackDeletionsInCiRunners < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:ci_runners) + end + + def down + untrack_record_deletions(:ci_runners) + end +end diff --git a/db/post_migrate/20211027064156_track_deletions_in_chat_names.rb b/db/post_migrate/20211027064156_track_deletions_in_chat_names.rb new file mode 100644 index 00000000000..1c8f9d5196a --- /dev/null +++ b/db/post_migrate/20211027064156_track_deletions_in_chat_names.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackDeletionsInChatNames < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:chat_names) + end + + def down + untrack_record_deletions(:chat_names) + end +end diff --git a/db/post_migrate/20211027112901_drop_index_keys_on_expires_at_and_before_expiry_notification_undelivered.rb b/db/post_migrate/20211027112901_drop_index_keys_on_expires_at_and_before_expiry_notification_undelivered.rb new file mode 100644 index 00000000000..3447c4da81a --- /dev/null +++ b/db/post_migrate/20211027112901_drop_index_keys_on_expires_at_and_before_expiry_notification_undelivered.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DropIndexKeysOnExpiresAtAndBeforeExpiryNotificationUndelivered < Gitlab::Database::Migration[1.0] + DOWNTIME = false + INDEX_NAME = 'index_keys_on_expires_at_and_expiry_notification_undelivered' + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name(:keys, INDEX_NAME) + end + + def down + add_concurrent_index :keys, + "date(timezone('UTC', expires_at)), expiry_notification_delivered_at", + where: 'expiry_notification_delivered_at IS NULL', name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211027204011_remove_index_for_dormant_users.rb b/db/post_migrate/20211027204011_remove_index_for_dormant_users.rb new file mode 100644 index 00000000000..5e556fe1f32 --- /dev/null +++ b/db/post_migrate/20211027204011_remove_index_for_dormant_users.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveIndexForDormantUsers < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_users_on_id_and_last_activity_on_for_non_internal_active' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :users, INDEX_NAME + end + + def down + index_condition = "state = 'active' AND (users.user_type IS NULL OR users.user_type IN (NULL, 6, 4))" + + add_concurrent_index :users, [:id, :last_activity_on], where: index_condition, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211028085926_add_occurrence_id_id_desc_index_to_vulnerability_occurrence_pipelines.rb b/db/post_migrate/20211028085926_add_occurrence_id_id_desc_index_to_vulnerability_occurrence_pipelines.rb new file mode 100644 index 00000000000..1f03e39aa81 --- /dev/null +++ b/db/post_migrate/20211028085926_add_occurrence_id_id_desc_index_to_vulnerability_occurrence_pipelines.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddOccurrenceIdIdDescIndexToVulnerabilityOccurrencePipelines < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = "index_vulnerability_occurrence_pipelines_occurrence_id_and_id" + + def up + add_concurrent_index( + :vulnerability_occurrence_pipelines, + [:occurrence_id, :id], + order: { id: :desc }, + name: INDEX_NAME + ) + end + + def down + remove_concurrent_index_by_name( + :vulnerability_occurrence_pipelines, + INDEX_NAME + ) + end +end diff --git a/db/post_migrate/20211028100303_tmp_index_for_delete_issue_merge_request_taggings_records.rb b/db/post_migrate/20211028100303_tmp_index_for_delete_issue_merge_request_taggings_records.rb new file mode 100644 index 00000000000..98984239ca4 --- /dev/null +++ b/db/post_migrate/20211028100303_tmp_index_for_delete_issue_merge_request_taggings_records.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class TmpIndexForDeleteIssueMergeRequestTaggingsRecords < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'tmp_index_taggings_on_id_where_taggable_type_issue_mr' + INDEX_CONDITION = "taggable_type IN ('Issue', 'MergeRequest')" + + def up + add_concurrent_index :taggings, :id, where: INDEX_CONDITION, name: INDEX_NAME # rubocop:disable Migration/PreventIndexCreation + end + + def down + remove_concurrent_index_by_name :taggings, INDEX_NAME + end +end diff --git a/db/post_migrate/20211028100843_delete_issue_merge_request_taggings_records.rb b/db/post_migrate/20211028100843_delete_issue_merge_request_taggings_records.rb new file mode 100644 index 00000000000..1ceaa1b5aef --- /dev/null +++ b/db/post_migrate/20211028100843_delete_issue_merge_request_taggings_records.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class DeleteIssueMergeRequestTaggingsRecords < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'tmp_index_taggings_on_id_where_taggable_type_issue_mr' + + BATCH_SIZE = 3_000 + TAGGABLE_TYPES = %w(Issue MergeRequest) + + def up + sleep 2 while ActsAsTaggableOn::Tagging.where(taggable_type: TAGGABLE_TYPES).limit(BATCH_SIZE).delete_all > 0 + + remove_concurrent_index_by_name :taggings, INDEX_NAME + end + + def down + end +end diff --git a/db/post_migrate/20211028123412_add_async_index_on_events_using_btree_created_at_id.rb b/db/post_migrate/20211028123412_add_async_index_on_events_using_btree_created_at_id.rb new file mode 100644 index 00000000000..03e461dfcd0 --- /dev/null +++ b/db/post_migrate/20211028123412_add_async_index_on_events_using_btree_created_at_id.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddAsyncIndexOnEventsUsingBtreeCreatedAtId < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_events_on_created_at_and_id' + TABLE = :events + COLUMNS = %i[created_at id] + CONSTRAINTS = "created_at > '2021-08-27'" + + def up + prepare_async_index TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS + end + + def down + unprepare_async_index TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS + end +end diff --git a/db/post_migrate/20211028155449_schedule_fix_merge_request_diff_commit_users_migration.rb b/db/post_migrate/20211028155449_schedule_fix_merge_request_diff_commit_users_migration.rb new file mode 100644 index 00000000000..659cb7b76b2 --- /dev/null +++ b/db/post_migrate/20211028155449_schedule_fix_merge_request_diff_commit_users_migration.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +class ScheduleFixMergeRequestDiffCommitUsersMigration < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION_CLASS = 'FixMergeRequestDiffCommitUsers' + + class Project < ApplicationRecord + include EachBatch + + self.table_name = 'projects' + end + + def up + # This is the day on which we merged + # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63669. Since the + # deploy of this MR we may have imported projects using the old format, but + # after their merge_request_diff_id range had been migrated by Sidekiq. As a + # result, there may be rows without a committer_id or commit_author_id + # field. + date = '2021-07-07 00:00:00' + + transaction do + Project.each_batch(of: 10_000) do |batch| + time = Time.now.utc + rows = batch + .where('created_at >= ?', date) + .where(import_type: 'gitlab_project') + .pluck(:id) + .map do |id| + Gitlab::Database::BackgroundMigrationJob.new( + class_name: MIGRATION_CLASS, + arguments: [id], + created_at: time, + updated_at: time + ) + end + + Gitlab::Database::BackgroundMigrationJob + .bulk_insert!(rows, validate: false) + end + end + + job = Gitlab::Database::BackgroundMigrationJob + .for_migration_class(MIGRATION_CLASS) + .pending + .first + + migrate_in(2.minutes, MIGRATION_CLASS, job.arguments) if job + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211029102822_add_open_source_plan.rb b/db/post_migrate/20211029102822_add_open_source_plan.rb new file mode 100644 index 00000000000..00266640f03 --- /dev/null +++ b/db/post_migrate/20211029102822_add_open_source_plan.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class AddOpenSourcePlan < Gitlab::Database::Migration[1.0] + class Plan < ActiveRecord::Base + self.inheritance_column = :_type_disabled + + has_one :limits, class_name: 'PlanLimits' + + def actual_limits + self.limits || self.build_limits + end + end + + class PlanLimits < ActiveRecord::Base + self.inheritance_column = :_type_disabled + + belongs_to :plan + end + + def create_plan_limits(plan_limit_name, plan) + plan_limit = Plan.find_or_initialize_by(name: plan_limit_name).actual_limits.dup + plan_limit.plan = plan + plan_limit.save! + end + + def up + return unless Gitlab.dev_env_or_com? + + opensource = Plan.create!(name: 'opensource', title: 'Open Source Program') + + create_plan_limits('ultimate', opensource) + end + + def down + return unless Gitlab.dev_env_or_com? + + Plan.where(name: 'opensource').delete_all + end +end diff --git a/db/post_migrate/20211031152417_add_indexes_to_issue_stage_events.rb b/db/post_migrate/20211031152417_add_indexes_to_issue_stage_events.rb new file mode 100644 index 00000000000..73b70ad1e27 --- /dev/null +++ b/db/post_migrate/20211031152417_add_indexes_to_issue_stage_events.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class AddIndexesToIssueStageEvents < Gitlab::Database::Migration[1.0] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + GROUP_INDEX_NAME = 'index_issue_stage_events_group_duration' + GROUP_IN_PROGRESS_INDEX_NAME = 'index_issue_stage_events_group_in_progress_duration' + PROJECT_INDEX_NAME = 'index_issue_stage_events_project_duration' + PROJECT_IN_PROGRESS_INDEX_NAME = 'index_issue_stage_events_project_in_progress_duration' + + def up + add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events, + 'stage_event_hash_id, group_id, end_event_timestamp, issue_id, start_event_timestamp', + where: 'end_event_timestamp IS NOT NULL', + name: GROUP_INDEX_NAME + + add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events, + 'stage_event_hash_id, project_id, end_event_timestamp, issue_id, start_event_timestamp', + where: 'end_event_timestamp IS NOT NULL', + name: PROJECT_INDEX_NAME + + add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events, + 'stage_event_hash_id, group_id, start_event_timestamp, issue_id', + where: 'end_event_timestamp IS NULL AND state_id = 1', + name: GROUP_IN_PROGRESS_INDEX_NAME + + add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events, + 'stage_event_hash_id, project_id, start_event_timestamp, issue_id', + where: 'end_event_timestamp IS NULL AND state_id = 1', + name: PROJECT_IN_PROGRESS_INDEX_NAME + end + + def down + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, GROUP_INDEX_NAME + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, PROJECT_INDEX_NAME + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, GROUP_IN_PROGRESS_INDEX_NAME + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, PROJECT_IN_PROGRESS_INDEX_NAME + end +end diff --git a/db/post_migrate/20211031154919_add_indexes_to_merge_request_stage_events.rb b/db/post_migrate/20211031154919_add_indexes_to_merge_request_stage_events.rb new file mode 100644 index 00000000000..9cc9d73c968 --- /dev/null +++ b/db/post_migrate/20211031154919_add_indexes_to_merge_request_stage_events.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class AddIndexesToMergeRequestStageEvents < Gitlab::Database::Migration[1.0] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + GROUP_INDEX_NAME = 'index_merge_request_stage_events_group_duration' + GROUP_IN_PROGRESS_INDEX_NAME = 'index_merge_request_stage_events_group_in_progress_duration' + PROJECT_INDEX_NAME = 'index_merge_request_stage_events_project_duration' + PROJECT_IN_PROGRESS_INDEX_NAME = 'index_merge_request_stage_events_project_in_progress_duration' + + def up + add_concurrent_partitioned_index :analytics_cycle_analytics_merge_request_stage_events, + 'stage_event_hash_id, group_id, end_event_timestamp, merge_request_id, start_event_timestamp', + where: 'end_event_timestamp IS NOT NULL', + name: GROUP_INDEX_NAME + + add_concurrent_partitioned_index :analytics_cycle_analytics_merge_request_stage_events, + 'stage_event_hash_id, project_id, end_event_timestamp, merge_request_id, start_event_timestamp', + where: 'end_event_timestamp IS NOT NULL', + name: PROJECT_INDEX_NAME + + add_concurrent_partitioned_index :analytics_cycle_analytics_merge_request_stage_events, + 'stage_event_hash_id, group_id, start_event_timestamp, merge_request_id', + where: 'end_event_timestamp IS NULL AND state_id = 1', + name: GROUP_IN_PROGRESS_INDEX_NAME + + add_concurrent_partitioned_index :analytics_cycle_analytics_merge_request_stage_events, + 'stage_event_hash_id, project_id, start_event_timestamp, merge_request_id', + where: 'end_event_timestamp IS NULL AND state_id = 1', + name: PROJECT_IN_PROGRESS_INDEX_NAME + end + + def down + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_merge_request_stage_events, GROUP_INDEX_NAME + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_merge_request_stage_events, PROJECT_INDEX_NAME + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_merge_request_stage_events, GROUP_IN_PROGRESS_INDEX_NAME + remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_merge_request_stage_events, PROJECT_IN_PROGRESS_INDEX_NAME + end +end diff --git a/db/post_migrate/20211102103127_add_temp_index_to_vulnerability_occurrences.rb b/db/post_migrate/20211102103127_add_temp_index_to_vulnerability_occurrences.rb new file mode 100644 index 00000000000..4aee79950dc --- /dev/null +++ b/db/post_migrate/20211102103127_add_temp_index_to_vulnerability_occurrences.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTempIndexToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'vulnerability_occurrences_location_temp_index' + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerability_occurrences, :id, where: 'location IS NULL', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerability_occurrences, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211102114802_update_vulnerability_occurrences_location.rb b/db/post_migrate/20211102114802_update_vulnerability_occurrences_location.rb new file mode 100644 index 00000000000..44e2630af06 --- /dev/null +++ b/db/post_migrate/20211102114802_update_vulnerability_occurrences_location.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class UpdateVulnerabilityOccurrencesLocation < Gitlab::Database::Migration[1.0] + BATCH_SIZE = 20_000 + DELAY_INTERVAL = 3.minutes + MIGRATION_NAME = 'UpdateVulnerabilityOccurrencesLocation' + + disable_ddl_transaction! + + def up + return unless Gitlab.ee? + + relation = Gitlab::BackgroundMigration::UpdateVulnerabilityOccurrencesLocation::Occurrence.where(location: nil) + 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/20211103162025_add_index_on_events_using_btree_created_at_id.rb b/db/post_migrate/20211103162025_add_index_on_events_using_btree_created_at_id.rb new file mode 100644 index 00000000000..33d5833db1a --- /dev/null +++ b/db/post_migrate/20211103162025_add_index_on_events_using_btree_created_at_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexOnEventsUsingBtreeCreatedAtId < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_events_on_created_at_and_id' + TABLE = :events + COLUMNS = %i[created_at id] + CONSTRAINTS = "created_at > '2021-08-27 00:00:00+00'" + disable_ddl_transaction! + + def up + add_concurrent_index TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS + end + + def down + remove_concurrent_index TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS + end +end diff --git a/db/post_migrate/20211104044453_remove_redundant_events_index.rb b/db/post_migrate/20211104044453_remove_redundant_events_index.rb new file mode 100644 index 00000000000..54e71e1b54b --- /dev/null +++ b/db/post_migrate/20211104044453_remove_redundant_events_index.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class RemoveRedundantEventsIndex < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :events, :index_events_on_target_type_and_target_id + end + + def down + add_concurrent_index :events, [:target_type, :target_id], name: :index_events_on_target_type_and_target_id + end +end diff --git a/db/post_migrate/20211105135157_drop_ci_build_trace_sections.rb b/db/post_migrate/20211105135157_drop_ci_build_trace_sections.rb new file mode 100644 index 00000000000..1595068952d --- /dev/null +++ b/db/post_migrate/20211105135157_drop_ci_build_trace_sections.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +class DropCiBuildTraceSections < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:dep_ci_build_trace_sections, column: :project_id) + end + + with_lock_retries do + remove_foreign_key_if_exists(:dep_ci_build_trace_section_names, column: :project_id) + end + + if table_exists?(:dep_ci_build_trace_sections) + with_lock_retries do + drop_table :dep_ci_build_trace_sections + end + end + + if table_exists?(:dep_ci_build_trace_section_names) + with_lock_retries do + drop_table :dep_ci_build_trace_section_names + end + end + + drop_function('trigger_91dc388a5fe6') + end + + def down + execute(<<~SQL) + CREATE OR REPLACE FUNCTION trigger_91dc388a5fe6() RETURNS trigger + LANGUAGE plpgsql + AS $$ + BEGIN + NEW."build_id_convert_to_bigint" := NEW."build_id"; + RETURN NEW; + END; + $$; + SQL + + execute_in_transaction(<<~SQL, !table_exists?(:dep_ci_build_trace_section_names)) + CREATE TABLE dep_ci_build_trace_section_names ( + id integer NOT NULL, + project_id integer NOT NULL, + name character varying NOT NULL + ); + + CREATE SEQUENCE dep_ci_build_trace_section_names_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + ALTER SEQUENCE dep_ci_build_trace_section_names_id_seq OWNED BY dep_ci_build_trace_section_names.id; + + ALTER TABLE ONLY dep_ci_build_trace_section_names ALTER COLUMN id SET DEFAULT nextval('dep_ci_build_trace_section_names_id_seq'::regclass); + ALTER TABLE ONLY dep_ci_build_trace_section_names ADD CONSTRAINT dep_ci_build_trace_section_names_pkey PRIMARY KEY (id); + SQL + + execute_in_transaction(<<~SQL, !table_exists?(:dep_ci_build_trace_sections)) + CREATE TABLE dep_ci_build_trace_sections ( + project_id integer NOT NULL, + date_start timestamp without time zone NOT NULL, + date_end timestamp without time zone NOT NULL, + byte_start bigint NOT NULL, + byte_end bigint NOT NULL, + build_id integer NOT NULL, + section_name_id integer NOT NULL, + build_id_convert_to_bigint bigint DEFAULT 0 NOT NULL + ); + + ALTER TABLE ONLY dep_ci_build_trace_sections ADD CONSTRAINT ci_build_trace_sections_pkey PRIMARY KEY (build_id, section_name_id); + CREATE TRIGGER trigger_91dc388a5fe6 BEFORE INSERT OR UPDATE ON dep_ci_build_trace_sections FOR EACH ROW EXECUTE FUNCTION trigger_91dc388a5fe6(); + SQL + + add_concurrent_index :dep_ci_build_trace_section_names, [:project_id, :name], unique: true, name: 'index_dep_ci_build_trace_section_names_on_project_id_and_name' + add_concurrent_index :dep_ci_build_trace_sections, :project_id, name: 'index_dep_ci_build_trace_sections_on_project_id' + add_concurrent_index :dep_ci_build_trace_sections, :section_name_id, name: 'index_dep_ci_build_trace_sections_on_section_name_id' + + add_concurrent_foreign_key :dep_ci_build_trace_sections, :dep_ci_build_trace_section_names, column: :section_name_id, on_delete: :cascade, name: 'fk_264e112c66' + add_concurrent_foreign_key :dep_ci_build_trace_sections, :projects, column: :project_id, on_delete: :cascade, name: 'fk_ab7c104e26' + add_concurrent_foreign_key :dep_ci_build_trace_section_names, :projects, column: :project_id, on_delete: :cascade, name: 'fk_f8cd72cd26' + end + + private + + def execute_in_transaction(sql, condition) + return unless condition + + transaction do + execute(sql) + end + end +end diff --git a/db/post_migrate/20211109112454_drop_old_loose_fk_deleted_records_index.rb b/db/post_migrate/20211109112454_drop_old_loose_fk_deleted_records_index.rb new file mode 100644 index 00000000000..ef5a70713d0 --- /dev/null +++ b/db/post_migrate/20211109112454_drop_old_loose_fk_deleted_records_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class DropOldLooseFkDeletedRecordsIndex < Gitlab::Database::Migration[1.0] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_loose_foreign_keys_deleted_records_for_loading_records' + + def up + remove_concurrent_partitioned_index_by_name :loose_foreign_keys_deleted_records, INDEX_NAME + end + + def down + add_concurrent_partitioned_index :loose_foreign_keys_deleted_records, + %I[fully_qualified_table_name id primary_key_value partition], + where: 'status = 1', + name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211112113300_remove_ci_pipeline_chat_data_fk_on_chat_names.rb b/db/post_migrate/20211112113300_remove_ci_pipeline_chat_data_fk_on_chat_names.rb new file mode 100644 index 00000000000..19adc6c7084 --- /dev/null +++ b/db/post_migrate/20211112113300_remove_ci_pipeline_chat_data_fk_on_chat_names.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class RemoveCiPipelineChatDataFkOnChatNames < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:ci_pipeline_chat_data, :chat_names, name: "fk_rails_f300456b63") + end + end + + def down + # Remove orphaned rows + execute <<~SQL + DELETE FROM ci_pipeline_chat_data + WHERE + NOT EXISTS (SELECT 1 FROM chat_names WHERE chat_names.id=ci_pipeline_chat_data.chat_name_id) + SQL + + add_concurrent_foreign_key(:ci_pipeline_chat_data, :chat_names, name: "fk_rails_f300456b63", column: :chat_name_id, target_column: :id, on_delete: "cascade") + end +end diff --git a/db/post_migrate/20211115151704_add_index_on_projects_import_type_id.rb b/db/post_migrate/20211115151704_add_index_on_projects_import_type_id.rb new file mode 100644 index 00000000000..b54edc1cf73 --- /dev/null +++ b/db/post_migrate/20211115151704_add_index_on_projects_import_type_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexOnProjectsImportTypeId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_imported_projects_on_import_type_id' + + def up + add_concurrent_index(:projects, [:import_type, :id], where: 'import_type IS NOT NULL', name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(:projects, INDEX_NAME) + end +end |