diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 08:43:02 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 08:43:02 +0000 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /db/post_migrate | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) | |
download | gitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'db/post_migrate')
123 files changed, 524 insertions, 2867 deletions
diff --git a/db/post_migrate/20190102152410_delete_inconsistent_internal_id_records2.rb b/db/post_migrate/20190102152410_delete_inconsistent_internal_id_records2.rb deleted file mode 100644 index ddcddcf72a3..00000000000 --- a/db/post_migrate/20190102152410_delete_inconsistent_internal_id_records2.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true -class DeleteInconsistentInternalIdRecords2 < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - # This migration cleans up any inconsistent records in internal_ids. - # - # That is, it deletes records that track a `last_value` that is - # smaller than the maximum internal id (usually `iid`) found in - # the corresponding model records. - - def up - disable_statement_timeout do - delete_internal_id_records('milestones', 'project_id') - delete_internal_id_records('milestones', 'namespace_id', 'group_id') - end - end - - class InternalId < ActiveRecord::Base - self.table_name = 'internal_ids' - enum usage: { issues: 0, merge_requests: 1, deployments: 2, milestones: 3, epics: 4, ci_pipelines: 5 } - end - - private - - def delete_internal_id_records(base_table, scope_column_name, base_scope_column_name = scope_column_name) - sql = <<~SQL - SELECT id FROM ( -- workaround for MySQL - SELECT internal_ids.id FROM ( - SELECT #{base_scope_column_name} AS #{scope_column_name}, max(iid) as maximum_iid from #{base_table} GROUP BY #{scope_column_name} - ) maxima JOIN internal_ids USING (#{scope_column_name}) - WHERE internal_ids.usage=#{InternalId.usages.fetch(base_table)} AND maxima.maximum_iid > internal_ids.last_value - ) internal_ids - SQL - - InternalId.where("id IN (#{sql})").tap do |ids| # rubocop:disable GitlabSecurity/SqlInjection - say "Deleting internal_id records for #{base_table}: #{ids.map { |i| [i.project_id, i.last_value] }}" unless ids.empty? - end.delete_all - end -end diff --git a/db/post_migrate/20190115054215_migrate_delete_container_repository_worker.rb b/db/post_migrate/20190115054215_migrate_delete_container_repository_worker.rb deleted file mode 100644 index 4fcee326b7e..00000000000 --- a/db/post_migrate/20190115054215_migrate_delete_container_repository_worker.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class MigrateDeleteContainerRepositoryWorker < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate('delete_container_repository', to: 'container_repository:delete_container_repository') - end - - def down - sidekiq_queue_migrate('container_repository:delete_container_repository', to: 'delete_container_repository') - end -end diff --git a/db/post_migrate/20190124200344_migrate_storage_migrator_sidekiq_queue.rb b/db/post_migrate/20190124200344_migrate_storage_migrator_sidekiq_queue.rb deleted file mode 100644 index 193bd571831..00000000000 --- a/db/post_migrate/20190124200344_migrate_storage_migrator_sidekiq_queue.rb +++ /dev/null @@ -1,18 +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 MigrateStorageMigratorSidekiqQueue < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'storage_migrator', to: 'hashed_storage:hashed_storage_migrator' - end - - def down - sidekiq_queue_migrate 'hashed_storage:hashed_storage_migrator', to: 'storage_migrator' - end -end diff --git a/db/post_migrate/20190131122559_fix_null_type_labels.rb b/db/post_migrate/20190131122559_fix_null_type_labels.rb deleted file mode 100644 index 83bb613990c..00000000000 --- a/db/post_migrate/20190131122559_fix_null_type_labels.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class FixNullTypeLabels < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - update_column_in_batches(:labels, :type, 'ProjectLabel') do |table, query| - query.where( - table[:project_id].not_eq(nil) - .and(table[:template].eq(false)) - .and(table[:type].eq(nil)) - ) - end - end - - def down - # no action - end -end diff --git a/db/post_migrate/20190204115450_migrate_auto_dev_ops_domain_to_cluster_domain.rb b/db/post_migrate/20190204115450_migrate_auto_dev_ops_domain_to_cluster_domain.rb deleted file mode 100644 index 036b0b64b48..00000000000 --- a/db/post_migrate/20190204115450_migrate_auto_dev_ops_domain_to_cluster_domain.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class MigrateAutoDevOpsDomainToClusterDomain < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - execute(update_clusters_domain_query) - end - - def down - # no-op - end - - private - - def update_clusters_domain_query - <<~HEREDOC - UPDATE clusters - SET domain = project_auto_devops.domain - FROM cluster_projects, project_auto_devops - WHERE - cluster_projects.cluster_id = clusters.id - AND project_auto_devops.project_id = cluster_projects.project_id - AND project_auto_devops.domain != '' - HEREDOC - end -end diff --git a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb deleted file mode 100644 index de062937fbe..00000000000 --- a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] - # This migration schedules the sync of state_id for issues and merge requests - # which are converting the state column from string to integer. - # For more information check: https://gitlab.com/gitlab-org/gitlab-foss/issues/51789 - - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - # 2019-02-12 gitlab.com issuable numbers - # issues count: 13587305 - # merge requests count: 18925274 - # - # Using 5000 as batch size and 115 seconds interval will give: - # 2718 jobs for issues - taking ~86 hours - # 3786 jobs for merge requests - taking ~120 hours - # - BATCH_SIZE = 5000 - DELAY_INTERVAL = 120.seconds.to_i - ISSUES_MIGRATION = 'SyncIssuesStateId' - MERGE_REQUESTS_MIGRATION = 'SyncMergeRequestsStateId' - - disable_ddl_transaction! - - class Issue < ActiveRecord::Base - include EachBatch - - self.table_name = 'issues' - end - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - Issue.all, - ISSUES_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - - queue_background_migration_jobs_by_range_at_intervals( - MergeRequest.all, - MERGE_REQUESTS_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - end - - def down - # No op - end -end diff --git a/db/post_migrate/20190301081611_migrate_project_migrate_sidekiq_queue.rb b/db/post_migrate/20190301081611_migrate_project_migrate_sidekiq_queue.rb deleted file mode 100644 index 46108d142b5..00000000000 --- a/db/post_migrate/20190301081611_migrate_project_migrate_sidekiq_queue.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class MigrateProjectMigrateSidekiqQueue < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'project_migrate_hashed_storage', to: 'hashed_storage:hashed_storage_project_migrate' - end - - def down - sidekiq_queue_migrate 'hashed_storage:hashed_storage_project_migrate', to: 'project_migrate_hashed_storage' - end -end diff --git a/db/post_migrate/20190313092516_clean_up_noteable_id_for_notes_on_commits.rb b/db/post_migrate/20190313092516_clean_up_noteable_id_for_notes_on_commits.rb deleted file mode 100644 index fcd63f42b0e..00000000000 --- a/db/post_migrate/20190313092516_clean_up_noteable_id_for_notes_on_commits.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 CleanUpNoteableIdForNotesOnCommits < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - TEMP_INDEX_NAME = 'index_notes_on_commit_with_null_noteable_id' - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name(:notes, TEMP_INDEX_NAME) - - add_concurrent_index(:notes, :id, where: "noteable_type = 'Commit' AND noteable_id IS NOT NULL", name: TEMP_INDEX_NAME) - - # rubocop:disable Migration/UpdateLargeTable - update_column_in_batches(:notes, :noteable_id, nil, batch_size: 300) do |table, query| - query.where( - table[:noteable_type].eq('Commit').and(table[:noteable_id].not_eq(nil)) - ) - end - - remove_concurrent_index_by_name(:notes, TEMP_INDEX_NAME) - end - - def down - end -end diff --git a/db/post_migrate/20190322132835_schedule_populate_merge_request_assignees_table.rb b/db/post_migrate/20190322132835_schedule_populate_merge_request_assignees_table.rb deleted file mode 100644 index 1ecb38e1a86..00000000000 --- a/db/post_migrate/20190322132835_schedule_populate_merge_request_assignees_table.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 SchedulePopulateMergeRequestAssigneesTable < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10_000 - MIGRATION = 'PopulateMergeRequestAssigneesTable' - DELAY_INTERVAL = 8.minutes.to_i - - disable_ddl_transaction! - - def up - say 'Scheduling `PopulateMergeRequestAssigneesTable` jobs' - # We currently have ~4_500_000 merge request records on GitLab.com. - # This means it'll schedule ~450 jobs (10k MRs each) with a 8 minutes gap, - # so this should take ~60 hours for all background migrations to complete. - queue_background_migration_jobs_by_range_at_intervals(MergeRequest, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end -end diff --git a/db/post_migrate/20190325111602_rename_v2_root_namespaces.rb b/db/post_migrate/20190325111602_rename_v2_root_namespaces.rb deleted file mode 100644 index 8571bb82fa0..00000000000 --- a/db/post_migrate/20190325111602_rename_v2_root_namespaces.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 RenameV2RootNamespaces < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - include Gitlab::Database::RenameReservedPathsMigration::V1 - - DOWNTIME = false - - disable_ddl_transaction! - - # We're taking over the /v2 namespace as it necessary for Docker client to - # work with GitLab as Dependency proxy for containers. - def up - disable_statement_timeout do - rename_root_paths 'v2' - end - end - - def down - disable_statement_timeout do - revert_renames - end - end -end diff --git a/db/post_migrate/20190404143330_add_unique_constraint_to_approvals_user_id_and_merge_request_id.rb b/db/post_migrate/20190404143330_add_unique_constraint_to_approvals_user_id_and_merge_request_id.rb deleted file mode 100644 index dd85ebc8001..00000000000 --- a/db/post_migrate/20190404143330_add_unique_constraint_to_approvals_user_id_and_merge_request_id.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -class AddUniqueConstraintToApprovalsUserIdAndMergeRequestId < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_duplicates - add_concurrent_index :approvals, [:user_id, :merge_request_id], unique: true - end - - def down - remove_concurrent_index :approvals, [:user_id, :merge_request_id] - end - - private - - def remove_duplicates - add_concurrent_index :approvals, [:user_id, :merge_request_id, :id] - - execute <<-SQL - DELETE FROM approvals - USING ( - SELECT user_id, merge_request_id, MIN(id) as min_id - FROM approvals - GROUP BY user_id, merge_request_id - HAVING COUNT(id) > 1 - ) as approvals_with_duplicates - WHERE approvals_with_duplicates.user_id = approvals.user_id - AND approvals_with_duplicates.merge_request_id = approvals.merge_request_id - AND approvals_with_duplicates.min_id <> approvals.id; - SQL - - remove_concurrent_index :approvals, [:user_id, :merge_request_id, :id] - end -end diff --git a/db/post_migrate/20190404231137_remove_alternate_url_from_geo_nodes.rb b/db/post_migrate/20190404231137_remove_alternate_url_from_geo_nodes.rb deleted file mode 100644 index 785ceb2fb28..00000000000 --- a/db/post_migrate/20190404231137_remove_alternate_url_from_geo_nodes.rb +++ /dev/null @@ -1,21 +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. - -# We are reverting the feature that created this column. This is for anyone who -# migrated while the feature still existed in master. -class RemoveAlternateUrlFromGeoNodes < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - def up - remove_column(:geo_nodes, :alternate_url) if column_exists?(:geo_nodes, :alternate_url) - end - - def down - add_column :geo_nodes, :alternate_url, :string - end -end diff --git a/db/post_migrate/20190418132125_populate_project_statistics_packages_size.rb b/db/post_migrate/20190418132125_populate_project_statistics_packages_size.rb deleted file mode 100644 index a6bee3453c1..00000000000 --- a/db/post_migrate/20190418132125_populate_project_statistics_packages_size.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -class PopulateProjectStatisticsPackagesSize < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class ProjectStatistics < ActiveRecord::Base - self.table_name = 'project_statistics' - end - - def up - stats_ids = ProjectStatistics.joins( - <<~SQL.strip_heredoc - INNER JOIN projects ON projects.id = project_statistics.project_id - INNER JOIN packages_packages ON packages_packages.project_id = projects.id - INNER JOIN packages_package_files ON packages_package_files.package_id = packages_packages.id - SQL - ).distinct.select(:id) - - packages_size = Arel.sql( - '(SELECT SUM(size) FROM packages_package_files ' \ - 'JOIN packages_packages ON packages_packages.id = packages_package_files.package_id ' \ - 'WHERE packages_packages.project_id = project_statistics.project_id)' - ) - update_column_in_batches(:project_statistics, :packages_size, packages_size) do |table, query| - query.where(table[:id].in(stats_ids)) - end - - storage_size = Arel.sql('(repository_size + lfs_objects_size + build_artifacts_size + COALESCE(packages_size, 0))') - update_column_in_batches(:project_statistics, :storage_size, storage_size) do |table, query| - query.where(table[:id].in(stats_ids)) - end - end - - def down - storage_size = Arel.sql('(repository_size + lfs_objects_size + build_artifacts_size)') - update_column_in_batches(:project_statistics, :storage_size, storage_size) do |table, query| - query.where(table[:packages_size].gt(0)) - end - - update_column_in_batches(:project_statistics, :packages_size, nil) - end -end diff --git a/db/post_migrate/20190424134256_drop_projects_ci_id.rb b/db/post_migrate/20190424134256_drop_projects_ci_id.rb deleted file mode 100644 index 223e9fd4a94..00000000000 --- a/db/post_migrate/20190424134256_drop_projects_ci_id.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 DropProjectsCiId < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - disable_ddl_transaction! - - def up - if index_exists?(:projects, :ci_id) - remove_concurrent_index :projects, :ci_id - end - - if column_exists?(:projects, :ci_id) - remove_column :projects, :ci_id - end - end - - def down - unless column_exists?(:projects, :ci_id) - add_column :projects, :ci_id, :integer # rubocop:disable Migration/AddColumnsToWideTables - end - - unless index_exists?(:projects, :ci_id) - add_concurrent_index :projects, :ci_id - end - end -end diff --git a/db/post_migrate/20190506135400_schedule_sync_issuables_state_id_where_nil.rb b/db/post_migrate/20190506135400_schedule_sync_issuables_state_id_where_nil.rb deleted file mode 100644 index 845c855358b..00000000000 --- a/db/post_migrate/20190506135400_schedule_sync_issuables_state_id_where_nil.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -class ScheduleSyncIssuablesStateIdWhereNil < ActiveRecord::Migration[5.1] - # Issues and MergeRequests imported by GitHub are being created with - # state_id = null, this fixes them. - # - # Part of a bigger plan: https://gitlab.com/gitlab-org/gitlab-foss/issues/51789 - - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - # 2019-05-02 gitlab.com issuable numbers - # issues with state_id nil: ~40000 - # merge requests with state_id nil: ~200000 - # - # Using 5000 as batch size and 120 seconds interval will create: - # ~8 jobs for issues - taking ~16 minutes - # ~40 jobs for merge requests - taking ~1.34 hours - # - BATCH_SIZE = 5000 - DELAY_INTERVAL = 120.seconds.to_i - ISSUES_MIGRATION = 'SyncIssuesStateId' - MERGE_REQUESTS_MIGRATION = 'SyncMergeRequestsStateId' - - disable_ddl_transaction! - - class Issue < ActiveRecord::Base - include EachBatch - - self.table_name = 'issues' - end - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - Issue.where(state_id: nil), - ISSUES_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - - queue_background_migration_jobs_by_range_at_intervals( - MergeRequest.where(state_id: nil), - MERGE_REQUESTS_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - - # Remove temporary indexes added on "AddTemporaryIndexesToStateId" - remove_concurrent_index_by_name(:issues, "idx_on_issues_where_state_id_is_null") - remove_concurrent_index_by_name(:merge_requests, "idx_on_merge_requests_where_state_id_is_null") - end - - def down - # No op - end -end diff --git a/db/post_migrate/20190511144331_remove_users_support_type.rb b/db/post_migrate/20190511144331_remove_users_support_type.rb deleted file mode 100644 index e72fbb229b8..00000000000 --- a/db/post_migrate/20190511144331_remove_users_support_type.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class RemoveUsersSupportType < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - INDEX_STATE_INTERNAL_ATTRS = 'index_users_on_state_and_internal_attrs' - - disable_ddl_transaction! - - def up - remove_concurrent_index :users, :state, name: INDEX_STATE_INTERNAL_ATTRS - remove_concurrent_index :users, :support_bot - - remove_column :users, :support_bot - end - - def down - add_column :users, :support_bot, :boolean # rubocop:disable Migration/AddColumnsToWideTables - - add_concurrent_index :users, :support_bot - add_concurrent_index :users, :state, - name: INDEX_STATE_INTERNAL_ATTRS, - where: 'ghost <> true AND support_bot <> true' - end -end diff --git a/db/post_migrate/20190517153211_migrate_k8s_service_integration.rb b/db/post_migrate/20190517153211_migrate_k8s_service_integration.rb deleted file mode 100644 index 0b409cd2866..00000000000 --- a/db/post_migrate/20190517153211_migrate_k8s_service_integration.rb +++ /dev/null @@ -1,104 +0,0 @@ -# frozen_string_literal: true - -class MigrateK8sServiceIntegration < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - class Cluster < ActiveRecord::Base - self.table_name = 'clusters' - - has_one :platform_kubernetes, class_name: 'MigrateK8sServiceIntegration::PlatformsKubernetes' - - accepts_nested_attributes_for :platform_kubernetes - - enum cluster_type: { - instance_type: 1, - group_type: 2, - project_type: 3 - } - - enum platform_type: { - kubernetes: 1 - } - - enum provider_type: { - user: 0, - gcp: 1 - } - end - - class PlatformsKubernetes < ActiveRecord::Base - self.table_name = 'cluster_platforms_kubernetes' - - belongs_to :cluster, class_name: 'MigrateK8sServiceIntegration::Cluster' - - attr_encrypted :token, - mode: :per_attribute_iv, - key: Settings.attr_encrypted_db_key_base_truncated, - algorithm: 'aes-256-cbc' - end - - class Service < ActiveRecord::Base - include EachBatch - - self.table_name = 'services' - self.inheritance_column = :_type_disabled # Disable STI, otherwise KubernetesModel will be looked up - - belongs_to :project, class_name: 'MigrateK8sServiceIntegration::Project', foreign_key: :project_id - - scope :kubernetes_service_templates, -> do - where(category: 'deployment', type: 'KubernetesService', template: true) - end - - def api_url - parsed_properties['api_url'].presence - end - - def ca_pem - parsed_properties['ca_pem'] - end - - def namespace - parsed_properties['namespace'].presence - end - - def token - parsed_properties['token'].presence - end - - private - - def parsed_properties - @parsed_properties ||= JSON.parse(self.properties) # rubocop:disable Gitlab/Json - end - end - - def up - has_instance_cluster = Cluster.instance_type.where(enabled: true).exists? - - MigrateK8sServiceIntegration::Service.kubernetes_service_templates.find_each do |service| - next unless service.api_url && service.token - - MigrateK8sServiceIntegration::Cluster.create!( - enabled: !has_instance_cluster && service.active, - managed: false, - name: 'KubernetesService', - cluster_type: 'instance_type', - provider_type: 'user', - platform_type: 'kubernetes', - platform_kubernetes_attributes: { - api_url: service.api_url, - ca_cert: service.ca_pem, - namespace: service.namespace, - token: service.token - } - ) - end - end - - def down - # It is not possible to tell which instance-level clusters were created by - # this migration. The original data is intentionally left intact. - end -end diff --git a/db/post_migrate/20190520201748_populate_rule_type_on_approval_merge_request_rules.rb b/db/post_migrate/20190520201748_populate_rule_type_on_approval_merge_request_rules.rb deleted file mode 100644 index 0f0df456134..00000000000 --- a/db/post_migrate/20190520201748_populate_rule_type_on_approval_merge_request_rules.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 PopulateRuleTypeOnApprovalMergeRequestRules < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - disable_ddl_transaction! - - class ApprovalMergeRequestRule < ActiveRecord::Base - include EachBatch - - enum rule_types: { - regular: 1, - code_owner: 2 - } - end - - def up - # On Gitlab.com, this should update about 17k rows. Since our updates are - # small and we are populating prior to indexing, the overhead should be small - ApprovalMergeRequestRule.where(code_owner: true).each_batch do |batch| - batch.update_all(rule_type: ApprovalMergeRequestRule.rule_types[:code_owner]) - end - end - - def down - # code_owner is already kept in sync with `rule_type`, so no changes are needed - end -end diff --git a/db/post_migrate/20190522143720_drop_project_auto_devops_domain.rb b/db/post_migrate/20190522143720_drop_project_auto_devops_domain.rb deleted file mode 100644 index 36278d83927..00000000000 --- a/db/post_migrate/20190522143720_drop_project_auto_devops_domain.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class DropProjectAutoDevopsDomain < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :project_auto_devops, :domain, :string - end -end diff --git a/db/post_migrate/20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb b/db/post_migrate/20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb deleted file mode 100644 index 1d8510e4514..00000000000 --- a/db/post_migrate/20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.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 ScheduleFillValidTimeForPagesDomainCertificates < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - MIGRATION = 'FillValidTimeForPagesDomainCertificate' - BATCH_SIZE = 500 - BATCH_TIME = 5.minutes - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - disable_ddl_transaction! - - class PagesDomain < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'pages_domains' - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - PagesDomain.where.not(certificate: [nil, '']), - MIGRATION, - BATCH_TIME, - batch_size: BATCH_SIZE) - end - - def down - end -end diff --git a/db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb b/db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb deleted file mode 100644 index f337390f10c..00000000000 --- a/db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class ScheduleCalculateWikiSizes < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'CalculateWikiSizes' - BATCH_SIZE = 100000 - BATCH_TIME = 5.minutes - - class ProjectStatistics < ActiveRecord::Base - self.table_name = 'project_statistics' - - scope :without_wiki_size, -> { where(wiki_size: nil) } - - include ::EachBatch - end - - disable_ddl_transaction! - - # Disabling this old migration because it should already run - # in 14.0. This will allow us to remove some `technical debt` - # in ProjectStatistics model, because of some columns - # not present by the time the migration is run. - def up - # no-op - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190528180441_enqueue_reset_merge_status.rb b/db/post_migrate/20190528180441_enqueue_reset_merge_status.rb deleted file mode 100644 index a3d2f497806..00000000000 --- a/db/post_migrate/20190528180441_enqueue_reset_merge_status.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 EnqueueResetMergeStatus < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10_000 - MIGRATION = 'ResetMergeStatus' - DELAY_INTERVAL = 5.minutes.to_i - - disable_ddl_transaction! - - def up - say 'Scheduling `ResetMergeStatus` jobs' - - # We currently have more than ~5_000_000 merge request records on GitLab.com. - # This means it'll schedule ~500 jobs (10k MRs each) with a 5 minutes gap, - # so this should take ~41 hours for all background migrations to complete. - # ((5_000_000 / 10_000) * 5) / 60 => 41.6666.. - queue_background_migration_jobs_by_range_at_intervals(MergeRequest, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end -end diff --git a/db/post_migrate/20190606163724_migrate_legacy_managed_clusters_to_unmanaged.rb b/db/post_migrate/20190606163724_migrate_legacy_managed_clusters_to_unmanaged.rb deleted file mode 100644 index 759ab939f7d..00000000000 --- a/db/post_migrate/20190606163724_migrate_legacy_managed_clusters_to_unmanaged.rb +++ /dev/null @@ -1,48 +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 MigrateLegacyManagedClustersToUnmanaged < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Cluster < ActiveRecord::Base - include EachBatch - - self.table_name = 'clusters' - - has_many :kubernetes_namespaces, class_name: 'MigrateLegacyManagedClustersToUnmanaged::KubernetesNamespace' - - scope :managed, -> { where(managed: true) } - - enum cluster_type: { - instance_type: 1, - group_type: 2, - project_type: 3 - } - end - - class KubernetesNamespace < ActiveRecord::Base - self.table_name = 'clusters_kubernetes_namespaces' - - belongs_to :cluster, class_name: 'MigrateLegacyManagedClustersToUnmanaged::Cluster' - end - - def up - Cluster.managed - .project_type - .left_joins(:kubernetes_namespaces) - .where(clusters_kubernetes_namespaces: { cluster_id: nil }) - .where('clusters.created_at < ?', 5.minutes.ago) - .each_batch do |batch| - batch.update_all(managed: false) - end - end - - def down - end -end diff --git a/db/post_migrate/20190606175050_encrypt_feature_flags_clients_tokens.rb b/db/post_migrate/20190606175050_encrypt_feature_flags_clients_tokens.rb deleted file mode 100644 index b8df41767f0..00000000000 --- a/db/post_migrate/20190606175050_encrypt_feature_flags_clients_tokens.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class EncryptFeatureFlagsClientsTokens < ActiveRecord::Migration[5.1] - DOWNTIME = false - - class FeatureFlagsClient < ActiveRecord::Base - self.table_name = 'operations_feature_flags_clients' - end - - def up - say_with_time("Encrypting tokens from operations_feature_flags_clients") do - FeatureFlagsClient.where('token_encrypted is NULL AND token IS NOT NULL').find_each do |feature_flags_client| - token_encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(feature_flags_client.token, nonce: Gitlab::CryptoHelper::AES256_GCM_IV_STATIC) - feature_flags_client.update!(token_encrypted: token_encrypted) - end - end - end - - def down - say_with_time("Decrypting tokens from operations_feature_flags_clients") do - FeatureFlagsClient.where('token_encrypted IS NOT NULL AND token IS NULL').find_each do |feature_flags_client| - token = Gitlab::CryptoHelper.aes256_gcm_decrypt(feature_flags_client.token_encrypted) - feature_flags_client.update!(token: token) - end - end - end -end diff --git a/db/post_migrate/20190611161642_add_index_to_events_and_audit_events_created_at_author_id.rb b/db/post_migrate/20190611161642_add_index_to_events_and_audit_events_created_at_author_id.rb deleted file mode 100644 index 5b9afbe128c..00000000000 --- a/db/post_migrate/20190611161642_add_index_to_events_and_audit_events_created_at_author_id.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 AddIndexToEventsAndAuditEventsCreatedAtAuthorId < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'analytics_index_%s_on_created_at_and_author_id' - EVENTS_INDEX_NAME = (INDEX_NAME % 'events') - AUDIT_EVENTS_INDEX_NAME = (INDEX_NAME % 'audit_events') - - disable_ddl_transaction! - - def up - add_concurrent_index :events, [:created_at, :author_id], name: EVENTS_INDEX_NAME - add_concurrent_index :audit_events, [:created_at, :author_id], name: AUDIT_EVENTS_INDEX_NAME - end - - def down - remove_concurrent_index_by_name :events, EVENTS_INDEX_NAME - remove_concurrent_index_by_name :audit_events, AUDIT_EVENTS_INDEX_NAME - end -end diff --git a/db/post_migrate/20190613231640_migrate_managed_clusters_with_no_token_to_unmanaged.rb b/db/post_migrate/20190613231640_migrate_managed_clusters_with_no_token_to_unmanaged.rb deleted file mode 100644 index b2914afe2cd..00000000000 --- a/db/post_migrate/20190613231640_migrate_managed_clusters_with_no_token_to_unmanaged.rb +++ /dev/null @@ -1,48 +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 MigrateManagedClustersWithNoTokenToUnmanaged < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Cluster < ActiveRecord::Base - include EachBatch - - self.table_name = 'clusters' - - has_many :kubernetes_namespaces, class_name: 'MigrateManagedClustersWithNoTokenToUnmanaged::KubernetesNamespace' - - scope :managed, -> { where(managed: true) } - - enum cluster_type: { - instance_type: 1, - group_type: 2, - project_type: 3 - } - end - - class KubernetesNamespace < ActiveRecord::Base - self.table_name = 'clusters_kubernetes_namespaces' - - belongs_to :cluster, class_name: 'MigrateManagedClustersWithNoTokenToUnmanaged::Cluster' - end - - def up - Cluster.managed - .project_type - .joins(:kubernetes_namespaces) - .where(clusters_kubernetes_namespaces: { encrypted_service_account_token: nil }) - .where('clusters.created_at < ?', Date.new(2018, 12, 1).midnight) - .each_batch do |batch| - batch.update_all(managed: false) - end - end - - def down - end -end diff --git a/db/post_migrate/20190618171120_update_geo_nodes_primary.rb b/db/post_migrate/20190618171120_update_geo_nodes_primary.rb deleted file mode 100644 index dc9cfbda177..00000000000 --- a/db/post_migrate/20190618171120_update_geo_nodes_primary.rb +++ /dev/null @@ -1,20 +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 UpdateGeoNodesPrimary < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - change_column_default(:geo_nodes, :primary, false) - change_column_null(:geo_nodes, :primary, false, false) - end - - def down - change_column_default(:geo_nodes, :primary, nil) - change_column_null(:geo_nodes, :primary, true) - end -end diff --git a/db/post_migrate/20190619175843_remove_import_columns_from_projects.rb b/db/post_migrate/20190619175843_remove_import_columns_from_projects.rb deleted file mode 100644 index 85f776ac99c..00000000000 --- a/db/post_migrate/20190619175843_remove_import_columns_from_projects.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class RemoveImportColumnsFromProjects < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - def change - remove_column :projects, :import_status, :string - remove_column :projects, :import_jid, :string - remove_column :projects, :import_error, :text - end -end diff --git a/db/post_migrate/20190620112608_enqueue_reset_merge_status_second_run.rb b/db/post_migrate/20190620112608_enqueue_reset_merge_status_second_run.rb deleted file mode 100644 index 2d096a2a39c..00000000000 --- a/db/post_migrate/20190620112608_enqueue_reset_merge_status_second_run.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 EnqueueResetMergeStatusSecondRun < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10_000 - MIGRATION = 'ResetMergeStatus' - DELAY_INTERVAL = 5.minutes.to_i - - disable_ddl_transaction! - - def up - say 'Scheduling `ResetMergeStatus` jobs' - - # We currently have more than ~5_000_000 merge request records on GitLab.com. - # This means it'll schedule ~500 jobs (10k MRs each) with a 5 minutes gap, - # so this should take ~41 hours for all background migrations to complete. - # ((5_000_000 / 10_000) * 5) / 60 => 41.6666.. - queue_background_migration_jobs_by_range_at_intervals(MergeRequest, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end -end diff --git a/db/post_migrate/20190625184066_remove_sentry_from_application_settings.rb b/db/post_migrate/20190625184066_remove_sentry_from_application_settings.rb deleted file mode 100644 index 7a0923aabd8..00000000000 --- a/db/post_migrate/20190625184066_remove_sentry_from_application_settings.rb +++ /dev/null @@ -1,40 +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 RemoveSentryFromApplicationSettings < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - SENTRY_ENABLED_COLUMNS = [ - :sentry_enabled, - :clientside_sentry_enabled - ].freeze - - SENTRY_DSN_COLUMNS = [ - :sentry_dsn, - :clientside_sentry_dsn - ].freeze - - disable_ddl_transaction! - - def up - (SENTRY_ENABLED_COLUMNS + SENTRY_DSN_COLUMNS).each do |column| - remove_column(:application_settings, column) if column_exists?(:application_settings, column) - end - end - - def down - SENTRY_ENABLED_COLUMNS.each do |column| - # rubocop:disable Migration/AddColumnWithDefault - add_column_with_default(:application_settings, column, :boolean, default: false, allow_null: false) unless column_exists?(:application_settings, column) - # rubocop:enable Migration/AddColumnWithDefault - end - - SENTRY_DSN_COLUMNS.each do |column| - add_column(:application_settings, column, :string) unless column_exists?(:application_settings, column) - end - end -end diff --git a/db/post_migrate/20190628191740_schedule_fixing_names_of_user_namespaces.rb b/db/post_migrate/20190628191740_schedule_fixing_names_of_user_namespaces.rb deleted file mode 100644 index 8fa7068b957..00000000000 --- a/db/post_migrate/20190628191740_schedule_fixing_names_of_user_namespaces.rb +++ /dev/null @@ -1,48 +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 ScheduleFixingNamesOfUserNamespaces < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - class Namespace < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'namespaces' - - scope :user_namespaces, -> { where(type: nil) } - end - - class Route < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'routes' - - scope :project_routes, -> { where(source_type: 'Project') } - end - - disable_ddl_transaction! - - def up - queue_background_migration_jobs_by_range_at_intervals( - ScheduleFixingNamesOfUserNamespaces::Namespace.user_namespaces, - 'FixUserNamespaceNames', - 60.seconds, - batch_size: 5000 - ) - - queue_background_migration_jobs_by_range_at_intervals( - ScheduleFixingNamesOfUserNamespaces::Route.project_routes, - 'FixUserProjectRouteNames', - 60.seconds, - batch_size: 5000 - ) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190702173936_populate_remaining_merge_request_assignees.rb b/db/post_migrate/20190702173936_populate_remaining_merge_request_assignees.rb deleted file mode 100644 index c435b94015d..00000000000 --- a/db/post_migrate/20190702173936_populate_remaining_merge_request_assignees.rb +++ /dev/null @@ -1,20 +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 PopulateRemainingMergeRequestAssignees < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10_000 - MIGRATION = 'PopulateMergeRequestAssigneesTable' - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal(MIGRATION) - - Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable.new.perform_all_sync(batch_size: BATCH_SIZE) - end -end diff --git a/db/post_migrate/20190703185326_fix_wrong_pages_access_level.rb b/db/post_migrate/20190703185326_fix_wrong_pages_access_level.rb deleted file mode 100644 index e5981956cf5..00000000000 --- a/db/post_migrate/20190703185326_fix_wrong_pages_access_level.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class FixWrongPagesAccessLevel < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'FixPagesAccessLevel' - BATCH_SIZE = 20_000 - BATCH_TIME = 2.minutes - - disable_ddl_transaction! - - class ProjectFeature < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'project_features' - self.inheritance_column = :_type_disabled - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - ProjectFeature, - MIGRATION, - BATCH_TIME, - batch_size: BATCH_SIZE) - end -end diff --git a/db/post_migrate/20190711201818_encrypt_deploy_tokens_tokens.rb b/db/post_migrate/20190711201818_encrypt_deploy_tokens_tokens.rb deleted file mode 100644 index b2de98118b7..00000000000 --- a/db/post_migrate/20190711201818_encrypt_deploy_tokens_tokens.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class EncryptDeployTokensTokens < ActiveRecord::Migration[5.1] - DOWNTIME = false - - class DeploymentTokens < ActiveRecord::Base - self.table_name = 'deploy_tokens' - end - - def up - say_with_time("Encrypting tokens from deploy_tokens") do - DeploymentTokens.where('token_encrypted is NULL AND token IS NOT NULL').find_each(batch_size: 10000) do |deploy_token| - token_encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(deploy_token.token, nonce: Gitlab::CryptoHelper::AES256_GCM_IV_STATIC) - deploy_token.update!(token_encrypted: token_encrypted) - end - end - end - - def down - say_with_time("Decrypting tokens from deploy_tokens") do - DeploymentTokens.where('token_encrypted IS NOT NULL AND token IS NULL').find_each(batch_size: 10000) do |deploy_token| - token = Gitlab::CryptoHelper.aes256_gcm_decrypt(deploy_token.token_encrypted) - deploy_token.update!(token: token) - end - end - end -end diff --git a/db/post_migrate/20190715043944_remove_sha_index_from_versions.rb b/db/post_migrate/20190715043944_remove_sha_index_from_versions.rb deleted file mode 100644 index b23abb80dda..00000000000 --- a/db/post_migrate/20190715043944_remove_sha_index_from_versions.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class RemoveShaIndexFromVersions < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_concurrent_index :design_management_versions, :sha - end - - def down - add_concurrent_index :design_management_versions, :sha, unique: true, using: :btree - end -end diff --git a/db/post_migrate/20190715044501_add_unique_issue_id_sha_index_to_versions.rb b/db/post_migrate/20190715044501_add_unique_issue_id_sha_index_to_versions.rb deleted file mode 100644 index 27b0c9648f9..00000000000 --- a/db/post_migrate/20190715044501_add_unique_issue_id_sha_index_to_versions.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddUniqueIssueIdShaIndexToVersions < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :design_management_versions, [:sha, :issue_id], unique: true, using: :btree - end - - def down - remove_concurrent_index :design_management_versions, [:sha, :issue_id] - end -end diff --git a/db/post_migrate/20190715114644_drop_project_features_pages_access_level_default.rb b/db/post_migrate/20190715114644_drop_project_features_pages_access_level_default.rb deleted file mode 100644 index 2fb0aa0f460..00000000000 --- a/db/post_migrate/20190715114644_drop_project_features_pages_access_level_default.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class DropProjectFeaturesPagesAccessLevelDefault < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - ENABLED_VALUE = 20 - - def change - change_column_default :project_features, :pages_access_level, from: ENABLED_VALUE, to: nil - end -end diff --git a/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb b/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb deleted file mode 100644 index 13f8477f3ea..00000000000 --- a/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb +++ /dev/null @@ -1,62 +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 MigrateDiscussionIdOnPromotedEpics < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - # We have ~5000 unique discussion_ids -> this migration will take about 102 minutes - # (5000/100 * 2 minutes + 2 minutes initial delay) on gitlab.com. - DOWNTIME = false - BATCH_SIZE = 100 - DELAY_INTERVAL = 2.minutes - MIGRATION = 'FixPromotedEpicsDiscussionIds' - - disable_ddl_transaction! - - class SystemNoteMetadata < ActiveRecord::Base - self.table_name = 'system_note_metadata' - self.inheritance_column = :_type_disabled - end - - class Note < ActiveRecord::Base - include EachBatch - - has_one :system_note_metadata, class_name: 'MigrateDiscussionIdOnPromotedEpics::SystemNoteMetadata' - - self.table_name = 'notes' - self.inheritance_column = :_type_disabled - - def self.fetch_discussion_ids_query - promoted_epics_query = Note - .joins(:system_note_metadata) - .where(system: true) - .where(noteable_type: 'Epic') - .where(system_note_metadata: { action: 'moved' }) - .select("DISTINCT noteable_id") - - Note.where(noteable_type: 'Epic') - .where(noteable_id: promoted_epics_query) - .distinct.pluck(:discussion_id) - end - end - - def up - add_concurrent_index(:system_note_metadata, :note_id, where: "action='moved'", name: 'temp_index_system_note_metadata_on_moved_note_id') - add_concurrent_index(:notes, [:id, :noteable_id], where: "noteable_type='Epic' AND system", name: 'temp_index_notes_on_id_and_noteable_id' ) - - all_discussion_ids = Note.fetch_discussion_ids_query - all_discussion_ids.in_groups_of(BATCH_SIZE, false).each_with_index do |ids, index| - delay = DELAY_INTERVAL * (index + 1) - BackgroundMigrationWorker.perform_in(delay, MIGRATION, [ids]) - end - - remove_concurrent_index(:system_note_metadata, :note_id, where: "action='moved'", name: 'temp_index_system_note_metadata_on_moved_note_id') - remove_concurrent_index(:notes, [:id, :noteable_id], where: "noteable_type='Epic' AND system", name: 'temp_index_notes_on_id_and_noteable_id') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190723105753_add_index_on_identities_lower_extern_uid_and_provider.rb b/db/post_migrate/20190723105753_add_index_on_identities_lower_extern_uid_and_provider.rb deleted file mode 100644 index 36ecca4821f..00000000000 --- a/db/post_migrate/20190723105753_add_index_on_identities_lower_extern_uid_and_provider.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnIdentitiesLowerExternUidAndProvider < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - INDEX_NAME = "index_on_identities_lower_extern_uid_and_provider" - - def up - add_concurrent_index(:identities, 'lower(extern_uid), provider', name: INDEX_NAME) - end - - def down - remove_concurrent_index_by_name(:identities, INDEX_NAME) - end -end diff --git a/db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb b/db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb deleted file mode 100644 index db42e949d3f..00000000000 --- a/db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class SetNotNullOnUsersPrivateProfile < ActiveRecord::Migration[5.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal('MigrateNullPrivateProfileToFalse') - - # rubocop:disable Migration/UpdateLargeTable - # rubocop:disable Migration/UpdateColumnInBatches - # Data has been migrated previously, count should be close to 0 - update_column_in_batches(:users, :private_profile, false) do |table, query| - query.where(table[:private_profile].eq(nil)) - end - - change_column_null :users, :private_profile, false - end - - def down - change_column_null :users, :private_profile, true - end -end diff --git a/db/post_migrate/20190801114109_cleanup_allow_local_requests_from_hooks_and_services_application_setting_rename.rb b/db/post_migrate/20190801114109_cleanup_allow_local_requests_from_hooks_and_services_application_setting_rename.rb deleted file mode 100644 index cb86f843f9c..00000000000 --- a/db/post_migrate/20190801114109_cleanup_allow_local_requests_from_hooks_and_services_application_setting_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupAllowLocalRequestsFromHooksAndServicesApplicationSettingRename < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :application_settings, :allow_local_requests_from_hooks_and_services, :allow_local_requests_from_web_hooks_and_services - end - - def down - undo_cleanup_concurrent_column_rename :application_settings, :allow_local_requests_from_hooks_and_services, :allow_local_requests_from_web_hooks_and_services - end -end diff --git a/db/post_migrate/20190802091750_cleanup_application_settings_snowplow_collector_uri_rename.rb b/db/post_migrate/20190802091750_cleanup_application_settings_snowplow_collector_uri_rename.rb deleted file mode 100644 index 77472585512..00000000000 --- a/db/post_migrate/20190802091750_cleanup_application_settings_snowplow_collector_uri_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupApplicationSettingsSnowplowCollectorUriRename < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :application_settings, :snowplow_collector_uri, :snowplow_collector_hostname - end - - def down - undo_cleanup_concurrent_column_rename :application_settings, :snowplow_collector_uri, :snowplow_collector_hostname - end -end diff --git a/db/post_migrate/20190802235445_add_index_on_id_and_type_and_public_to_keys.rb b/db/post_migrate/20190802235445_add_index_on_id_and_type_and_public_to_keys.rb deleted file mode 100644 index 9b4d74b4bea..00000000000 --- a/db/post_migrate/20190802235445_add_index_on_id_and_type_and_public_to_keys.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnIdAndTypeAndPublicToKeys < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - INDEX_NAME = "index_on_deploy_keys_id_and_type_and_public" - - def up - add_concurrent_index(:keys, - [:id, :type], - where: "public = 't'", - unique: true, - name: INDEX_NAME) - end - - def down - remove_concurrent_index_by_name(:keys, INDEX_NAME) - end -end diff --git a/db/post_migrate/20190809072552_set_self_monitoring_project_alerting_token.rb b/db/post_migrate/20190809072552_set_self_monitoring_project_alerting_token.rb deleted file mode 100644 index d10887fb5d5..00000000000 --- a/db/post_migrate/20190809072552_set_self_monitoring_project_alerting_token.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class SetSelfMonitoringProjectAlertingToken < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - # no-op - # Converted to no-op in https://gitlab.com/gitlab-org/gitlab/merge_requests/17049. - - # This migration has been made a no-op because the pre-requisite migration - # which creates the self-monitoring project has already been removed in - # https://gitlab.com/gitlab-org/gitlab/merge_requests/16864. As - # such, this migration would do nothing. - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190812070645_migrate_private_profile_nulls.rb b/db/post_migrate/20190812070645_migrate_private_profile_nulls.rb deleted file mode 100644 index 063c1e16c27..00000000000 --- a/db/post_migrate/20190812070645_migrate_private_profile_nulls.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class MigratePrivateProfileNulls < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY = 5.minutes.to_i - BATCH_SIZE = 1_000 - - disable_ddl_transaction! - - class User < ActiveRecord::Base - self.table_name = 'users' - - include ::EachBatch - end - - def up - # Migration will take about 7 hours - User.where(private_profile: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql("MIN(id)"), Arel.sql("MAX(id)")).first - delay = index * DELAY - - BackgroundMigrationWorker.perform_in(delay.seconds, 'MigrateNullPrivateProfileToFalse', [*range]) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20190819231552_update_knative_prometheus_query_for_invocation_count.rb b/db/post_migrate/20190819231552_update_knative_prometheus_query_for_invocation_count.rb deleted file mode 100644 index 828f551baf6..00000000000 --- a/db/post_migrate/20190819231552_update_knative_prometheus_query_for_invocation_count.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class UpdateKnativePrometheusQueryForInvocationCount < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - ::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190822185441_cleanup_epics_state_id_rename.rb b/db/post_migrate/20190822185441_cleanup_epics_state_id_rename.rb deleted file mode 100644 index 471b2ab9ca2..00000000000 --- a/db/post_migrate/20190822185441_cleanup_epics_state_id_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupEpicsStateIdRename < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :epics, :state, :state_id - end - - def down - rename_column_concurrently :epics, :state_id, :state - end -end diff --git a/db/post_migrate/20190827102026_migrate_code_owner_approval_status_to_protected_branches_in_batches.rb b/db/post_migrate/20190827102026_migrate_code_owner_approval_status_to_protected_branches_in_batches.rb deleted file mode 100644 index b109f582909..00000000000 --- a/db/post_migrate/20190827102026_migrate_code_owner_approval_status_to_protected_branches_in_batches.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -class MigrateCodeOwnerApprovalStatusToProtectedBranchesInBatches < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - BATCH_SIZE = 200 - - class Project < ActiveRecord::Base - include EachBatch - - self.table_name = 'projects' - self.inheritance_column = :_type_disabled - - has_many :protected_branches - end - - class ProtectedBranch < ActiveRecord::Base - include EachBatch - - self.table_name = 'protected_branches' - self.inheritance_column = :_type_disabled - - belongs_to :project - end - - def up - add_concurrent_index :projects, :id, name: "temp_active_projects_with_prot_branches", where: 'archived = false and pending_delete = false and merge_requests_require_code_owner_approval = true' - - ProtectedBranch - .joins(:project) - .where(projects: { archived: false, pending_delete: false, merge_requests_require_code_owner_approval: true }) - .each_batch(of: BATCH_SIZE) do |batch| - batch.update_all(code_owner_approval_required: true) - end - - remove_concurrent_index_by_name(:projects, "temp_active_projects_with_prot_branches") - end - - def down - # noop - # - end -end diff --git a/db/post_migrate/20190902160015_remove_support_bot_column_from_users.rb b/db/post_migrate/20190902160015_remove_support_bot_column_from_users.rb deleted file mode 100644 index 80d69b57f5d..00000000000 --- a/db/post_migrate/20190902160015_remove_support_bot_column_from_users.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveSupportBotColumnFromUsers < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - return unless column_exists?(:users, :support_bot) - - remove_column :users, :support_bot - end - - def down - # no-op because the column should not exist in the previous version - end -end diff --git a/db/post_migrate/20190904205212_remove_id_column_from_intermediate_release_milestones.rb b/db/post_migrate/20190904205212_remove_id_column_from_intermediate_release_milestones.rb deleted file mode 100644 index e4b65d26db6..00000000000 --- a/db/post_migrate/20190904205212_remove_id_column_from_intermediate_release_milestones.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class RemoveIdColumnFromIntermediateReleaseMilestones < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def change - remove_column :milestone_releases, :id, :bigint - end -end diff --git a/db/post_migrate/20190905091812_schedule_project_any_approval_rule_migration.rb b/db/post_migrate/20190905091812_schedule_project_any_approval_rule_migration.rb deleted file mode 100644 index be47e4dfdf5..00000000000 --- a/db/post_migrate/20190905091812_schedule_project_any_approval_rule_migration.rb +++ /dev/null @@ -1,49 +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 ScheduleProjectAnyApprovalRuleMigration < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 5_000 - MIGRATION = 'PopulateAnyApprovalRuleForProjects' - DELAY_INTERVAL = 8.minutes.to_i - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - include EachBatch - - self.table_name = 'projects' - - scope :with_approvals_before_merge, -> { where('approvals_before_merge <> 0') } - end - - def up - return unless Gitlab.ee? - - add_concurrent_index :projects, :id, - name: 'tmp_projects_with_approvals_before_merge', - where: 'approvals_before_merge <> 0' - - say "Scheduling `#{MIGRATION}` jobs" - - # We currently have ~43k project records with non-zero approvals_before_merge on GitLab.com. - # This means it'll schedule ~9 jobs (5k projects each) with a 8 minutes gap, - # so this should take ~1 hour for all background migrations to complete. - # - # The approximate expected number of affected rows is: 18k - - queue_background_migration_jobs_by_range_at_intervals( - ScheduleProjectAnyApprovalRuleMigration::Project.with_approvals_before_merge, - MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - - remove_concurrent_index_by_name(:projects, 'tmp_projects_with_approvals_before_merge') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190905091831_schedule_merge_request_any_approval_rule_migration.rb b/db/post_migrate/20190905091831_schedule_merge_request_any_approval_rule_migration.rb deleted file mode 100644 index cdec87270f0..00000000000 --- a/db/post_migrate/20190905091831_schedule_merge_request_any_approval_rule_migration.rb +++ /dev/null @@ -1,49 +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 ScheduleMergeRequestAnyApprovalRuleMigration < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 5_000 - MIGRATION = 'PopulateAnyApprovalRuleForMergeRequests' - DELAY_INTERVAL = 8.minutes.to_i - - disable_ddl_transaction! - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - - scope :with_approvals_before_merge, -> { where('approvals_before_merge <> 0') } - end - - def up - return unless Gitlab.ee? - - add_concurrent_index :merge_requests, :id, - name: 'tmp_merge_requests_with_approvals_before_merge', - where: 'approvals_before_merge <> 0' - - say "Scheduling `#{MIGRATION}` jobs" - - # We currently have ~440_000 merge request records with non-zero approvals_before_merge on GitLab.com. - # This means it'll schedule ~88 jobs (5k merge requests each) with a 8 minutes gap, - # so this should take ~12 hours for all background migrations to complete. - # - # The approximate expected number of affected rows is: 190k - - queue_background_migration_jobs_by_range_at_intervals( - ScheduleMergeRequestAnyApprovalRuleMigration::MergeRequest.with_approvals_before_merge, - MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - - remove_concurrent_index_by_name(:merge_requests, 'tmp_merge_requests_with_approvals_before_merge') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190909141517_update_cs_vulnerability_confidence_column.rb b/db/post_migrate/20190909141517_update_cs_vulnerability_confidence_column.rb deleted file mode 100644 index befa08e0cb6..00000000000 --- a/db/post_migrate/20190909141517_update_cs_vulnerability_confidence_column.rb +++ /dev/null @@ -1,32 +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 UpdateCsVulnerabilityConfidenceColumn < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - BATCH_SIZE = 1_000 - INTERVAL = 5.minutes - - # 137_424 records to be updated on GitLab.com, - # giving us an estimated runtime of 12 hours. - def up - # no-op in CE - return unless Gitlab.ee? - - migration = Gitlab::BackgroundMigration::UpdateVulnerabilityConfidence - migration_name = migration.to_s.demodulize - relation = migration::Occurrence.container_scanning_reports_with_medium_confidence - 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/20190910000130_add_index_on_application_id_on_oauth_access_tokens.rb b/db/post_migrate/20190910000130_add_index_on_application_id_on_oauth_access_tokens.rb deleted file mode 100644 index 78f7c0ecf0f..00000000000 --- a/db/post_migrate/20190910000130_add_index_on_application_id_on_oauth_access_tokens.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnApplicationIdOnOauthAccessTokens < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :oauth_access_tokens, :application_id - end - - def down - remove_concurrent_index :oauth_access_tokens, :application_id - end -end diff --git a/db/post_migrate/20190911251732_sync_issuables_state_id.rb b/db/post_migrate/20190911251732_sync_issuables_state_id.rb deleted file mode 100644 index 031837122fb..00000000000 --- a/db/post_migrate/20190911251732_sync_issuables_state_id.rb +++ /dev/null @@ -1,81 +0,0 @@ -# frozen_string_literal: true - -# Sync remaining records for issues/merge_requests tables where state_id -# is still null. -# For more information check: https://gitlab.com/gitlab-org/gitlab/issues/26823 -# It creates a temporary index before performing the UPDATES to sync values. -# -# In 09-11-2019 we have the following numbers for records with state_id == nil: -# -# 1348 issues - default batch size for each update 67 -# 10247 merge requests - default batch size for each update 511 - -class SyncIssuablesStateId < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - %i(issues merge_requests).each do |table| - temp_index_name = index_name_for(table) - - add_concurrent_index( - table, - 'id', - name: temp_index_name, - where: 'state_id IS NULL' - ) - - update_value = update_condition_for(table) - - update_column_in_batches(table, :state_id, update_value) do |table, query| - query.where(table[:state_id].eq(nil)) - end - ensure - remove_concurrent_index_by_name(table, temp_index_name) - end - end - - def down - # NO OP - end - - def update_condition_for(table) - value_expresson = - if table == :issues - issues_state_id_condition - else - merge_requests_state_id_condition - end - - Arel.sql(value_expresson) - end - - def index_name_for(table) - "idx_tmp_on_#{table}_where_state_id_is_null" - end - - def issues_state_id_condition - <<~SQL - CASE state - WHEN 'opened' THEN 1 - WHEN 'closed' THEN 2 - ELSE 2 - END - SQL - end - - def merge_requests_state_id_condition - <<~SQL - CASE state - WHEN 'opened' THEN 1 - WHEN 'closed' THEN 2 - WHEN 'merged' THEN 3 - WHEN 'locked' THEN 4 - ELSE 2 - END - SQL - end -end diff --git a/db/post_migrate/20190917173107_backfill_software_licenses_spdx_identifiers.rb b/db/post_migrate/20190917173107_backfill_software_licenses_spdx_identifiers.rb deleted file mode 100644 index 09492f5f99e..00000000000 --- a/db/post_migrate/20190917173107_backfill_software_licenses_spdx_identifiers.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -class BackfillSoftwareLicensesSpdxIdentifiers < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - CURRENT_LICENSES = { - 'AGPL-1.0' => 'AGPL-1.0', - 'AGPL-3.0' => 'AGPL-3.0', - 'Apache 2.0' => 'Apache-2.0', - 'Artistic-2.0' => 'Artistic-2.0', - 'BSD' => 'BSD-4-Clause', - 'CC0 1.0 Universal' => 'CC0-1.0', - 'CDDL-1.0' => 'CDDL-1.0', - 'CDDL-1.1' => 'CDDL-1.1', - 'EPL-1.0' => 'EPL-1.0', - 'EPL-2.0' => 'EPL-2.0', - 'GPLv2' => 'GPL-2.0', - 'GPLv3' => 'GPL-3.0', - 'ISC' => 'ISC', - 'LGPL' => 'LGPL-3.0-only', - 'LGPL-2.1' => 'LGPL-2.1', - 'MIT' => 'MIT', - 'Mozilla Public License 2.0' => 'MPL-2.0', - 'MS-PL' => 'MS-PL', - 'MS-RL' => 'MS-RL', - 'New BSD' => 'BSD-3-Clause', - 'Python Software Foundation License' => 'Python-2.0', - 'ruby' => 'Ruby', - 'Simplified BSD' => 'BSD-2-Clause', - 'WTFPL' => 'WTFPL', - 'Zlib' => 'Zlib' - }.freeze - - disable_ddl_transaction! - - # 25 records to be updated on GitLab.com - def up - return unless Gitlab.ee? - - say "Expect #{CURRENT_LICENSES.count} updates to the software_licenses table to occur" - CURRENT_LICENSES.each do |name, spdx_identifier| - # The following cop is disabled because of https://gitlab.com/gitlab-org/gitlab/issues/33470 - # For more context see https://gitlab.com/gitlab-org/gitlab/merge_requests/17004#note_226264823 - # rubocop:disable Migration/UpdateColumnInBatches - update_column_in_batches(:software_licenses, :spdx_identifier, spdx_identifier) do |table, query| - query.where(table[:name].eq(name)) - end - end - end - - def down - return unless Gitlab.ee? - - update_column_in_batches(:software_licenses, :spdx_identifier, nil) - end -end diff --git a/db/post_migrate/20190918104222_schedule_productivity_analytics_backfill.rb b/db/post_migrate/20190918104222_schedule_productivity_analytics_backfill.rb deleted file mode 100644 index cd759735f00..00000000000 --- a/db/post_migrate/20190918104222_schedule_productivity_analytics_backfill.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class ScheduleProductivityAnalyticsBackfill < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - # no-op since the migration was removed - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20190924152703_migrate_issue_trackers_data.rb b/db/post_migrate/20190924152703_migrate_issue_trackers_data.rb deleted file mode 100644 index 93ea501e7e0..00000000000 --- a/db/post_migrate/20190924152703_migrate_issue_trackers_data.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class MigrateIssueTrackersData < 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 - # no need - end -end diff --git a/db/post_migrate/20190926180443_schedule_epic_issues_after_epics_move.rb b/db/post_migrate/20190926180443_schedule_epic_issues_after_epics_move.rb deleted file mode 100644 index 113b7104209..00000000000 --- a/db/post_migrate/20190926180443_schedule_epic_issues_after_epics_move.rb +++ /dev/null @@ -1,35 +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 ScheduleEpicIssuesAfterEpicsMove < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INTERVAL = 5.minutes.to_i - BATCH_SIZE = 100 - MIGRATION = 'MoveEpicIssuesAfterEpics' - - disable_ddl_transaction! - - class Epic < ActiveRecord::Base - self.table_name = 'epics' - - include ::EachBatch - end - - def up - return unless ::Gitlab.ee? - - Epic.each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck('MIN(id)', 'MAX(id)').first - delay = index * INTERVAL - BackgroundMigrationWorker.perform_in(delay, MIGRATION, range) - end - end - - def down - # no need - end -end diff --git a/db/post_migrate/20191002031332_schedule_pages_metadata_migration.rb b/db/post_migrate/20191002031332_schedule_pages_metadata_migration.rb deleted file mode 100644 index 0cd24da50d0..00000000000 --- a/db/post_migrate/20191002031332_schedule_pages_metadata_migration.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class SchedulePagesMetadataMigration < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - BATCH_SIZE = 10_000 - MIGRATION = 'MigratePagesMetadata' - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'projects' - end - - def up - say "Scheduling `#{MIGRATION}` jobs" - - # At the time of writing there are ~10_669_292 records to be inserted for GitLab.com, - # batches of 10_000 with delay interval of 2 minutes gives us an estimate of close to 36 hours. - 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/20191007163701_populate_remaining_any_approver_rules_for_merge_requests.rb b/db/post_migrate/20191007163701_populate_remaining_any_approver_rules_for_merge_requests.rb deleted file mode 100644 index e1c0f1d6c0c..00000000000 --- a/db/post_migrate/20191007163701_populate_remaining_any_approver_rules_for_merge_requests.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 PopulateRemainingAnyApproverRulesForMergeRequests < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10_000 - MIGRATION = 'PopulateAnyApprovalRuleForMergeRequests' - - disable_ddl_transaction! - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - - scope :with_approvals_before_merge, -> { where.not(approvals_before_merge: 0) } - end - - def up - return unless Gitlab.ee? - - add_concurrent_index :merge_requests, :id, - name: 'tmp_merge_requests_with_approvals_before_merge', - where: 'approvals_before_merge != 0' - - Gitlab::BackgroundMigration.steal(MIGRATION) - - PopulateRemainingAnyApproverRulesForMergeRequests::MergeRequest.with_approvals_before_merge.each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - Gitlab::BackgroundMigration::PopulateAnyApprovalRuleForMergeRequests.new.perform(*range) - end - - remove_concurrent_index_by_name(:merge_requests, 'tmp_merge_requests_with_approvals_before_merge') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20191007163736_populate_remaining_any_approver_rules_for_projects.rb b/db/post_migrate/20191007163736_populate_remaining_any_approver_rules_for_projects.rb deleted file mode 100644 index fce17ffcf16..00000000000 --- a/db/post_migrate/20191007163736_populate_remaining_any_approver_rules_for_projects.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 PopulateRemainingAnyApproverRulesForProjects < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 5_000 - MIGRATION = 'PopulateAnyApprovalRuleForProjects' - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - include EachBatch - - self.table_name = 'projects' - - scope :with_approvals_before_merge, -> { where.not(approvals_before_merge: 0) } - end - - def up - return unless Gitlab.ee? - - add_concurrent_index :projects, :id, - name: 'tmp_projects_with_approvals_before_merge', - where: 'approvals_before_merge != 0' - - Gitlab::BackgroundMigration.steal(MIGRATION) - - PopulateRemainingAnyApproverRulesForProjects::Project.with_approvals_before_merge.each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - Gitlab::BackgroundMigration::PopulateAnyApprovalRuleForProjects.new.perform(*range) - end - - remove_concurrent_index_by_name(:projects, 'tmp_projects_with_approvals_before_merge') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20191008143850_fix_any_approver_rule_for_projects.rb b/db/post_migrate/20191008143850_fix_any_approver_rule_for_projects.rb deleted file mode 100644 index c1f4b7e42ab..00000000000 --- a/db/post_migrate/20191008143850_fix_any_approver_rule_for_projects.rb +++ /dev/null @@ -1,51 +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 FixAnyApproverRuleForProjects < ActiveRecord::Migration[5.2] - DOWNTIME = false - BATCH_SIZE = 1000 - - disable_ddl_transaction! - - class ApprovalProjectRule < ActiveRecord::Base - NON_EXISTENT_RULE_TYPE = 4 - ANY_APPROVER_RULE_TYPE = 3 - - include EachBatch - - self.table_name = 'approval_project_rules' - - scope :any_approver, -> { where(rule_type: ANY_APPROVER_RULE_TYPE) } - scope :non_existent_rule_type, -> { where(rule_type: NON_EXISTENT_RULE_TYPE) } - end - - def up - return unless Gitlab.ee? - - # Remove approval project rule with rule type 4 if the project has a rule with rule_type 3 - # - # Currently, there is no projects on gitlab.com which have both rules with 3 and 4 rule type - # There's a code-level validation for a rule, which doesn't allow to create rules with the same names - # - # But in order to avoid failing the update query due to uniqueness constraint - # Let's run the delete query to be sure - project_ids = FixAnyApproverRuleForProjects::ApprovalProjectRule.any_approver.select(:project_id) - FixAnyApproverRuleForProjects::ApprovalProjectRule - .non_existent_rule_type - .where(project_id: project_ids) - .delete_all - - # Set approval project rule types to 3 - # Currently there are 18_445 records to be updated - FixAnyApproverRuleForProjects::ApprovalProjectRule.non_existent_rule_type.each_batch(of: BATCH_SIZE) do |rules| - rules.update_all(rule_type: FixAnyApproverRuleForProjects::ApprovalProjectRule::ANY_APPROVER_RULE_TYPE) - end - end - - def down - # The migration doesn't leave the database in an inconsistent state - # And can be run multiple times - end -end diff --git a/db/post_migrate/20191014030134_cleanup_design_management_version_user_to_author_rename.rb b/db/post_migrate/20191014030134_cleanup_design_management_version_user_to_author_rename.rb deleted file mode 100644 index e7132cbeeb7..00000000000 --- a/db/post_migrate/20191014030134_cleanup_design_management_version_user_to_author_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupDesignManagementVersionUserToAuthorRename < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :design_management_versions, :user_id, :author_id - end - - def down - undo_cleanup_concurrent_column_rename :design_management_versions, :user_id, :author_id - end -end diff --git a/db/post_migrate/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects.rb b/db/post_migrate/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects.rb deleted file mode 100644 index f31471c2891..00000000000 --- a/db/post_migrate/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects.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 DropMergeRequestsRequireCodeOwnerApprovalFromProjects < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_column :projects, :merge_requests_require_code_owner_approval, :boolean - end - - def down - add_column :projects, :merge_requests_require_code_owner_approval, :boolean # rubocop:disable Migration/AddColumnsToWideTables - - add_concurrent_index( - :projects, - %i[archived pending_delete merge_requests_require_code_owner_approval], - name: 'projects_requiring_code_owner_approval', - where: '((pending_delete = false) AND (archived = false) AND (merge_requests_require_code_owner_approval = true))' - ) - end -end diff --git a/db/post_migrate/20191017045817_schedule_fix_gitlab_com_pages_access_level.rb b/db/post_migrate/20191017045817_schedule_fix_gitlab_com_pages_access_level.rb deleted file mode 100644 index fc44568ea17..00000000000 --- a/db/post_migrate/20191017045817_schedule_fix_gitlab_com_pages_access_level.rb +++ /dev/null @@ -1,17 +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. - -# Code of this migration was removed after execution on gitlab.com -# https://gitlab.com/gitlab-org/gitlab/issues/34018 -# Empty migration is left here to avoid any problems with rolling back -class ScheduleFixGitlabComPagesAccessLevel < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - end - - def down - end -end diff --git a/db/post_migrate/20191017180026_drop_ci_build_trace_sections_id.rb b/db/post_migrate/20191017180026_drop_ci_build_trace_sections_id.rb deleted file mode 100644 index 0405e23b465..00000000000 --- a/db/post_migrate/20191017180026_drop_ci_build_trace_sections_id.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class DropCiBuildTraceSectionsId < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - ## - # This column has already been ignored since 12.4 - # See https://gitlab.com/gitlab-org/gitlab/issues/32569 - remove_column :ci_build_trace_sections, :id - end - - def down - ## - # We don't backfill serial ids as it's not used in application code - # and quite expensive process. - add_column :ci_build_trace_sections, :id, :bigint - end -end diff --git a/db/post_migrate/20191021101942_remove_empty_github_service_templates.rb b/db/post_migrate/20191021101942_remove_empty_github_service_templates.rb deleted file mode 100644 index 64abe93b3e8..00000000000 --- a/db/post_migrate/20191021101942_remove_empty_github_service_templates.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -## It's expected to delete one record on GitLab.com -# -class RemoveEmptyGithubServiceTemplates < ActiveRecord::Migration[5.2] - DOWNTIME = false - - class Service < ActiveRecord::Base - self.table_name = 'services' - self.inheritance_column = :_type_disabled - - serialize :properties, JSON - end - - def up - relationship.where(properties: {}).delete_all - end - - def down - relationship.find_or_create_by!(properties: {}) - end - - private - - def relationship - RemoveEmptyGithubServiceTemplates::Service.where(template: true, type: 'GithubService') - end -end diff --git a/db/post_migrate/20191022113635_nullify_feature_flag_plaintext_tokens.rb b/db/post_migrate/20191022113635_nullify_feature_flag_plaintext_tokens.rb deleted file mode 100644 index 9ade1454844..00000000000 --- a/db/post_migrate/20191022113635_nullify_feature_flag_plaintext_tokens.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -class NullifyFeatureFlagPlaintextTokens < ActiveRecord::Migration[5.2] - DOWNTIME = false - - class FeatureFlagsClient < ActiveRecord::Base - include EachBatch - - self.table_name = 'operations_feature_flags_clients' - - scope :with_encrypted_token, -> { where.not(token_encrypted: nil) } - scope :with_plaintext_token, -> { where.not(token: nil) } - scope :without_plaintext_token, -> { where(token: nil) } - end - - disable_ddl_transaction! - - def up - return unless Gitlab.ee? - - # 7357 records to be updated on GitLab.com - FeatureFlagsClient.with_encrypted_token.with_plaintext_token.each_batch do |relation| - relation.update_all(token: nil) - end - end - - def down - return unless Gitlab.ee? - - # There is no way to restore only the tokens that were NULLifyed in the `up` - # but we can do is to restore _all_ of them in case it is needed. - say_with_time('Decrypting tokens from operations_feature_flags_clients') do - FeatureFlagsClient.with_encrypted_token.without_plaintext_token.find_each do |feature_flags_client| - token = Gitlab::CryptoHelper.aes256_gcm_decrypt(feature_flags_client.token_encrypted) - feature_flags_client.update_column(:token, token) - end - end - end -end diff --git a/db/post_migrate/20191029095537_cleanup_application_settings_snowplow_site_id_rename.rb b/db/post_migrate/20191029095537_cleanup_application_settings_snowplow_site_id_rename.rb deleted file mode 100644 index 83b4a2af2b6..00000000000 --- a/db/post_migrate/20191029095537_cleanup_application_settings_snowplow_site_id_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupApplicationSettingsSnowplowSiteIdRename < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :application_settings, :snowplow_site_id, :snowplow_app_id - end - - def down - undo_cleanup_concurrent_column_rename :application_settings, :snowplow_site_id, :snowplow_app_id - end -end diff --git a/db/post_migrate/20191030193050_remove_pendo_from_application_settings.rb b/db/post_migrate/20191030193050_remove_pendo_from_application_settings.rb deleted file mode 100644 index c1a1cc01aa4..00000000000 --- a/db/post_migrate/20191030193050_remove_pendo_from_application_settings.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemovePendoFromApplicationSettings < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - - def up - remove_column :application_settings, :pendo_enabled - remove_column :application_settings, :pendo_url - end - - def down - add_column_with_default :application_settings, :pendo_enabled, :boolean, default: false, allow_null: false # rubocop:disable Migration/AddColumnWithDefault - add_column :application_settings, :pendo_url, :string, limit: 255 - end -end diff --git a/db/post_migrate/20191030223057_backfill_version_author_and_created_at.rb b/db/post_migrate/20191030223057_backfill_version_author_and_created_at.rb deleted file mode 100644 index 3ec6c59f166..00000000000 --- a/db/post_migrate/20191030223057_backfill_version_author_and_created_at.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -class BackfillVersionAuthorAndCreatedAt < ActiveRecord::Migration[5.2] - DOWNTIME = false - MIGRATION = 'BackfillVersionDataFromGitaly' - BATCH_SIZE = 500 - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - self.table_name = 'projects' - self.inheritance_column = :_type_disabled - end - - class Issue < ActiveRecord::Base - self.table_name = 'issues' - self.inheritance_column = :_type_disabled - end - - class Version < ActiveRecord::Base - include EachBatch - self.table_name = 'design_management_versions' - self.inheritance_column = :_type_disabled - - # Returns unique issue ids of versions that are not in projects - # that are pending deletion. - scope :with_unique_issue_ids, -> do - versions = Version.arel_table - issues = Issue.arel_table - projects = Project.arel_table - - select(versions[:issue_id]).where( - versions[:author_id].eq(nil).or( - versions[:created_at].eq(nil) - ).and( - issues[:project_id].not_in( - projects.project(projects[:id]).where(projects[:pending_delete].eq(true)) - ) - ) - ).joins( - versions.join(issues).on( - issues[:id].eq(versions[:issue_id]) - ).join_sources - ).distinct - end - end - - # This migration will make around ~1300 UPDATE queries on GitLab.com, - # one per design_management_versions record as the migration will update - # each record individually. - # - # It will make around 870 Gitaly `ListCommitsByOid` requests on GitLab.com. - # One for every unique issue with design_management_versions records. - def up - return unless Gitlab.ee? # no-op for CE - - Version.with_unique_issue_ids.each_batch(of: BATCH_SIZE) do |versions, index| - jobs = versions.map { |version| [MIGRATION, [version.issue_id]] } - - BackgroundMigrationWorker.bulk_perform_async(jobs) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20191031112603_remove_limits_from_plans.rb b/db/post_migrate/20191031112603_remove_limits_from_plans.rb deleted file mode 100644 index 30fb6a9d193..00000000000 --- a/db/post_migrate/20191031112603_remove_limits_from_plans.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class RemoveLimitsFromPlans < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - remove_column :plans, :active_pipelines_limit - remove_column :plans, :pipeline_size_limit - remove_column :plans, :active_jobs_limit - end - - def down - add_column :plans, :active_pipelines_limit, :integer - add_column :plans, :pipeline_size_limit, :integer - add_column :plans, :active_jobs_limit, :integer - end -end diff --git a/db/post_migrate/20191104142124_nullify_users_role.rb b/db/post_migrate/20191104142124_nullify_users_role.rb deleted file mode 100644 index ab8eae46745..00000000000 --- a/db/post_migrate/20191104142124_nullify_users_role.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class NullifyUsersRole < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - INDEX_NAME = 'partial_index_users_updated_at_for_cleaning_mistaken_values' - - DOWNTIME = false - - def up - # expected updated users count is around 10K - # rubocop: disable Migration/UpdateLargeTable - add_concurrent_index(:users, :updated_at, where: 'role = 0', name: INDEX_NAME) - - update_column_in_batches(:users, :role, nil) do |table, query| - query.where(table[:updated_at].lt('2019-11-05 12:08:00')).where(table[:role].eq(0)) - end - - remove_concurrent_index_by_name(:users, INDEX_NAME) - end - - def down - # noop - end -end diff --git a/db/post_migrate/20191105094625_set_report_type_for_vulnerabilities.rb b/db/post_migrate/20191105094625_set_report_type_for_vulnerabilities.rb deleted file mode 100644 index 40e9e3bddc8..00000000000 --- a/db/post_migrate/20191105094625_set_report_type_for_vulnerabilities.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -class SetReportTypeForVulnerabilities < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - # set report_type based on vulnerability_occurrences from which the vulnerabilities were promoted, - # that is, first vulnerability_occurrences among those having the same vulnerability_id - execute <<~SQL - WITH first_findings_for_vulnerabilities AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT MIN(id) AS id, vulnerability_id - FROM vulnerability_occurrences - WHERE vulnerability_id IS NOT NULL - GROUP BY vulnerability_id - ) - UPDATE vulnerabilities - SET report_type = vulnerability_occurrences.report_type - FROM vulnerability_occurrences, first_findings_for_vulnerabilities - WHERE vulnerability_occurrences.id = first_findings_for_vulnerabilities.id - AND vulnerabilities.id = vulnerability_occurrences.vulnerability_id - SQL - - # set default report_type for orphan vulnerabilities (there should be none but...) - execute 'UPDATE vulnerabilities SET report_type = 0 WHERE report_type IS NULL' - - change_column_null :vulnerabilities, :report_type, false - end - - def down - change_column_null :vulnerabilities, :report_type, true - - execute 'UPDATE vulnerabilities SET report_type = NULL' - end -end diff --git a/db/post_migrate/20191105140942_add_indices_to_abuse_reports.rb b/db/post_migrate/20191105140942_add_indices_to_abuse_reports.rb deleted file mode 100644 index 2b2d04e8ccc..00000000000 --- a/db/post_migrate/20191105140942_add_indices_to_abuse_reports.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddIndicesToAbuseReports < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index :abuse_reports, :user_id - end - - def down - remove_concurrent_index :abuse_reports, :user_id - end -end diff --git a/db/post_migrate/20191108202723_add_unique_constraint_to_software_licenses.rb b/db/post_migrate/20191108202723_add_unique_constraint_to_software_licenses.rb deleted file mode 100644 index 580d3a189c8..00000000000 --- a/db/post_migrate/20191108202723_add_unique_constraint_to_software_licenses.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -class AddUniqueConstraintToSoftwareLicenses < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - DOWNTIME = false - NEW_INDEX = 'index_software_licenses_on_unique_name' - OLD_INDEX = 'index_software_licenses_on_name' - - disable_ddl_transaction! - - # 12 software licenses will be removed on GitLab.com - # 0 software license policies will be updated on GitLab.com - def up(attempts: 100) - remove_redundant_software_licenses! - - add_concurrent_index :software_licenses, :name, unique: true, name: NEW_INDEX - remove_concurrent_index :software_licenses, :name, name: OLD_INDEX - rescue ActiveRecord::RecordNotUnique - retry if (attempts -= 1) > 0 - - raise StandardError, <<~EOS - Failed to add an unique index to software_licenses, despite retrying the - migration 100 times. - - See https://gitlab.com/gitlab-org/gitlab/merge_requests/19840. - EOS - end - - def down - remove_concurrent_index :software_licenses, :name, unique: true, name: NEW_INDEX - add_concurrent_index :software_licenses, :name, name: OLD_INDEX - end - - private - - def remove_redundant_software_licenses! - redundant_software_licenses = execute <<~SQL - SELECT min(id) id, name - FROM software_licenses - WHERE name IN (select name from software_licenses group by name having count(name) > 1) - GROUP BY name - SQL - say "Detected #{redundant_software_licenses.count} duplicates." - - redundant_software_licenses.each_row do |id, name| - say_with_time("Reassigning policies that reference software license #{name}.") do - duplicates = software_licenses.where.not(id: id).where(name: name) - - software_license_policies - .where(software_license_id: duplicates) - .update_all(software_license_id: id) - - duplicates.delete_all - end - end - end - - def table(name) - Class.new(ActiveRecord::Base) { self.table_name = name } - end - - def software_licenses - @software_licenses ||= table(:software_licenses) - end - - def software_license_policies - @software_license_policies ||= table(:software_license_policies) - end -end diff --git a/db/post_migrate/20191112023159_complete_pages_metadata_migration.rb b/db/post_migrate/20191112023159_complete_pages_metadata_migration.rb deleted file mode 100644 index 6468eef8cc1..00000000000 --- a/db/post_migrate/20191112023159_complete_pages_metadata_migration.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class CompletePagesMetadataMigration < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - Gitlab::BackgroundMigration.steal('MigratePagesMetadata') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20191112115317_change_vulnerabilities_title_html_to_nullable.rb b/db/post_migrate/20191112115317_change_vulnerabilities_title_html_to_nullable.rb deleted file mode 100644 index 6e0f3247410..00000000000 --- a/db/post_migrate/20191112115317_change_vulnerabilities_title_html_to_nullable.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class ChangeVulnerabilitiesTitleHtmlToNullable < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def change - change_column_null :vulnerabilities, :title_html, true - end -end diff --git a/db/post_migrate/20191114173624_set_resolved_state_on_vulnerabilities.rb b/db/post_migrate/20191114173624_set_resolved_state_on_vulnerabilities.rb deleted file mode 100644 index 2900ef852a5..00000000000 --- a/db/post_migrate/20191114173624_set_resolved_state_on_vulnerabilities.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class SetResolvedStateOnVulnerabilities < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - execute <<~SQL - -- selecting IDs for all non-orphan Findings that either have no feedback or it's a non-dismissal feedback - WITH resolved_vulnerability_ids AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( - SELECT DISTINCT vulnerability_id AS id - FROM vulnerability_occurrences - LEFT JOIN vulnerability_feedback ON vulnerability_feedback.project_fingerprint = ENCODE(vulnerability_occurrences.project_fingerprint::bytea, 'HEX') - WHERE vulnerability_id IS NOT NULL - AND (vulnerability_feedback.id IS NULL OR vulnerability_feedback.feedback_type <> 0) - ) - UPDATE vulnerabilities - SET state = 3, resolved_by_id = closed_by_id, resolved_at = NOW() - FROM resolved_vulnerability_ids - WHERE vulnerabilities.id IN (resolved_vulnerability_ids.id) - AND state = 2 -- only 'closed' Vulnerabilities become 'resolved' - SQL - end - - def down - execute <<~SQL - UPDATE vulnerabilities - SET state = 2, resolved_by_id = NULL, resolved_at = NULL -- state = 'closed' - WHERE state = 3 -- 'resolved' - SQL - end -end diff --git a/db/post_migrate/20191114204343_remove_milestone_id_from_epics.rb b/db/post_migrate/20191114204343_remove_milestone_id_from_epics.rb deleted file mode 100644 index 4ef6decda95..00000000000 --- a/db/post_migrate/20191114204343_remove_milestone_id_from_epics.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class RemoveMilestoneIdFromEpics < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - remove_column :epics, :milestone_id - end - - def down - add_column :epics, :milestone_id, :integer - end -end diff --git a/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb b/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb deleted file mode 100644 index 97f2e568a7e..00000000000 --- a/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -class MigrateEpicMentionsToDb < ActiveRecord::Migration[5.2] - DOWNTIME = false - - disable_ddl_transaction! - - DELAY = 2.minutes.to_i - BATCH_SIZE = 10000 - MIGRATION = 'UserMentions::CreateResourceUserMention' - - JOIN = "LEFT JOIN epic_user_mentions on epics.id = epic_user_mentions.epic_id" - QUERY_CONDITIONS = "(description like '%@%' OR title like '%@%') AND epic_user_mentions.epic_id is null" - - class Epic < ActiveRecord::Base - include EachBatch - - self.table_name = 'epics' - end - - def up - return unless Gitlab.ee? - - Epic - .joins(JOIN) - .where(QUERY_CONDITIONS) - .each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck(Arel.sql('MIN(epics.id)'), Arel.sql('MAX(epics.id)')).first - BackgroundMigrationWorker.perform_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range]) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20191115115522_migrate_epic_notes_mentions_to_db.rb b/db/post_migrate/20191115115522_migrate_epic_notes_mentions_to_db.rb deleted file mode 100644 index 7914ff59dbd..00000000000 --- a/db/post_migrate/20191115115522_migrate_epic_notes_mentions_to_db.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -class MigrateEpicNotesMentionsToDb < 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 = 'epic_mentions_temp_index' - INDEX_CONDITION = "note LIKE '%@%'::text AND notes.noteable_type = 'Epic'" - QUERY_CONDITIONS = "#{INDEX_CONDITION} AND epic_user_mentions.epic_id IS NULL" - JOIN = 'INNER JOIN epics ON epics.id = notes.noteable_id LEFT JOIN epic_user_mentions ON notes.id = epic_user_mentions.note_id' - - class Note < ActiveRecord::Base - include EachBatch - - self.table_name = 'notes' - end - - def up - return unless Gitlab.ee? - - # 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, ['Epic', 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/20191118211629_migrate_ops_feature_flags_scopes_target_user_ids.rb b/db/post_migrate/20191118211629_migrate_ops_feature_flags_scopes_target_user_ids.rb deleted file mode 100644 index 47622a216d9..00000000000 --- a/db/post_migrate/20191118211629_migrate_ops_feature_flags_scopes_target_user_ids.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -class MigrateOpsFeatureFlagsScopesTargetUserIds < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class OperationsFeatureFlagScope < ActiveRecord::Base - include EachBatch - self.table_name = 'operations_feature_flag_scopes' - self.inheritance_column = :_type_disabled - end - - ### - # 2019-11-26 - # - # There are about 1000 rows in the operations_feature_flag_scopes table on gitlab.com. - # This migration will update about 30 of them. - # https://gitlab.com/gitlab-org/gitlab/merge_requests/20325#note_250742098 - # - # This should take a few seconds to run. - # https://gitlab.com/gitlab-org/gitlab/merge_requests/20325#note_254871603 - # - ### - def up - OperationsFeatureFlagScope.where("strategies @> ?", [{ 'name': 'userWithId' }].to_json).each_batch do |scopes| - scopes.each do |scope| - if scope.active - default_strategy = scope.strategies.find { |s| s['name'] == 'default' } - - if default_strategy.present? - scope.update({ strategies: [default_strategy] }) - end - else - user_with_id_strategy = scope.strategies.find { |s| s['name'] == 'userWithId' } - - scope.update({ - active: true, - strategies: [user_with_id_strategy] - }) - end - end - end - end - - def down - # This is not reversible. - # The old Target Users feature required the same list of user ids to be applied to each environment scope. - # Now we allow the list of user ids to differ for each scope. - end -end diff --git a/db/post_migrate/20191119221041_cleanup_software_license_policies_classification_rename.rb b/db/post_migrate/20191119221041_cleanup_software_license_policies_classification_rename.rb deleted file mode 100644 index eb605dce5aa..00000000000 --- a/db/post_migrate/20191119221041_cleanup_software_license_policies_classification_rename.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class CleanupSoftwareLicensePoliciesClassificationRename < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :software_license_policies, :approval_status, :classification - end - - def down - undo_cleanup_concurrent_column_rename :software_license_policies, :approval_status, :classification - end -end diff --git a/db/post_migrate/20191121122856_drop_packages_package_metadata_table.rb b/db/post_migrate/20191121122856_drop_packages_package_metadata_table.rb deleted file mode 100644 index 9e24f64660c..00000000000 --- a/db/post_migrate/20191121122856_drop_packages_package_metadata_table.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class DropPackagesPackageMetadataTable < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - drop_table :packages_package_metadata - end - - def down - create_table :packages_package_metadata do |t| - t.references :package, index: { unique: true }, null: false, foreign_key: { to_table: :packages_packages, on_delete: :cascade }, type: :integer - t.binary :metadata, null: false - end - end -end diff --git a/db/post_migrate/20191122135327_remove_plaintext_columns_from_application_settings.rb b/db/post_migrate/20191122135327_remove_plaintext_columns_from_application_settings.rb deleted file mode 100644 index b5cd58b10a8..00000000000 --- a/db/post_migrate/20191122135327_remove_plaintext_columns_from_application_settings.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class RemovePlaintextColumnsFromApplicationSettings < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - PLAINTEXT_ATTRIBUTES = %w[ - akismet_api_key - elasticsearch_aws_secret_access_key - recaptcha_private_key - recaptcha_site_key - slack_app_secret - slack_app_verification_token - ].freeze - - def up - PLAINTEXT_ATTRIBUTES.each do |plaintext_attribute| - remove_column :application_settings, plaintext_attribute - end - end - - def down - PLAINTEXT_ATTRIBUTES.each do |plaintext_attribute| - add_column :application_settings, plaintext_attribute, :text - end - end -end diff --git a/db/post_migrate/20191125024005_cleanup_deploy_access_levels_for_removed_groups.rb b/db/post_migrate/20191125024005_cleanup_deploy_access_levels_for_removed_groups.rb deleted file mode 100644 index 29592612a02..00000000000 --- a/db/post_migrate/20191125024005_cleanup_deploy_access_levels_for_removed_groups.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class CleanupDeployAccessLevelsForRemovedGroups < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - return unless Gitlab.ee? - - delete = <<~SQL - DELETE FROM protected_environment_deploy_access_levels d - USING protected_environments p - WHERE d.protected_environment_id=p.id - AND d.group_id IS NOT NULL - AND NOT EXISTS (SELECT 1 FROM project_group_links WHERE project_id=p.project_id AND group_id=d.group_id) - RETURNING * - SQL - - # At the time of writing there are 4 such records on GitLab.com, - # execution time is expected to be around 15ms. - records = execute(delete) - - logger = Gitlab::BackgroundMigration::Logger.build - records.to_a.each do |record| - logger.info record.as_json.merge(message: "protected_environments_deploy_access_levels was deleted") - end - end - - def down - # There is no pragmatic way to restore - # the records deleted in the `#up` method above. - end -end diff --git a/db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb b/db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb deleted file mode 100644 index 7f91d5112b3..00000000000 --- a/db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class DropProjectCiCdSettingsMergeTrainsEnabled < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_column :project_ci_cd_settings, :merge_trains_enabled - end - - def down - # rubocop:disable Migration/AddColumnWithDefault - add_column_with_default :project_ci_cd_settings, :merge_trains_enabled, :boolean, default: false, allow_null: true # rubocop:disable Migration/UpdateLargeTable - # rubocop:enable Migration/AddColumnWithDefault - end -end diff --git a/db/post_migrate/20191202031812_drop_operations_feature_flags_clients_token.rb b/db/post_migrate/20191202031812_drop_operations_feature_flags_clients_token.rb deleted file mode 100644 index 93cef322f02..00000000000 --- a/db/post_migrate/20191202031812_drop_operations_feature_flags_clients_token.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class DropOperationsFeatureFlagsClientsToken < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # Ignored in 12.5 - https://gitlab.com/gitlab-org/gitlab/merge_requests/18923 - remove_column :operations_feature_flags_clients, :token - end - - def down - unless column_exists?(:operations_feature_flags_clients, :token) - add_column :operations_feature_flags_clients, :token, :string - end - - add_concurrent_index :operations_feature_flags_clients, [:project_id, :token], unique: true, - name: 'index_operations_feature_flags_clients_on_project_id_and_token' - end -end diff --git a/db/post_migrate/20191204114127_delete_legacy_triggers.rb b/db/post_migrate/20191204114127_delete_legacy_triggers.rb deleted file mode 100644 index 82d901ae689..00000000000 --- a/db/post_migrate/20191204114127_delete_legacy_triggers.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class DeleteLegacyTriggers < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - execute <<~SQL - DELETE FROM ci_triggers WHERE owner_id IS NULL - SQL - - change_column_null :ci_triggers, :owner_id, false - end - - def down - change_column_null :ci_triggers, :owner_id, true - end -end diff --git a/db/post_migrate/20191205084057_update_minimum_password_length.rb b/db/post_migrate/20191205084057_update_minimum_password_length.rb deleted file mode 100644 index d9324347075..00000000000 --- a/db/post_migrate/20191205084057_update_minimum_password_length.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class UpdateMinimumPasswordLength < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - value_to_be_updated_to = [ - Devise.password_length.min, - ApplicationSetting::DEFAULT_MINIMUM_PASSWORD_LENGTH - ].max - - execute "UPDATE application_settings SET minimum_password_length = #{value_to_be_updated_to}" - - ApplicationSetting.expire - end - - def down - value_to_be_updated_to = ApplicationSetting::DEFAULT_MINIMUM_PASSWORD_LENGTH - - execute "UPDATE application_settings SET minimum_password_length = #{value_to_be_updated_to}" - - ApplicationSetting.expire - end -end diff --git a/db/post_migrate/20191209215316_knative_0_9_prometheus_update.rb b/db/post_migrate/20191209215316_knative_0_9_prometheus_update.rb deleted file mode 100644 index 52127f71cd0..00000000000 --- a/db/post_migrate/20191209215316_knative_0_9_prometheus_update.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class Knative09PrometheusUpdate < ActiveRecord::Migration[5.2] - DOWNTIME = false - - def up - ::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20191212162434_change_commit_user_mentions_commit_id_column_type_cleanup.rb b/db/post_migrate/20191212162434_change_commit_user_mentions_commit_id_column_type_cleanup.rb deleted file mode 100644 index aed9d335af9..00000000000 --- a/db/post_migrate/20191212162434_change_commit_user_mentions_commit_id_column_type_cleanup.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class ChangeCommitUserMentionsCommitIdColumnTypeCleanup < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - NEW_INDEX = 'commit_id_for_type_change_and_note_id_index' - OLD_INDEX = 'commit_user_mentions_on_commit_id_and_note_id_index' - - def up - cleanup_concurrent_column_type_change :commit_user_mentions, :commit_id - end - - def down - change_column_type_concurrently :commit_user_mentions, :commit_id, :binary - - # change_column_type_concurrently creates a new index based on existing commit_id_and_note_id_index` naming it - # `commit_id_for_type_change_and_note_id_index` so we'll rename it back to its original name. - add_concurrent_index :commit_user_mentions, [:commit_id_for_type_change, :note_id], name: OLD_INDEX - remove_concurrent_index_by_name :commit_user_mentions, NEW_INDEX - end -end diff --git a/db/post_migrate/20191218225624_add_index_on_project_id_to_ci_pipelines.rb b/db/post_migrate/20191218225624_add_index_on_project_id_to_ci_pipelines.rb deleted file mode 100644 index ab6c3b0616a..00000000000 --- a/db/post_migrate/20191218225624_add_index_on_project_id_to_ci_pipelines.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddIndexOnProjectIdToCiPipelines < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_ci_pipelines_on_project_id_and_id_desc' - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_pipelines, [:project_id, :id], name: INDEX_NAME, order: { id: :desc } - end - - def down - remove_concurrent_index :ci_pipelines, [:project_id, :id], name: INDEX_NAME, order: { id: :desc } - end -end diff --git a/db/post_migrate/20210906130643_drop_temporary_columns_and_triggers_for_taggings.rb b/db/post_migrate/20210906130643_drop_temporary_columns_and_triggers_for_taggings.rb new file mode 100644 index 00000000000..cb5714055bb --- /dev/null +++ b/db/post_migrate/20210906130643_drop_temporary_columns_and_triggers_for_taggings.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropTemporaryColumnsAndTriggersForTaggings < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + TABLE = 'taggings' + COLUMNS = %w(id taggable_id) + + # rubocop:disable Migration/WithLockRetriesDisallowedMethod + def up + cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + # rubocop:enable Migration/WithLockRetriesDisallowedMethod + + def down + restore_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20210907013944_cleanup_bigint_conversion_for_ci_builds_metadata.rb b/db/post_migrate/20210907013944_cleanup_bigint_conversion_for_ci_builds_metadata.rb new file mode 100644 index 00000000000..54dce0a7da8 --- /dev/null +++ b/db/post_migrate/20210907013944_cleanup_bigint_conversion_for_ci_builds_metadata.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class CleanupBigintConversionForCiBuildsMetadata < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + TABLE = :ci_builds_metadata + + def up + cleanup_conversion_of_integer_to_bigint(TABLE, :id) + cleanup_conversion_of_integer_to_bigint(TABLE, :build_id) + end + + def down + restore_conversion_of_integer_to_bigint(TABLE, :build_id) + restore_conversion_of_integer_to_bigint(TABLE, :id) + end +end diff --git a/db/post_migrate/20210910194952_update_report_type_for_existing_approval_project_rules.rb b/db/post_migrate/20210910194952_update_report_type_for_existing_approval_project_rules.rb new file mode 100644 index 00000000000..537c235edab --- /dev/null +++ b/db/post_migrate/20210910194952_update_report_type_for_existing_approval_project_rules.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class UpdateReportTypeForExistingApprovalProjectRules < Gitlab::Database::Migration[1.0] + def up + # 1. We only want to consider when rule_type is set to :report_approver (i.e., 2): + # enum rule_type: { + # regular: 0, + # code_owner: 1, # currently unused + # report_approver: 2, + # any_approver: 3 + # } + # 2. Also we want to change only the folowing names and respective values: + # DEFAULT_NAME_FOR_LICENSE_REPORT = 'License-Check' + # DEFAULT_NAME_FOR_VULNERABILITY_REPORT = 'Vulnerability-Check' + # DEFAULT_NAME_FOR_COVERAGE = 'Coverage-Check' + # enum report_type: { + # vulnerability: 1, + # license_scanning: 2, + # code_coverage: 3 + # } + + execute <<~SQL + UPDATE approval_project_rules + SET report_type = converted_values.report_type + FROM + ( values + (1, 'Vulnerability-Check'), + (2, 'License-Check'), + (3, 'Coverage-Check') + ) AS converted_values(report_type, name) + WHERE approval_project_rules.name = converted_values.name + AND approval_project_rules.rule_type = 2; + SQL + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20210915022415_cleanup_bigint_conversion_for_ci_builds.rb b/db/post_migrate/20210915022415_cleanup_bigint_conversion_for_ci_builds.rb new file mode 100644 index 00000000000..d72866691ff --- /dev/null +++ b/db/post_migrate/20210915022415_cleanup_bigint_conversion_for_ci_builds.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class CleanupBigintConversionForCiBuilds < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + TABLE = :ci_builds + COLUMNS = [:id, :stage_id] + + def up + cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + restore_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb b/db/post_migrate/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb new file mode 100644 index 00000000000..224d97243c5 --- /dev/null +++ b/db/post_migrate/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveOldPendingJobsForRecalculateVulnerabilitiesOccurrencesUuid < Gitlab::Database::Migration[1.0] + MIGRATION_NAME = 'RecalculateVulnerabilitiesOccurrencesUuid' + NEW_MIGRATION_START_DATE = DateTime.new(2021, 8, 18, 0, 0, 0) + + def up + Gitlab::Database::BackgroundMigrationJob + .for_migration_class(MIGRATION_NAME) + .where('created_at < ?', NEW_MIGRATION_START_DATE) + .where(status: :pending) + .delete_all + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb b/db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb new file mode 100644 index 00000000000..88351b3007a --- /dev/null +++ b/db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class ReschedulePendingJobsForRecalculateVulnerabilitiesOccurrencesUuid < Gitlab::Database::Migration[1.0] + MIGRATION = "RecalculateVulnerabilitiesOccurrencesUuid" + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + def up + delete_queued_jobs(MIGRATION) + + requeue_background_migration_jobs_by_range_at_intervals(MIGRATION, DELAY_INTERVAL) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20210920232025_remove_ci_builds_foreign_key_from_terraform_state_versions.rb b/db/post_migrate/20210920232025_remove_ci_builds_foreign_key_from_terraform_state_versions.rb new file mode 100644 index 00000000000..7435a2c889b --- /dev/null +++ b/db/post_migrate/20210920232025_remove_ci_builds_foreign_key_from_terraform_state_versions.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveCiBuildsForeignKeyFromTerraformStateVersions < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:terraform_state_versions, :ci_builds) + end + end + + def down + add_concurrent_foreign_key(:terraform_state_versions, :ci_builds, column: :ci_build_id, on_delete: :nullify) + end +end diff --git a/db/post_migrate/20210921062820_add_image_location_index_to_vulnerability_occurrences.rb b/db/post_migrate/20210921062820_add_image_location_index_to_vulnerability_occurrences.rb new file mode 100644 index 00000000000..7a6543395ff --- /dev/null +++ b/db/post_migrate/20210921062820_add_image_location_index_to_vulnerability_occurrences.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddImageLocationIndexToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_vulnerability_occurrences_on_location_image' + + def up + add_concurrent_index :vulnerability_occurrences, "(location -> 'image')", + using: 'GIN', + where: 'report_type IN (2, 7)', + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME + end +end diff --git a/db/post_migrate/20210922021816_drop_int4_columns_for_ci_job_artifacts.rb b/db/post_migrate/20210922021816_drop_int4_columns_for_ci_job_artifacts.rb new file mode 100644 index 00000000000..e45d6ed34aa --- /dev/null +++ b/db/post_migrate/20210922021816_drop_int4_columns_for_ci_job_artifacts.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class DropInt4ColumnsForCiJobArtifacts < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + remove_column :ci_job_artifacts, :id_convert_to_bigint, :integer, null: false, default: 0 + remove_column :ci_job_artifacts, :job_id_convert_to_bigint, :integer, null: false, default: 0 + end +end diff --git a/db/post_migrate/20210922025631_drop_int4_column_for_ci_sources_pipelines.rb b/db/post_migrate/20210922025631_drop_int4_column_for_ci_sources_pipelines.rb new file mode 100644 index 00000000000..b25f1d88736 --- /dev/null +++ b/db/post_migrate/20210922025631_drop_int4_column_for_ci_sources_pipelines.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class DropInt4ColumnForCiSourcesPipelines < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + remove_column :ci_sources_pipelines, :source_job_id_convert_to_bigint, :integer + end +end diff --git a/db/post_migrate/20210922082019_drop_int4_column_for_events.rb b/db/post_migrate/20210922082019_drop_int4_column_for_events.rb new file mode 100644 index 00000000000..a34d54e11e3 --- /dev/null +++ b/db/post_migrate/20210922082019_drop_int4_column_for_events.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class DropInt4ColumnForEvents < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + remove_column :events, :id_convert_to_bigint, :integer, null: false, default: 0 + end +end diff --git a/db/post_migrate/20210922084115_concurrent_index_resource_group_status_commit_id_for_ci_builds.rb b/db/post_migrate/20210922084115_concurrent_index_resource_group_status_commit_id_for_ci_builds.rb new file mode 100644 index 00000000000..922a9b64b55 --- /dev/null +++ b/db/post_migrate/20210922084115_concurrent_index_resource_group_status_commit_id_for_ci_builds.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class ConcurrentIndexResourceGroupStatusCommitIdForCiBuilds < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_ci_builds_on_resource_group_and_status_and_commit_id' + + disable_ddl_transaction! + + # Indexes were pre-created on gitlab.com to avoid slowing down deployments + # See: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70279 + + # rubocop: disable Migration/PreventIndexCreation + def up + add_concurrent_index :ci_builds, [:resource_group_id, :status, :commit_id], + where: 'resource_group_id IS NOT NULL', + name: INDEX_NAME + end + # rubocop: enable Migration/PreventIndexCreation + + def down + remove_concurrent_index_by_name :ci_builds, INDEX_NAME + end +end diff --git a/db/post_migrate/20210922091402_drop_int4_column_for_push_event_payloads.rb b/db/post_migrate/20210922091402_drop_int4_column_for_push_event_payloads.rb new file mode 100644 index 00000000000..5e30ddacc98 --- /dev/null +++ b/db/post_migrate/20210922091402_drop_int4_column_for_push_event_payloads.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class DropInt4ColumnForPushEventPayloads < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + remove_column :push_event_payloads, :event_id_convert_to_bigint, :integer, null: false, default: 0 + end +end diff --git a/db/post_migrate/20210923133143_remove_redundant_taggings_index.rb b/db/post_migrate/20210923133143_remove_redundant_taggings_index.rb new file mode 100644 index 00000000000..a33885cc87b --- /dev/null +++ b/db/post_migrate/20210923133143_remove_redundant_taggings_index.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveRedundantTaggingsIndex < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = :index_taggings_on_taggable_id_and_taggable_type + + def up + remove_concurrent_index_by_name :taggings, INDEX_NAME + end + + def down + add_concurrent_index :taggings, [:taggable_id, :taggable_type], name: INDEX_NAME + end +end diff --git a/db/post_migrate/20210923135909_remove_delayed_project_removal_from_namespaces.rb b/db/post_migrate/20210923135909_remove_delayed_project_removal_from_namespaces.rb new file mode 100644 index 00000000000..531410a91d9 --- /dev/null +++ b/db/post_migrate/20210923135909_remove_delayed_project_removal_from_namespaces.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveDelayedProjectRemovalFromNamespaces < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_column :namespaces, :delayed_project_removal + end + end + + def down + with_lock_retries do + add_column :namespaces, :delayed_project_removal, :boolean, default: false, null: false, if_not_exists: true # rubocop:disable Migration/AddColumnsToWideTables + end + + add_concurrent_index :namespaces, :id, name: 'tmp_idx_on_namespaces_delayed_project_removal', where: 'delayed_project_removal = TRUE' + end +end diff --git a/db/post_migrate/20210927153807_update_issues_relative_position_indexes.rb b/db/post_migrate/20210927153807_update_issues_relative_position_indexes.rb new file mode 100644 index 00000000000..c7b0c7c6d14 --- /dev/null +++ b/db/post_migrate/20210927153807_update_issues_relative_position_indexes.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class UpdateIssuesRelativePositionIndexes < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + RELATIVE_POSITION_INDEX_NAME = 'idx_issues_on_project_id_and_rel_asc_and_id' + RELATIVE_POSITION_STATE_INDEX_NAME = 'idx_issues_on_project_id_and_rel_position_and_state_id_and_id' + + NEW_RELATIVE_POSITION_STATE_INDEX_NAME = 'idx_issues_on_project_id_and_rel_position_and_id_and_state_id' + + def up + add_concurrent_index :issues, [:project_id, :relative_position, :id, :state_id], name: NEW_RELATIVE_POSITION_STATE_INDEX_NAME + + remove_concurrent_index_by_name :issues, RELATIVE_POSITION_INDEX_NAME + remove_concurrent_index_by_name :issues, RELATIVE_POSITION_STATE_INDEX_NAME + end + + def down + add_concurrent_index :issues, [:project_id, :relative_position, :state_id, :id], order: { id: :desc }, name: RELATIVE_POSITION_STATE_INDEX_NAME + add_concurrent_index :issues, [:project_id, :relative_position, :id], name: RELATIVE_POSITION_INDEX_NAME + + remove_concurrent_index_by_name :issues, NEW_RELATIVE_POSITION_STATE_INDEX_NAME + end +end diff --git a/db/post_migrate/20211004110500_add_temporary_index_to_issue_metrics.rb b/db/post_migrate/20211004110500_add_temporary_index_to_issue_metrics.rb new file mode 100644 index 00000000000..cfc37c55121 --- /dev/null +++ b/db/post_migrate/20211004110500_add_temporary_index_to_issue_metrics.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTemporaryIndexToIssueMetrics < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_issue_metrics_first_mentioned_in_commit' + + def up + add_concurrent_index :issue_metrics, :issue_id, where: 'EXTRACT(YEAR FROM first_mentioned_in_commit_at) > 2019', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :issue_metrics, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20211004110927_schedule_fix_first_mentioned_in_commit_at_job.rb b/db/post_migrate/20211004110927_schedule_fix_first_mentioned_in_commit_at_job.rb new file mode 100644 index 00000000000..c7612db3aaf --- /dev/null +++ b/db/post_migrate/20211004110927_schedule_fix_first_mentioned_in_commit_at_job.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class ScheduleFixFirstMentionedInCommitAtJob < Gitlab::Database::Migration[1.0] + MIGRATION = 'FixFirstMentionedInCommitAt' + BATCH_SIZE = 10_000 + INTERVAL = 2.minutes.to_i + + disable_ddl_transaction! + + def up + scope = define_batchable_model('issue_metrics') + .where('EXTRACT(YEAR FROM first_mentioned_in_commit_at) > 2019') + + queue_background_migration_jobs_by_range_at_intervals( + scope, + MIGRATION, + INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true, + primary_column_name: :issue_id + ) + end + + def down + # noop + end +end diff --git a/db/post_migrate/20211004151202_remove_bio_html_from_user_details.rb b/db/post_migrate/20211004151202_remove_bio_html_from_user_details.rb new file mode 100644 index 00000000000..d82589efc90 --- /dev/null +++ b/db/post_migrate/20211004151202_remove_bio_html_from_user_details.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class RemoveBioHtmlFromUserDetails < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + remove_column :user_details, :bio_html, :text, null: true + remove_column :user_details, :cached_markdown_version, :integer, null: true + end +end diff --git a/db/post_migrate/20211005010101_rereschedule_delete_orphaned_deployments.rb b/db/post_migrate/20211005010101_rereschedule_delete_orphaned_deployments.rb new file mode 100644 index 00000000000..f49a0fe2f56 --- /dev/null +++ b/db/post_migrate/20211005010101_rereschedule_delete_orphaned_deployments.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class RerescheduleDeleteOrphanedDeployments < Gitlab::Database::Migration[1.0] + MIGRATION = 'DeleteOrphanedDeployments' + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + # This is the third time to schedule `DeleteOrphanedDeployments` migration. + # The first time failed by an inappropriate batch size and the second time failed by a retry bug. + # Since there is no issue in this migration itself, we can simply requeue the + # migration jobs **without** no-op-ing the previous migration. + # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/69051#note_669230405 for more information. + def up + delete_queued_jobs(MIGRATION) + + requeue_background_migration_jobs_by_range_at_intervals(MIGRATION, DELAY_INTERVAL) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211005083015_recreate_index_security_ci_builds_on_name_and_id_parser_features.rb b/db/post_migrate/20211005083015_recreate_index_security_ci_builds_on_name_and_id_parser_features.rb new file mode 100644 index 00000000000..9887752618d --- /dev/null +++ b/db/post_migrate/20211005083015_recreate_index_security_ci_builds_on_name_and_id_parser_features.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class RecreateIndexSecurityCiBuildsOnNameAndIdParserFeatures < Gitlab::Database::Migration[1.0] + TABLE = "ci_builds" + OLD_INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features" + NEW_INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features_broken" + COLUMNS = %i[name id] + 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" + + enable_lock_retries! + + def up + rename_index(TABLE, OLD_INDEX_NAME, NEW_INDEX_NAME) + prepare_async_index TABLE, COLUMNS, name: OLD_INDEX_NAME, where: CONSTRAINTS + end + + def down + unprepare_async_index TABLE, COLUMNS, name: OLD_INDEX_NAME + rename_index(TABLE, NEW_INDEX_NAME, OLD_INDEX_NAME) + end +end diff --git a/db/post_migrate/20211006060436_schedule_populate_topics_total_projects_count_cache.rb b/db/post_migrate/20211006060436_schedule_populate_topics_total_projects_count_cache.rb new file mode 100644 index 00000000000..b14a9ab88b9 --- /dev/null +++ b/db/post_migrate/20211006060436_schedule_populate_topics_total_projects_count_cache.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class SchedulePopulateTopicsTotalProjectsCountCache < Gitlab::Database::Migration[1.0] + MIGRATION = 'PopulateTopicsTotalProjectsCountCache' + BATCH_SIZE = 10_000 + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('topics'), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211006145004_finalize_indexes_for_ci_job_artifacts_expire_at_unlocked.rb b/db/post_migrate/20211006145004_finalize_indexes_for_ci_job_artifacts_expire_at_unlocked.rb new file mode 100644 index 00000000000..b046ab6ab03 --- /dev/null +++ b/db/post_migrate/20211006145004_finalize_indexes_for_ci_job_artifacts_expire_at_unlocked.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class FinalizeIndexesForCiJobArtifactsExpireAtUnlocked < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + TABLE_NAME = 'ci_job_artifacts' + INDEX_NAME = 'ci_job_artifacts_expire_at_unlocked_idx' + + def up + add_concurrent_index TABLE_NAME, [:expire_at], where: 'locked = 0', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end +end diff --git a/db/post_migrate/20211006174114_add_namespace_index_on_type_sync.rb b/db/post_migrate/20211006174114_add_namespace_index_on_type_sync.rb new file mode 100644 index 00000000000..0185e4cbc5e --- /dev/null +++ b/db/post_migrate/20211006174114_add_namespace_index_on_type_sync.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddNamespaceIndexOnTypeSync < Gitlab::Database::Migration[1.0] + FULL_INDEX_NAME = 'index_namespaces_on_type_and_id' + PARTIAL_INDEX_NAME = 'index_namespaces_on_type_and_id_partial' + + disable_ddl_transaction! + + def up + add_concurrent_index :namespaces, [:type, :id], name: FULL_INDEX_NAME + + remove_concurrent_index_by_name :namespaces, name: PARTIAL_INDEX_NAME + end + + def down + add_concurrent_index(:namespaces, [:type, :id], where: 'type IS NOT NULL', name: PARTIAL_INDEX_NAME) + + remove_concurrent_index_by_name :namespaces, name: FULL_INDEX_NAME + end +end diff --git a/db/post_migrate/20211007093340_remove_analytics_snapshots_segment_id_column.rb b/db/post_migrate/20211007093340_remove_analytics_snapshots_segment_id_column.rb new file mode 100644 index 00000000000..df0b8ef2a94 --- /dev/null +++ b/db/post_migrate/20211007093340_remove_analytics_snapshots_segment_id_column.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveAnalyticsSnapshotsSegmentIdColumn < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + remove_column :analytics_devops_adoption_snapshots, :segment_id + end + + def down + add_column :analytics_devops_adoption_snapshots, :segment_id, :bigint, after: :id + add_concurrent_foreign_key :analytics_devops_adoption_snapshots, :analytics_devops_adoption_segments, + column: :segment_id, name: 'fk_rails_25da9a92c0', on_delete: :cascade + add_concurrent_index :analytics_devops_adoption_snapshots, [:segment_id, :end_time], name: :index_on_snapshots_segment_id_end_time + add_concurrent_index :analytics_devops_adoption_snapshots, [:segment_id, :recorded_at], name: :index_on_snapshots_segment_id_recorded_at + end +end diff --git a/db/post_migrate/20211007155221_schedule_populate_status_column_of_security_scans.rb b/db/post_migrate/20211007155221_schedule_populate_status_column_of_security_scans.rb new file mode 100644 index 00000000000..03032dfbb0a --- /dev/null +++ b/db/post_migrate/20211007155221_schedule_populate_status_column_of_security_scans.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class SchedulePopulateStatusColumnOfSecurityScans < Gitlab::Database::Migration[1.0] + MIGRATION = 'PopulateStatusColumnOfSecurityScans' + BATCH_SIZE = 10_000 + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + def up + return unless Gitlab.ee? + + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('security_scans'), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211011152701_cleanup_delete_orphaned_deployments_background_migration.rb b/db/post_migrate/20211011152701_cleanup_delete_orphaned_deployments_background_migration.rb new file mode 100644 index 00000000000..82a0b1ac9c8 --- /dev/null +++ b/db/post_migrate/20211011152701_cleanup_delete_orphaned_deployments_background_migration.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CleanupDeleteOrphanedDeploymentsBackgroundMigration < Gitlab::Database::Migration[1.0] + MIGRATION = 'DeleteOrphanedDeployments' + + disable_ddl_transaction! + + def up + finalize_background_migration(MIGRATION) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20211012155931_remove_schedule_and_status_from_pending_alert_escalations.rb b/db/post_migrate/20211012155931_remove_schedule_and_status_from_pending_alert_escalations.rb new file mode 100644 index 00000000000..e895ab6b9a0 --- /dev/null +++ b/db/post_migrate/20211012155931_remove_schedule_and_status_from_pending_alert_escalations.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class RemoveScheduleAndStatusFromPendingAlertEscalations < Gitlab::Database::Migration[1.0] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + ESCALATIONS_TABLE = :incident_management_pending_alert_escalations + SCHEDULES_TABLE = :incident_management_oncall_schedules + INDEX_NAME = 'index_incident_management_pending_alert_escalations_on_schedule' + CONSTRAINT_NAME = 'fk_rails_fcbfd9338b' + + def up + with_lock_retries do + remove_column ESCALATIONS_TABLE, :schedule_id + remove_column ESCALATIONS_TABLE, :status + end + end + + def down + with_lock_retries do + add_column ESCALATIONS_TABLE, :schedule_id, :bigint unless column_exists?(ESCALATIONS_TABLE, :schedule_id) + add_column ESCALATIONS_TABLE, :status, :smallint unless column_exists?(ESCALATIONS_TABLE, :status) + end + + add_concurrent_partitioned_index ESCALATIONS_TABLE, :schedule_id, name: INDEX_NAME + add_concurrent_partitioned_foreign_key ESCALATIONS_TABLE, SCHEDULES_TABLE, column: :schedule_id, name: CONSTRAINT_NAME + end +end |