diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /db/post_migrate | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'db/post_migrate')
79 files changed, 622 insertions, 1675 deletions
diff --git a/db/post_migrate/20180104131052_schedule_set_confidential_note_events_on_webhooks.rb b/db/post_migrate/20180104131052_schedule_set_confidential_note_events_on_webhooks.rb deleted file mode 100644 index 0822aebc2c6..00000000000 --- a/db/post_migrate/20180104131052_schedule_set_confidential_note_events_on_webhooks.rb +++ /dev/null @@ -1,23 +0,0 @@ -class ScheduleSetConfidentialNoteEventsOnWebhooks < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - INTERVAL = 5.minutes - - disable_ddl_transaction! - - def up - migration = Gitlab::BackgroundMigration::SetConfidentialNoteEventsOnWebhooks - migration_name = migration.to_s.demodulize - relation = migration::WebHook.hooks_to_update - - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - end -end diff --git a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb deleted file mode 100644 index 66ad0a89539..00000000000 --- a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb +++ /dev/null @@ -1,58 +0,0 @@ -class RemoveRedundantPipelineStages < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up(attempts: 100) - remove_redundant_pipeline_stages! - remove_outdated_index! - add_unique_index! - rescue ActiveRecord::RecordNotUnique - retry if (attempts -= 1) > 0 - - raise StandardError, <<~EOS - Failed to add an unique index to ci_stages, despite retrying the - migration 100 times. - - See https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/16580. - EOS - end - - def down - remove_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true - add_concurrent_index :ci_stages, [:pipeline_id, :name] - end - - private - - def remove_outdated_index! - return unless index_exists?(:ci_stages, [:pipeline_id, :name]) - - remove_concurrent_index :ci_stages, [:pipeline_id, :name] - end - - def add_unique_index! - add_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true - end - - def remove_redundant_pipeline_stages! - disable_statement_timeout do - redundant_stages_ids = <<~SQL - SELECT id FROM ci_stages WHERE (pipeline_id, name) IN ( - SELECT pipeline_id, name FROM ci_stages - GROUP BY pipeline_id, name HAVING COUNT(*) > 1 - ) - SQL - - execute <<~SQL - UPDATE ci_builds SET stage_id = NULL WHERE stage_id IN (#{redundant_stages_ids}) - SQL - - execute <<~SQL - DELETE FROM ci_stages WHERE id IN (#{redundant_stages_ids}) - SQL - end - end -end diff --git a/db/post_migrate/20180122154930_schedule_set_confidential_note_events_on_services.rb b/db/post_migrate/20180122154930_schedule_set_confidential_note_events_on_services.rb deleted file mode 100644 index 98bbb34dda1..00000000000 --- a/db/post_migrate/20180122154930_schedule_set_confidential_note_events_on_services.rb +++ /dev/null @@ -1,23 +0,0 @@ -class ScheduleSetConfidentialNoteEventsOnServices < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - INTERVAL = 20.minutes - - disable_ddl_transaction! - - def up - migration = Gitlab::BackgroundMigration::SetConfidentialNoteEventsOnServices - migration_name = migration.to_s.demodulize - relation = migration::Service.services_to_update - - queue_background_migration_jobs_by_range_at_intervals(relation, - migration_name, - INTERVAL, - batch_size: BATCH_SIZE) - end - - def down - end -end diff --git a/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb b/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb deleted file mode 100644 index 54b8a91fa47..00000000000 --- a/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb +++ /dev/null @@ -1,26 +0,0 @@ -class ChangeAuthorIdToNotNullInTodos < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - class Todo < ActiveRecord::Base - self.table_name = 'todos' - include EachBatch - end - - BATCH_SIZE = 1000 - - DOWNTIME = false - - disable_ddl_transaction! - - def up - Todo.where(author_id: nil).each_batch(of: BATCH_SIZE) do |batch| - batch.delete_all - end - - change_column_null :todos, :author_id, false - end - - def down - change_column_null :todos, :author_id, true - end -end diff --git a/db/post_migrate/20180212101828_add_tmp_partial_null_index_to_builds.rb b/db/post_migrate/20180212101828_add_tmp_partial_null_index_to_builds.rb deleted file mode 100644 index f8badcac990..00000000000 --- a/db/post_migrate/20180212101828_add_tmp_partial_null_index_to_builds.rb +++ /dev/null @@ -1,14 +0,0 @@ -class AddTmpPartialNullIndexToBuilds < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - add_concurrent_index(:ci_builds, :id, where: 'stage_id IS NULL', - name: 'tmp_id_partial_null_index') - end - - def down - remove_concurrent_index_by_name(:ci_builds, 'tmp_id_partial_null_index') - end -end diff --git a/db/post_migrate/20180212101928_schedule_build_stage_migration.rb b/db/post_migrate/20180212101928_schedule_build_stage_migration.rb deleted file mode 100644 index 2445ab1a130..00000000000 --- a/db/post_migrate/20180212101928_schedule_build_stage_migration.rb +++ /dev/null @@ -1,14 +0,0 @@ -class ScheduleBuildStageMigration < ActiveRecord::Migration[4.2] - ## - # This migration has been rescheduled to run again, see - # `20180405101928_reschedule_builds_stages_migration.rb` - # - - def up - # noop - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180212102028_remove_tmp_partial_null_index_from_builds.rb b/db/post_migrate/20180212102028_remove_tmp_partial_null_index_from_builds.rb deleted file mode 100644 index 2444df881b8..00000000000 --- a/db/post_migrate/20180212102028_remove_tmp_partial_null_index_from_builds.rb +++ /dev/null @@ -1,14 +0,0 @@ -class RemoveTmpPartialNullIndexFromBuilds < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - remove_concurrent_index_by_name(:ci_builds, 'tmp_id_partial_null_index') - end - - def down - add_concurrent_index(:ci_builds, :id, where: 'stage_id IS NULL', - name: 'tmp_id_partial_null_index') - end -end diff --git a/db/post_migrate/20180216121020_fill_pages_domain_verification_code.rb b/db/post_migrate/20180216121020_fill_pages_domain_verification_code.rb deleted file mode 100644 index dae43ee14df..00000000000 --- a/db/post_migrate/20180216121020_fill_pages_domain_verification_code.rb +++ /dev/null @@ -1,41 +0,0 @@ -class FillPagesDomainVerificationCode < ActiveRecord::Migration[4.2] - DOWNTIME = false - - class PagesDomain < ActiveRecord::Base - include EachBatch - end - - # Allow this migration to resume if it fails partway through - disable_ddl_transaction! - - def up - PagesDomain.where(verification_code: [nil, '']).each_batch do |relation| - connection.execute(set_codes_sql(relation)) - - # Sleep 2 minutes between batches to not overload the DB with dead tuples - sleep(2.minutes) unless relation.reorder(:id).last == PagesDomain.reorder(:id).last - end - - change_column_null(:pages_domains, :verification_code, false) - end - - def down - change_column_null(:pages_domains, :verification_code, true) - end - - private - - def set_codes_sql(relation) - ids = relation.pluck(:id) - whens = ids.map { |id| "WHEN #{id} THEN '#{SecureRandom.hex(16)}'" } - - <<~SQL - UPDATE pages_domains - SET verification_code = - CASE id - #{whens.join("\n")} - END - WHERE id IN(#{ids.join(',')}) - SQL - end -end diff --git a/db/post_migrate/20180216121030_enqueue_verify_pages_domain_workers.rb b/db/post_migrate/20180216121030_enqueue_verify_pages_domain_workers.rb deleted file mode 100644 index d776fb85f00..00000000000 --- a/db/post_migrate/20180216121030_enqueue_verify_pages_domain_workers.rb +++ /dev/null @@ -1,16 +0,0 @@ -class EnqueueVerifyPagesDomainWorkers < ActiveRecord::Migration[4.2] - class PagesDomain < ActiveRecord::Base - include EachBatch - end - - def up - PagesDomain.each_batch do |relation| - ids = relation.pluck(:id).map { |id| [id] } - PagesDomainVerificationWorker.bulk_perform_async(ids) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20180220150310_remove_empty_extern_uid_auth0_identities.rb b/db/post_migrate/20180220150310_remove_empty_extern_uid_auth0_identities.rb deleted file mode 100644 index 86ef333685e..00000000000 --- a/db/post_migrate/20180220150310_remove_empty_extern_uid_auth0_identities.rb +++ /dev/null @@ -1,25 +0,0 @@ -class RemoveEmptyExternUidAuth0Identities < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Identity < ActiveRecord::Base - self.table_name = 'identities' - include EachBatch - end - - def up - broken_auth0_identities.each_batch do |identity| - identity.delete_all - end - end - - def broken_auth0_identities - Identity.where(provider: 'auth0', extern_uid: [nil, '']) - end - - def down - end -end diff --git a/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb b/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb deleted file mode 100644 index 1eb49d60da5..00000000000 --- a/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb +++ /dev/null @@ -1,139 +0,0 @@ -require_relative '../migrate/20180223120443_create_user_interacted_projects_table.rb' -# rubocop:disable AddIndex -# rubocop:disable AddConcurrentForeignKey -class BuildUserInteractedProjectsTable < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - UNIQUE_INDEX_NAME = 'index_user_interacted_projects_on_project_id_and_user_id' - - disable_ddl_transaction! - - def up - PostgresStrategy.new.up - - if index_exists_by_name?(:user_interacted_projects, CreateUserInteractedProjectsTable::INDEX_NAME) - remove_concurrent_index_by_name :user_interacted_projects, CreateUserInteractedProjectsTable::INDEX_NAME - end - end - - def down - execute "TRUNCATE user_interacted_projects" - - if foreign_key_exists?(:user_interacted_projects, :users) - remove_foreign_key :user_interacted_projects, :users - end - - if foreign_key_exists?(:user_interacted_projects, :projects) - remove_foreign_key :user_interacted_projects, :projects - end - - if index_exists_by_name?(:user_interacted_projects, UNIQUE_INDEX_NAME) - remove_concurrent_index_by_name :user_interacted_projects, UNIQUE_INDEX_NAME - end - - unless index_exists_by_name?(:user_interacted_projects, CreateUserInteractedProjectsTable::INDEX_NAME) - add_concurrent_index :user_interacted_projects, [:project_id, :user_id], name: CreateUserInteractedProjectsTable::INDEX_NAME - end - end - - class PostgresStrategy < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - BATCH_SIZE = 100_000 - SLEEP_TIME = 5 - - def up - with_index(:events, [:author_id, :project_id], name: 'events_user_interactions_temp', where: 'project_id IS NOT NULL') do - insert_missing_records - - # Do this once without lock to speed up the second invocation - remove_duplicates - with_table_lock(:user_interacted_projects) do - remove_duplicates - create_unique_index - end - - remove_without_project - with_table_lock(:user_interacted_projects, :projects) do - remove_without_project - create_fk :user_interacted_projects, :projects, :project_id - end - - remove_without_user - with_table_lock(:user_interacted_projects, :users) do - remove_without_user - create_fk :user_interacted_projects, :users, :user_id - end - end - - execute "ANALYZE user_interacted_projects" - end - - private - - def insert_missing_records - iteration = 0 - records = 0 - begin - Rails.logger.info "Building user_interacted_projects table, batch ##{iteration}" # rubocop:disable Gitlab/RailsLogger - result = execute <<~SQL - INSERT INTO user_interacted_projects (user_id, project_id) - SELECT e.user_id, e.project_id - FROM (SELECT DISTINCT author_id AS user_id, project_id FROM events WHERE project_id IS NOT NULL) AS e - LEFT JOIN user_interacted_projects ucp USING (user_id, project_id) - WHERE ucp.user_id IS NULL - LIMIT #{BATCH_SIZE} - SQL - iteration += 1 - records += result.cmd_tuples - Rails.logger.info "Building user_interacted_projects table, batch ##{iteration} complete, created #{records} overall" # rubocop:disable Gitlab/RailsLogger - Kernel.sleep(SLEEP_TIME) if result.cmd_tuples > 0 - end while result.cmd_tuples > 0 - end - - def remove_duplicates - execute <<~SQL - WITH numbered AS (select ctid, ROW_NUMBER() OVER (PARTITION BY (user_id, project_id)) as row_number, user_id, project_id from user_interacted_projects) - DELETE FROM user_interacted_projects WHERE ctid IN (SELECT ctid FROM numbered WHERE row_number > 1); - SQL - end - - def remove_without_project - execute "DELETE FROM user_interacted_projects WHERE NOT EXISTS (SELECT 1 FROM projects WHERE id = user_interacted_projects.project_id)" - end - - def remove_without_user - execute "DELETE FROM user_interacted_projects WHERE NOT EXISTS (SELECT 1 FROM users WHERE id = user_interacted_projects.user_id)" - end - - def create_fk(table, target, column) - return if foreign_key_exists?(table, target, column: column) - - add_foreign_key table, target, column: column, on_delete: :cascade - end - - def create_unique_index - return if index_exists_by_name?(:user_interacted_projects, UNIQUE_INDEX_NAME) - - add_index :user_interacted_projects, [:project_id, :user_id], unique: true, name: UNIQUE_INDEX_NAME - end - - # Protect table against concurrent data changes while still allowing reads - def with_table_lock(*tables) - ActiveRecord::Base.connection.transaction do - execute "LOCK TABLE #{tables.join(", ")} IN SHARE MODE" - yield - end - end - - def with_index(*args) - add_concurrent_index(*args) unless index_exists?(*args) - yield - ensure - remove_concurrent_index(*args) if index_exists?(*args) - end - end -end diff --git a/db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb b/db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb deleted file mode 100644 index 62a239b0e7c..00000000000 --- a/db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb +++ /dev/null @@ -1,29 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class ChangeProjectNamespaceIdNotNull < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - class Project < ActiveRecord::Base - self.table_name = 'projects' - include EachBatch - end - - BATCH_SIZE = 1000 - - DOWNTIME = false - - disable_ddl_transaction! - - def up - Project.where(namespace_id: nil).each_batch(of: BATCH_SIZE) do |batch| - batch.delete_all - end - - change_column_null :projects, :namespace_id, false - end - - def down - change_column_null :projects, :namespace_id, true - end -end diff --git a/db/post_migrate/20180305100050_remove_permanent_from_redirect_routes.rb b/db/post_migrate/20180305100050_remove_permanent_from_redirect_routes.rb deleted file mode 100644 index e363642b2ac..00000000000 --- a/db/post_migrate/20180305100050_remove_permanent_from_redirect_routes.rb +++ /dev/null @@ -1,33 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemovePermanentFromRedirectRoutes < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - INDEX_NAME_PERM = "index_redirect_routes_on_path_text_pattern_ops_where_permanent" - INDEX_NAME_TEMP = "index_redirect_routes_on_path_text_pattern_ops_where_temporary" - - def up - # These indexes were created on Postgres only in: - # ReworkRedirectRoutesIndexes: - # https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/16211 - disable_statement_timeout do - execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_PERM};" - execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_TEMP};" - end - - remove_column(:redirect_routes, :permanent) - end - - def down - add_column(:redirect_routes, :permanent, :boolean) - - disable_statement_timeout do - execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_PERM} ON redirect_routes (lower(path) varchar_pattern_ops) where (permanent);") - execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_TEMP} ON redirect_routes (lower(path) varchar_pattern_ops) where (not permanent or permanent is null) ;") - end - end -end diff --git a/db/post_migrate/20180306074045_migrate_create_trace_artifact_sidekiq_queue.rb b/db/post_migrate/20180306074045_migrate_create_trace_artifact_sidekiq_queue.rb deleted file mode 100644 index fc74f6f1712..00000000000 --- a/db/post_migrate/20180306074045_migrate_create_trace_artifact_sidekiq_queue.rb +++ /dev/null @@ -1,13 +0,0 @@ -class MigrateCreateTraceArtifactSidekiqQueue < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'pipeline_default:create_trace_artifact', to: 'pipeline_background:archive_trace' - end - - def down - sidekiq_queue_migrate 'pipeline_background:archive_trace', to: 'pipeline_default:create_trace_artifact' - end -end diff --git a/db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb b/db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb deleted file mode 100644 index f0257e303f7..00000000000 --- a/db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb +++ /dev/null @@ -1,31 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class AddPathIndexToRedirectRoutes < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - disable_ddl_transaction! - - INDEX_NAME = 'index_redirect_routes_on_path_unique_text_pattern_ops' - - # Indexing on LOWER(path) varchar_pattern_ops speeds up the LIKE query in - # RedirectRoute.matching_path_and_descendants - # - # This same index is also added in the `ReworkRedirectRoutesIndexes` so this - # is a no-op in most cases. - def up - disable_statement_timeout do - unless index_exists_by_name?(:redirect_routes, INDEX_NAME) - execute("CREATE UNIQUE INDEX CONCURRENTLY #{INDEX_NAME} ON redirect_routes (lower(path) varchar_pattern_ops);") - end - end - end - - def down - # Do nothing in the DOWN. Since the index above is originally created in the - # `ReworkRedirectRoutesIndexes`. This migration wouldn't have actually - # created any new index. - end -end diff --git a/db/post_migrate/20180307012445_migrate_update_head_pipeline_for_merge_request_sidekiq_queue.rb b/db/post_migrate/20180307012445_migrate_update_head_pipeline_for_merge_request_sidekiq_queue.rb deleted file mode 100644 index 372c04429c7..00000000000 --- a/db/post_migrate/20180307012445_migrate_update_head_pipeline_for_merge_request_sidekiq_queue.rb +++ /dev/null @@ -1,15 +0,0 @@ -class MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'pipeline_default:update_head_pipeline_for_merge_request', - to: 'pipeline_processing:update_head_pipeline_for_merge_request' - end - - def down - sidekiq_queue_migrate 'pipeline_processing:update_head_pipeline_for_merge_request', - to: 'pipeline_default:update_head_pipeline_for_merge_request' - end -end diff --git a/db/post_migrate/20180405101928_reschedule_builds_stages_migration.rb b/db/post_migrate/20180405101928_reschedule_builds_stages_migration.rb deleted file mode 100644 index 213d97b71f7..00000000000 --- a/db/post_migrate/20180405101928_reschedule_builds_stages_migration.rb +++ /dev/null @@ -1,33 +0,0 @@ -class RescheduleBuildsStagesMigration < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - ## - # Rescheduled `20180212101928_schedule_build_stage_migration.rb` - # - - DOWNTIME = false - MIGRATION = 'MigrateBuildStage'.freeze - BATCH_SIZE = 500 - - disable_ddl_transaction! - - class Build < ActiveRecord::Base - include EachBatch - self.table_name = 'ci_builds' - end - - def up - disable_statement_timeout do - Build.where('stage_id IS NULL').tap do |relation| - queue_background_migration_jobs_by_range_at_intervals(relation, - MIGRATION, - 5.minutes, - batch_size: BATCH_SIZE) - end - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180408143355_cleanup_users_rss_token_rename.rb b/db/post_migrate/20180408143355_cleanup_users_rss_token_rename.rb deleted file mode 100644 index 813603cb3ad..00000000000 --- a/db/post_migrate/20180408143355_cleanup_users_rss_token_rename.rb +++ /dev/null @@ -1,14 +0,0 @@ -class CleanupUsersRssTokenRename < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :users, :rss_token, :feed_token - end - - def down - # rubocop:disable Migration/UpdateLargeTable - rename_column_concurrently :users, :feed_token, :rss_token - end -end diff --git a/db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb b/db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb deleted file mode 100644 index a400a071e07..00000000000 --- a/db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb +++ /dev/null @@ -1,30 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class PopulateMissingProjectCiCdSettings < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # Projects created after the initial migration but before the code started - # using ProjectCiCdSetting won't have a corresponding row in - # project_ci_cd_settings, so let's fix that. - execute <<~SQL - INSERT INTO project_ci_cd_settings (project_id) - SELECT id - FROM projects - WHERE NOT EXISTS ( - SELECT 1 - FROM project_ci_cd_settings - WHERE project_ci_cd_settings.project_id = projects.id - ) - SQL - end - - def down - # There's nothing to revert for this migration. - end -end diff --git a/db/post_migrate/20180420080616_schedule_stages_index_migration.rb b/db/post_migrate/20180420080616_schedule_stages_index_migration.rb deleted file mode 100644 index 2d72e75393f..00000000000 --- a/db/post_migrate/20180420080616_schedule_stages_index_migration.rb +++ /dev/null @@ -1,29 +0,0 @@ -class ScheduleStagesIndexMigration < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'MigrateStageIndex'.freeze - BATCH_SIZE = 10000 - - disable_ddl_transaction! - - class Stage < ActiveRecord::Base - include EachBatch - self.table_name = 'ci_stages' - end - - def up - disable_statement_timeout do - Stage.all.tap do |relation| - queue_background_migration_jobs_by_range_at_intervals(relation, - MIGRATION, - 5.minutes, - batch_size: BATCH_SIZE) - end - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180424151928_fill_file_store.rb b/db/post_migrate/20180424151928_fill_file_store.rb deleted file mode 100644 index 45fa10c9550..00000000000 --- a/db/post_migrate/20180424151928_fill_file_store.rb +++ /dev/null @@ -1,72 +0,0 @@ -class FillFileStore < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class JobArtifact < ActiveRecord::Base - include EachBatch - self.table_name = 'ci_job_artifacts' - BATCH_SIZE = 10_000 - - def self.params_for_background_migration - yield self.where(file_store: nil), 'FillFileStoreJobArtifact', 5.minutes, BATCH_SIZE - end - end - - class LfsObject < ActiveRecord::Base - include EachBatch - self.table_name = 'lfs_objects' - BATCH_SIZE = 10_000 - - def self.params_for_background_migration - yield self.where(file_store: nil), 'FillFileStoreLfsObject', 5.minutes, BATCH_SIZE - end - end - - class Upload < ActiveRecord::Base - include EachBatch - self.table_name = 'uploads' - self.inheritance_column = :_type_disabled # Disable STI - BATCH_SIZE = 10_000 - - def self.params_for_background_migration - yield self.where(store: nil), 'FillStoreUpload', 5.minutes, BATCH_SIZE - end - end - - def up - # NOTE: Schedule background migrations that fill 'NULL' value by '1'(ObjectStorage::Store::LOCAL) on `file_store`, `store` columns - # - # Here are the target columns - # - ci_job_artifacts.file_store - # - lfs_objects.file_store - # - uploads.store - - FillFileStore::JobArtifact.params_for_background_migration do |relation, class_name, delay_interval, batch_size| - queue_background_migration_jobs_by_range_at_intervals(relation, - class_name, - delay_interval, - batch_size: batch_size) - end - - FillFileStore::LfsObject.params_for_background_migration do |relation, class_name, delay_interval, batch_size| - queue_background_migration_jobs_by_range_at_intervals(relation, - class_name, - delay_interval, - batch_size: batch_size) - end - - FillFileStore::Upload.params_for_background_migration do |relation, class_name, delay_interval, batch_size| - queue_background_migration_jobs_by_range_at_intervals(relation, - class_name, - delay_interval, - batch_size: batch_size) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180430143705_backfill_runner_type_for_ci_runners_post_migrate.rb b/db/post_migrate/20180430143705_backfill_runner_type_for_ci_runners_post_migrate.rb deleted file mode 100644 index ba1023866c5..00000000000 --- a/db/post_migrate/20180430143705_backfill_runner_type_for_ci_runners_post_migrate.rb +++ /dev/null @@ -1,24 +0,0 @@ -class BackfillRunnerTypeForCiRunnersPostMigrate < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - INSTANCE_RUNNER_TYPE = 1 - PROJECT_RUNNER_TYPE = 3 - - disable_ddl_transaction! - - def up - # rubocop:disable Migration/UpdateColumnInBatches - update_column_in_batches(:ci_runners, :runner_type, INSTANCE_RUNNER_TYPE) do |table, query| - query.where(table[:is_shared].eq(true)).where(table[:runner_type].eq(nil)) - end - - update_column_in_batches(:ci_runners, :runner_type, PROJECT_RUNNER_TYPE) do |table, query| - query.where(table[:is_shared].eq(false)).where(table[:runner_type].eq(nil)) - end - end - - def down - end -end diff --git a/db/post_migrate/20180507083701_set_minimal_project_build_timeout.rb b/db/post_migrate/20180507083701_set_minimal_project_build_timeout.rb deleted file mode 100644 index 34edbb08bcf..00000000000 --- a/db/post_migrate/20180507083701_set_minimal_project_build_timeout.rb +++ /dev/null @@ -1,21 +0,0 @@ -class SetMinimalProjectBuildTimeout < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MINIMUM_TIMEOUT = 600 - - # Allow this migration to resume if it fails partway through - disable_ddl_transaction! - - def up - # rubocop:disable Migration/UpdateLargeTable - # rubocop:disable Migration/UpdateColumnInBatches - update_column_in_batches(:projects, :build_timeout, MINIMUM_TIMEOUT) do |table, query| - query.where(table[:build_timeout].lt(MINIMUM_TIMEOUT)) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb b/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb deleted file mode 100644 index a526001a91e..00000000000 --- a/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb +++ /dev/null @@ -1,43 +0,0 @@ -class AddUniqueConstraintToProjectFeaturesProjectId < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class ProjectFeature < ActiveRecord::Base - self.table_name = 'project_features' - - include EachBatch - end - - def up - remove_duplicates - - add_concurrent_index :project_features, :project_id, unique: true, name: 'index_project_features_on_project_id_unique' - remove_concurrent_index_by_name :project_features, 'index_project_features_on_project_id' - rename_index :project_features, 'index_project_features_on_project_id_unique', 'index_project_features_on_project_id' - end - - def down - rename_index :project_features, 'index_project_features_on_project_id', 'index_project_features_on_project_id_old' - add_concurrent_index :project_features, :project_id - remove_concurrent_index_by_name :project_features, 'index_project_features_on_project_id_old' - end - - private - - def remove_duplicates - features = ProjectFeature - .select('MAX(id) AS max, COUNT(id), project_id') - .group(:project_id) - .having('COUNT(id) > 1') - - features.each do |feature| - ProjectFeature - .where(project_id: feature['project_id']) - .where('id <> ?', feature['max']) - .each_batch { |batch| batch.delete_all } - end - end -end diff --git a/db/post_migrate/20180512061621_add_not_null_constraint_to_project_features_project_id.rb b/db/post_migrate/20180512061621_add_not_null_constraint_to_project_features_project_id.rb deleted file mode 100644 index e3abbc039e8..00000000000 --- a/db/post_migrate/20180512061621_add_not_null_constraint_to_project_features_project_id.rb +++ /dev/null @@ -1,21 +0,0 @@ -class AddNotNullConstraintToProjectFeaturesProjectId < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - class ProjectFeature < ActiveRecord::Base - include EachBatch - - self.table_name = 'project_features' - end - - def up - ProjectFeature.where(project_id: nil).delete_all - - change_column_null :project_features, :project_id, false - end - - def down - change_column_null :project_features, :project_id, true - end -end diff --git a/db/post_migrate/20180514161336_remove_gemnasium_service.rb b/db/post_migrate/20180514161336_remove_gemnasium_service.rb deleted file mode 100644 index 5842bde474c..00000000000 --- a/db/post_migrate/20180514161336_remove_gemnasium_service.rb +++ /dev/null @@ -1,15 +0,0 @@ -class RemoveGemnasiumService < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - disable_statement_timeout - - execute("DELETE FROM services WHERE type='GemnasiumService';") - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180523125103_cleanup_merge_requests_allow_maintainer_to_push_rename.rb b/db/post_migrate/20180523125103_cleanup_merge_requests_allow_maintainer_to_push_rename.rb deleted file mode 100644 index b3b539fd156..00000000000 --- a/db/post_migrate/20180523125103_cleanup_merge_requests_allow_maintainer_to_push_rename.rb +++ /dev/null @@ -1,18 +0,0 @@ -class CleanupMergeRequestsAllowMaintainerToPushRename < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # NOOP - end - - def down - if column_exists?(:merge_requests, :allow_collaboration) - # rubocop:disable Migration/UpdateLargeTable - rename_column_concurrently :merge_requests, :allow_collaboration, :allow_maintainer_to_push - end - end -end diff --git a/db/post_migrate/20180529152628_schedule_to_archive_legacy_traces.rb b/db/post_migrate/20180529152628_schedule_to_archive_legacy_traces.rb deleted file mode 100644 index 6246f6afab0..00000000000 --- a/db/post_migrate/20180529152628_schedule_to_archive_legacy_traces.rb +++ /dev/null @@ -1,35 +0,0 @@ -class ScheduleToArchiveLegacyTraces < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 5000 - BACKGROUND_MIGRATION_CLASS = 'ArchiveLegacyTraces' - - disable_ddl_transaction! - - class Build < ActiveRecord::Base - include EachBatch - self.table_name = 'ci_builds' - self.inheritance_column = :_type_disabled # Disable STI - - scope :type_build, -> { where(type: 'Ci::Build') } - - scope :finished, -> { where(status: [:success, :failed, :canceled]) } - - scope :without_archived_trace, -> do - where('NOT EXISTS (SELECT 1 FROM ci_job_artifacts WHERE ci_builds.id = ci_job_artifacts.job_id AND ci_job_artifacts.file_type = 3)') - end - end - - def up - queue_background_migration_jobs_by_range_at_intervals( - ::ScheduleToArchiveLegacyTraces::Build.type_build.finished.without_archived_trace, - BACKGROUND_MIGRATION_CLASS, - 5.minutes, - batch_size: BATCH_SIZE) - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180603190921_migrate_object_storage_upload_sidekiq_queue.rb b/db/post_migrate/20180603190921_migrate_object_storage_upload_sidekiq_queue.rb deleted file mode 100644 index bc7c3eb5385..00000000000 --- a/db/post_migrate/20180603190921_migrate_object_storage_upload_sidekiq_queue.rb +++ /dev/null @@ -1,16 +0,0 @@ -class MigrateObjectStorageUploadSidekiqQueue < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - sidekiq_queue_migrate 'object_storage_upload', to: 'object_storage:object_storage_background_move' - end - - def down - # do not migrate any jobs back because we would migrate also - # jobs which were not part of the 'object_storage_upload' - end -end diff --git a/db/post_migrate/20180604123514_cleanup_stages_position_migration.rb b/db/post_migrate/20180604123514_cleanup_stages_position_migration.rb deleted file mode 100644 index 326cdfa27c3..00000000000 --- a/db/post_migrate/20180604123514_cleanup_stages_position_migration.rb +++ /dev/null @@ -1,45 +0,0 @@ -class CleanupStagesPositionMigration < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - TMP_INDEX_NAME = 'tmp_id_stage_position_partial_null_index'.freeze - - disable_ddl_transaction! - - class Stages < ActiveRecord::Base - include EachBatch - self.table_name = 'ci_stages' - end - - def up - disable_statement_timeout do - Gitlab::BackgroundMigration.steal('MigrateStageIndex') - - unless index_exists_by_name?(:ci_stages, TMP_INDEX_NAME) - add_concurrent_index(:ci_stages, :id, where: 'position IS NULL', name: TMP_INDEX_NAME) - end - - migratable = <<~SQL - position IS NULL AND EXISTS ( - SELECT 1 FROM ci_builds WHERE stage_id = ci_stages.id AND stage_idx IS NOT NULL - ) - SQL - - Stages.where(migratable).each_batch(of: 1000) do |batch| - batch.pluck(:id).each do |stage| - Gitlab::BackgroundMigration::MigrateStageIndex.new.perform(stage, stage) - end - end - - remove_concurrent_index_by_name(:ci_stages, TMP_INDEX_NAME) - end - end - - def down - if index_exists_by_name?(:ci_stages, TMP_INDEX_NAME) - disable_statement_timeout do - remove_concurrent_index_by_name(:ci_stages, TMP_INDEX_NAME) - end - end - end -end diff --git a/db/post_migrate/20180608201435_cleanup_merge_requests_allow_collaboration_rename.rb b/db/post_migrate/20180608201435_cleanup_merge_requests_allow_collaboration_rename.rb deleted file mode 100644 index 5e892f8bace..00000000000 --- a/db/post_migrate/20180608201435_cleanup_merge_requests_allow_collaboration_rename.rb +++ /dev/null @@ -1,20 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanupMergeRequestsAllowCollaborationRename < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - if column_exists?(:merge_requests, :allow_collaboration) - cleanup_concurrent_column_rename :merge_requests, :allow_collaboration, :allow_maintainer_to_push - end - end - - def down - # NOOP - end -end diff --git a/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb b/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb deleted file mode 100644 index 15c02cd77b8..00000000000 --- a/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb +++ /dev/null @@ -1,18 +0,0 @@ -class AddPartialIndexToProjectsForLastRepositoryCheckAt < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - disable_ddl_transaction! - - INDEX_NAME = "index_projects_on_last_repository_check_at" - - def up - add_concurrent_index(:projects, :last_repository_check_at, where: "last_repository_check_at IS NOT NULL", name: INDEX_NAME) - end - - def down - remove_concurrent_index(:projects, :last_repository_check_at, where: "last_repository_check_at IS NOT NULL", name: INDEX_NAME) - end -end diff --git a/db/post_migrate/20180702120647_enqueue_fix_cross_project_label_links.rb b/db/post_migrate/20180702120647_enqueue_fix_cross_project_label_links.rb deleted file mode 100644 index 3d3d49e7564..00000000000 --- a/db/post_migrate/20180702120647_enqueue_fix_cross_project_label_links.rb +++ /dev/null @@ -1,30 +0,0 @@ -class EnqueueFixCrossProjectLabelLinks < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 100 - MIGRATION = 'FixCrossProjectLabelLinks' - DELAY_INTERVAL = 5.minutes - - disable_ddl_transaction! - - class Label < ActiveRecord::Base - self.table_name = 'labels' - end - - class Namespace < ActiveRecord::Base - self.table_name = 'namespaces' - - include ::EachBatch - - default_scope { where(type: 'Group', id: Label.where(type: 'GroupLabel').select('distinct group_id')) } - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Namespace, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180704145007_update_project_indexes.rb b/db/post_migrate/20180704145007_update_project_indexes.rb deleted file mode 100644 index 0a82f4535a0..00000000000 --- a/db/post_migrate/20180704145007_update_project_indexes.rb +++ /dev/null @@ -1,23 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class UpdateProjectIndexes < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - NEW_INDEX_NAME = 'idx_project_repository_check_partial' - - disable_ddl_transaction! - - def up - add_concurrent_index(:projects, - [:repository_storage, :created_at], - name: NEW_INDEX_NAME, - where: 'last_repository_check_at IS NULL' - ) - end - - def down - remove_concurrent_index_by_name(:projects, NEW_INDEX_NAME) - end -end diff --git a/db/post_migrate/20180706223200_populate_site_statistics.rb b/db/post_migrate/20180706223200_populate_site_statistics.rb deleted file mode 100644 index 6f887a0c18f..00000000000 --- a/db/post_migrate/20180706223200_populate_site_statistics.rb +++ /dev/null @@ -1,25 +0,0 @@ -class PopulateSiteStatistics < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - transaction do - execute('SET LOCAL statement_timeout TO 0') # see https://gitlab.com/gitlab-org/gitlab-foss/issues/48967 - - execute("UPDATE site_statistics SET repositories_count = (SELECT COUNT(*) FROM projects)") - end - - transaction do - execute('SET LOCAL statement_timeout TO 0') # see https://gitlab.com/gitlab-org/gitlab-foss/issues/48967 - - execute("UPDATE site_statistics SET wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)") - end - end - - def down - # No downside in keeping the counter up-to-date - end -end diff --git a/db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb b/db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb deleted file mode 100644 index b272bad7f92..00000000000 --- a/db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class MigrateNullWikiAccessLevels < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class ProjectFeature < ActiveRecord::Base - include EachBatch - - self.table_name = 'project_features' - end - - def up - ProjectFeature.where(wiki_access_level: nil).each_batch do |relation| - relation.update_all(wiki_access_level: 20) - end - - # We need to re-count wikis as previous attempt was not considering the NULLs. - transaction do - execute('SET LOCAL statement_timeout TO 0') # see https://gitlab.com/gitlab-org/gitlab-foss/issues/48967 - - execute("UPDATE site_statistics SET wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)") - end - end - - def down - # there is no way to rollback this change, there are no downsides in keeping migrated data. - end -end diff --git a/db/post_migrate/20180816161409_migrate_legacy_artifacts_to_job_artifacts.rb b/db/post_migrate/20180816161409_migrate_legacy_artifacts_to_job_artifacts.rb deleted file mode 100644 index 6b0d1ef0d0c..00000000000 --- a/db/post_migrate/20180816161409_migrate_legacy_artifacts_to_job_artifacts.rb +++ /dev/null @@ -1,32 +0,0 @@ -class MigrateLegacyArtifactsToJobArtifacts < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'MigrateLegacyArtifacts'.freeze - BATCH_SIZE = 100 - - disable_ddl_transaction! - - class Build < ActiveRecord::Base - include EachBatch - - self.table_name = 'ci_builds' - self.inheritance_column = :_type_disabled - - scope :with_legacy_artifacts, -> { where("artifacts_file <> ''") } - end - - def up - MigrateLegacyArtifactsToJobArtifacts::Build - .with_legacy_artifacts.tap do |relation| - queue_background_migration_jobs_by_range_at_intervals(relation, - MIGRATION, - 5.minutes, - batch_size: BATCH_SIZE) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20180816193530_rename_login_root_namespaces.rb b/db/post_migrate/20180816193530_rename_login_root_namespaces.rb deleted file mode 100644 index 70db8f46d05..00000000000 --- a/db/post_migrate/20180816193530_rename_login_root_namespaces.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true -class RenameLoginRootNamespaces < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - include Gitlab::Database::RenameReservedPathsMigration::V1 - - DOWNTIME = false - - disable_ddl_transaction! - - # We're taking over the /login namespace as part of a fix for the Jira integration - def up - disable_statement_timeout do - rename_root_paths 'login' - end - end - - def down - disable_statement_timeout do - revert_renames - end - end -end diff --git a/db/post_migrate/20180826111825_recalculate_site_statistics.rb b/db/post_migrate/20180826111825_recalculate_site_statistics.rb deleted file mode 100644 index 938707c9ba4..00000000000 --- a/db/post_migrate/20180826111825_recalculate_site_statistics.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class RecalculateSiteStatistics < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - transaction do - execute('SET LOCAL statement_timeout TO 0') # see https://gitlab.com/gitlab-org/gitlab-foss/issues/48967 - - execute("UPDATE site_statistics SET repositories_count = (SELECT COUNT(*) FROM projects)") - end - - transaction do - execute('SET LOCAL statement_timeout TO 0') # see https://gitlab.com/gitlab-org/gitlab-foss/issues/48967 - - execute("UPDATE site_statistics SET wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)") - end - end - - def down - # No downside in keeping the counter up-to-date - end -end diff --git a/db/post_migrate/20180913142237_schedule_digest_personal_access_tokens.rb b/db/post_migrate/20180913142237_schedule_digest_personal_access_tokens.rb deleted file mode 100644 index 951cb3b088c..00000000000 --- a/db/post_migrate/20180913142237_schedule_digest_personal_access_tokens.rb +++ /dev/null @@ -1,28 +0,0 @@ -class ScheduleDigestPersonalAccessTokens < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - BATCH_SIZE = 10_000 - MIGRATION = 'DigestColumn' - DELAY_INTERVAL = 5.minutes.to_i - - disable_ddl_transaction! - - class PersonalAccessToken < ActiveRecord::Base - include EachBatch - - self.table_name = 'personal_access_tokens' - end - - def up - PersonalAccessToken.where('token is NOT NULL').each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck('MIN(id)', 'MAX(id)').first - BackgroundMigrationWorker.perform_in(index * DELAY_INTERVAL, MIGRATION, ['PersonalAccessToken', :token, :token_digest, *range]) - end - end - - def down - # raise ActiveRecord::IrreversibleMigration - end -end diff --git a/db/post_migrate/20180914162043_encrypt_web_hooks_columns.rb b/db/post_migrate/20180914162043_encrypt_web_hooks_columns.rb deleted file mode 100644 index ef864f490bb..00000000000 --- a/db/post_migrate/20180914162043_encrypt_web_hooks_columns.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class EncryptWebHooksColumns < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - BATCH_SIZE = 10000 - RANGE_SIZE = 100 - MIGRATION = 'EncryptColumns' - COLUMNS = [:token, :url] - - WebHook = ::Gitlab::BackgroundMigration::Models::EncryptColumns::WebHook - - disable_ddl_transaction! - - def up - WebHook.each_batch(of: BATCH_SIZE) do |relation, index| - delay = index * 2.minutes - - relation.each_batch(of: RANGE_SIZE) do |relation| - range = relation.pluck('MIN(id)', 'MAX(id)').first - args = [WebHook, COLUMNS, *range] - - BackgroundMigrationWorker.perform_in(delay, MIGRATION, args) - end - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20180914201132_remove_sidekiq_throttling_from_application_settings.rb b/db/post_migrate/20180914201132_remove_sidekiq_throttling_from_application_settings.rb deleted file mode 100644 index 2c007ec395d..00000000000 --- a/db/post_migrate/20180914201132_remove_sidekiq_throttling_from_application_settings.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. - -class RemoveSidekiqThrottlingFromApplicationSettings < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :application_settings, :sidekiq_throttling_enabled, :boolean, default: false - remove_column :application_settings, :sidekiq_throttling_queues, :string - remove_column :application_settings, :sidekiq_throttling_factor, :decimal - - Rails.cache.delete("ApplicationSetting:#{Gitlab::VERSION}:#{Rails.version}") - end -end diff --git a/db/post_migrate/20180917172041_remove_wikis_count_from_site_statistics.rb b/db/post_migrate/20180917172041_remove_wikis_count_from_site_statistics.rb deleted file mode 100644 index 3b8300dabeb..00000000000 --- a/db/post_migrate/20180917172041_remove_wikis_count_from_site_statistics.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true -class RemoveWikisCountFromSiteStatistics < ActiveRecord::Migration[4.2] - def change - remove_column :site_statistics, :wikis_count, :integer - end -end diff --git a/db/post_migrate/20181008145341_steal_encrypt_columns.rb b/db/post_migrate/20181008145341_steal_encrypt_columns.rb deleted file mode 100644 index 4102643ba13..00000000000 --- a/db/post_migrate/20181008145341_steal_encrypt_columns.rb +++ /dev/null @@ -1,15 +0,0 @@ -class StealEncryptColumns < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal('EncryptColumns') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20181008145359_remove_web_hooks_token_and_url.rb b/db/post_migrate/20181008145359_remove_web_hooks_token_and_url.rb deleted file mode 100644 index 93e4458b795..00000000000 --- a/db/post_migrate/20181008145359_remove_web_hooks_token_and_url.rb +++ /dev/null @@ -1,10 +0,0 @@ -class RemoveWebHooksTokenAndUrl < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :web_hooks, :token, :string - remove_column :web_hooks, :url, :string, limit: 2000 - end -end diff --git a/db/post_migrate/20181008200441_remove_circuit_breaker.rb b/db/post_migrate/20181008200441_remove_circuit_breaker.rb deleted file mode 100644 index 09491038e50..00000000000 --- a/db/post_migrate/20181008200441_remove_circuit_breaker.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class RemoveCircuitBreaker < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - disable_ddl_transaction! - - CIRCUIT_BREAKER_COLUMS_WITH_DEFAULT = { - circuitbreaker_failure_count_threshold: 3, - circuitbreaker_failure_reset_time: 1800, - circuitbreaker_storage_timeout: 15, - circuitbreaker_access_retries: 3, - circuitbreaker_check_interval: 1 - }.freeze - - def up - CIRCUIT_BREAKER_COLUMS_WITH_DEFAULT.keys.each do |column| - remove_column(:application_settings, column) if column_exists?(:application_settings, column) - end - end - - def down - CIRCUIT_BREAKER_COLUMS_WITH_DEFAULT.each do |column, default| - # rubocop:disable Migration/AddColumnWithDefault - add_column_with_default(:application_settings, column, :integer, default: default) unless column_exists?(:application_settings, column) - # rubocop:enable Migration/AddColumnWithDefault - end - end -end diff --git a/db/post_migrate/20181010133639_backfill_store_project_full_path_in_repo.rb b/db/post_migrate/20181010133639_backfill_store_project_full_path_in_repo.rb deleted file mode 100644 index 247f5980f7e..00000000000 --- a/db/post_migrate/20181010133639_backfill_store_project_full_path_in_repo.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class BackfillStoreProjectFullPathInRepo < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - DELAY_INTERVAL = 5.minutes - UP_MIGRATION = 'BackfillProjectFullpathInRepoConfig::Up' - DOWN_MIGRATION = 'BackfillProjectFullpathInRepoConfig::Down' - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - self.table_name = 'projects' - - include EachBatch - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Project, UP_MIGRATION, DELAY_INTERVAL) - end - - def down - queue_background_migration_jobs_by_range_at_intervals(Project, DOWN_MIGRATION, DELAY_INTERVAL) - end -end diff --git a/db/post_migrate/20181013005024_remove_koding_from_application_settings.rb b/db/post_migrate/20181013005024_remove_koding_from_application_settings.rb deleted file mode 100644 index 550ad94f4ab..00000000000 --- a/db/post_migrate/20181013005024_remove_koding_from_application_settings.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class RemoveKodingFromApplicationSettings < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - remove_column :application_settings, :koding_enabled - remove_column :application_settings, :koding_url - end - - def down - add_column :application_settings, :koding_enabled, :boolean # rubocop:disable Migration/SaferBooleanColumn - add_column :application_settings, :koding_url, :string - end -end diff --git a/db/post_migrate/20181022173835_enqueue_populate_cluster_kubernetes_namespace.rb b/db/post_migrate/20181022173835_enqueue_populate_cluster_kubernetes_namespace.rb deleted file mode 100644 index 94a4574abff..00000000000 --- a/db/post_migrate/20181022173835_enqueue_populate_cluster_kubernetes_namespace.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class EnqueuePopulateClusterKubernetesNamespace < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'PopulateClusterKubernetesNamespaceTable'.freeze - - disable_ddl_transaction! - - def up - BackgroundMigrationWorker.perform_async(MIGRATION) - end - - def down - Clusters::KubernetesNamespace.delete_all - end -end diff --git a/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb b/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb deleted file mode 100644 index 7c2df832882..00000000000 --- a/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class MigrateForbiddenRedirectUris < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - FORBIDDEN_SCHEMES = %w[data:// vbscript:// javascript://] - NEW_URI = 'http://forbidden-scheme-has-been-overwritten' - - disable_ddl_transaction! - - def up - update_forbidden_uris(:oauth_applications) - update_forbidden_uris(:oauth_access_grants) - end - - def down - # noop - end - - private - - def update_forbidden_uris(table_name) - update_column_in_batches(table_name, :redirect_uri, NEW_URI) do |table, query| - where_clause = FORBIDDEN_SCHEMES.map do |scheme| - table[:redirect_uri].matches("#{scheme}%") - end.inject(&:or) - - query.where(where_clause) - end - end -end diff --git a/db/post_migrate/20181030135124_fill_empty_finished_at_in_deployments.rb b/db/post_migrate/20181030135124_fill_empty_finished_at_in_deployments.rb deleted file mode 100644 index 228841a14a0..00000000000 --- a/db/post_migrate/20181030135124_fill_empty_finished_at_in_deployments.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class FillEmptyFinishedAtInDeployments < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DEPLOYMENT_STATUS_SUCCESS = 2 # Equivalent to Deployment.statuses[:success] - - class Deployments < ActiveRecord::Base - self.table_name = 'deployments' - - include EachBatch - end - - def up - FillEmptyFinishedAtInDeployments::Deployments - .where('finished_at IS NULL') - .where('status = ?', DEPLOYMENT_STATUS_SUCCESS) - .each_batch(of: 10_000) do |relation| - relation.update_all('finished_at=created_at') - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20181101091005_steal_digest_column.rb b/db/post_migrate/20181101091005_steal_digest_column.rb deleted file mode 100644 index 58ea710c18a..00000000000 --- a/db/post_migrate/20181101091005_steal_digest_column.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class StealDigestColumn < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal('DigestColumn') - end - - def down - # raise ActiveRecord::IrreversibleMigration - end -end diff --git a/db/post_migrate/20181101091124_remove_token_from_personal_access_tokens.rb b/db/post_migrate/20181101091124_remove_token_from_personal_access_tokens.rb deleted file mode 100644 index 415373068d5..00000000000 --- a/db/post_migrate/20181101091124_remove_token_from_personal_access_tokens.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class RemoveTokenFromPersonalAccessTokens < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :personal_access_tokens, :token, :string - end -end diff --git a/db/post_migrate/20181105201455_steal_fill_store_upload.rb b/db/post_migrate/20181105201455_steal_fill_store_upload.rb deleted file mode 100644 index a31a4eab472..00000000000 --- a/db/post_migrate/20181105201455_steal_fill_store_upload.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class StealFillStoreUpload < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10_000 - - disable_ddl_transaction! - - class Upload < ActiveRecord::Base - include EachBatch - - self.table_name = 'uploads' - self.inheritance_column = :_type_disabled # Disable STI - end - - def up - Gitlab::BackgroundMigration.steal('FillStoreUpload') - - Upload.where(store: nil).each_batch(of: BATCH_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - Gitlab::BackgroundMigration::FillStoreUpload.new.perform(*range) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20181107054254_remove_restricted_todos_again.rb b/db/post_migrate/20181107054254_remove_restricted_todos_again.rb deleted file mode 100644 index bbeb4e8a1de..00000000000 --- a/db/post_migrate/20181107054254_remove_restricted_todos_again.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -# rescheduling of the revised RemoveRestrictedTodosWithCte background migration -class RemoveRestrictedTodosAgain < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - MIGRATION = 'RemoveRestrictedTodos'.freeze - BATCH_SIZE = 1000 - DELAY_INTERVAL = 5.minutes.to_i - - class Project < ActiveRecord::Base - include EachBatch - - self.table_name = 'projects' - end - - def up - Project.where('EXISTS (SELECT 1 FROM todos WHERE todos.project_id = projects.id)') - .each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pluck('MIN(id)', 'MAX(id)').first - - BackgroundMigrationWorker.perform_in(index * DELAY_INTERVAL, MIGRATION, range) - end - end - - def down - # nothing to do - end -end diff --git a/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb b/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb deleted file mode 100644 index ba82072fc98..00000000000 --- a/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRunnersTokenEncryption < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10000 - RANGE_SIZE = 2000 - MIGRATION = 'EncryptRunnersTokens' - - MODELS = [ - ::Gitlab::BackgroundMigration::Models::EncryptColumns::Settings, - ::Gitlab::BackgroundMigration::Models::EncryptColumns::Namespace, - ::Gitlab::BackgroundMigration::Models::EncryptColumns::Project, - ::Gitlab::BackgroundMigration::Models::EncryptColumns::Runner - ].freeze - - disable_ddl_transaction! - - def up - MODELS.each do |model| - model.each_batch(of: BATCH_SIZE) do |relation, index| - delay = index * 4.minutes - - relation.each_batch(of: RANGE_SIZE) do |relation| - range = relation.pluck('MIN(id)', 'MAX(id)').first - args = [model.name.demodulize.downcase, *range] - - BackgroundMigrationWorker.perform_in(delay, MIGRATION, args) - end - end - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20181123042307_drop_site_statistics.rb b/db/post_migrate/20181123042307_drop_site_statistics.rb deleted file mode 100644 index 8986374ef65..00000000000 --- a/db/post_migrate/20181123042307_drop_site_statistics.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class DropSiteStatistics < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - drop_table :site_statistics - end - - def down - create_table :site_statistics do |t| - t.integer :repositories_count, default: 0, null: false - end - - execute('INSERT INTO site_statistics (id) VALUES(1)') - end -end diff --git a/db/post_migrate/20181130102132_backfill_hashed_project_repositories.rb b/db/post_migrate/20181130102132_backfill_hashed_project_repositories.rb deleted file mode 100644 index 7814cdba58a..00000000000 --- a/db/post_migrate/20181130102132_backfill_hashed_project_repositories.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class BackfillHashedProjectRepositories < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - DELAY_INTERVAL = 5.minutes - MIGRATION = 'BackfillHashedProjectRepositories' - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - include EachBatch - - self.table_name = 'projects' - end - - def up - queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, DELAY_INTERVAL) - end - - def down - # no-op: since there could have been existing rows before the migration do not remove anything - end -end diff --git a/db/post_migrate/20181219130552_update_project_import_visibility_level.rb b/db/post_migrate/20181219130552_update_project_import_visibility_level.rb deleted file mode 100644 index bfa452578a3..00000000000 --- a/db/post_migrate/20181219130552_update_project_import_visibility_level.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -class UpdateProjectImportVisibilityLevel < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - BATCH_SIZE = 100 - - PRIVATE = 0 - INTERNAL = 10 - - disable_ddl_transaction! - - class Namespace < ActiveRecord::Base - self.table_name = 'namespaces' - end - - class Project < ActiveRecord::Base - include EachBatch - - belongs_to :namespace - - IMPORT_TYPE = 'gitlab_project' - - scope :with_group_visibility, ->(visibility) do - joins(:namespace) - .where(namespaces: { type: 'Group', visibility_level: visibility }) - .where(import_type: IMPORT_TYPE) - .where('projects.visibility_level > namespaces.visibility_level') - end - - self.table_name = 'projects' - end - - def up - # Update project's visibility to be the same as the group - # if it is more restrictive than `PUBLIC`. - update_projects_visibility(PRIVATE) - update_projects_visibility(INTERNAL) - end - - def down - # no-op: unrecoverable data migration - end - - private - - def update_projects_visibility(visibility) - say_with_time("Updating project visibility to #{visibility} on #{Project::IMPORT_TYPE} imports.") do - Project.with_group_visibility(visibility).select(:id).each_batch(of: BATCH_SIZE) do |batch, _index| - batch_sql = batch.select(:id).to_sql - - say("Updating #{batch.size} items.", true) - - execute("UPDATE projects SET visibility_level = '#{visibility}' WHERE id IN (#{batch_sql})") - end - end - end -end diff --git a/db/post_migrate/20181219145520_migrate_cluster_configure_worker_sidekiq_queue.rb b/db/post_migrate/20181219145520_migrate_cluster_configure_worker_sidekiq_queue.rb deleted file mode 100644 index c37f8c039c0..00000000000 --- a/db/post_migrate/20181219145520_migrate_cluster_configure_worker_sidekiq_queue.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class MigrateClusterConfigureWorkerSidekiqQueue < ActiveRecord::Migration[5.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'gcp_cluster:cluster_platform_configure', to: 'gcp_cluster:cluster_configure' - end - - def down - sidekiq_queue_migrate 'gcp_cluster:cluster_configure', to: 'gcp_cluster:cluster_platform_configure' - end -end diff --git a/db/post_migrate/20200310215714_migrate_saml_identities_to_scim_identities.rb b/db/post_migrate/20200310215714_migrate_saml_identities_to_scim_identities.rb index e2ec7b62d31..b41c55ce622 100644 --- a/db/post_migrate/20200310215714_migrate_saml_identities_to_scim_identities.rb +++ b/db/post_migrate/20200310215714_migrate_saml_identities_to_scim_identities.rb @@ -20,7 +20,7 @@ class MigrateSamlIdentitiesToScimIdentities < ActiveRecord::Migration[6.0] record.attributes.extract!("extern_uid", "user_id", "group_id", "active", "created_at", "updated_at") end - Gitlab::Database.bulk_insert(:scim_identities, data_to_insert, on_conflict: :do_nothing) + Gitlab::Database.bulk_insert(:scim_identities, data_to_insert, on_conflict: :do_nothing) # rubocop:disable Gitlab/BulkInsert end end diff --git a/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb b/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb index 2db270d303c..76b00796d1a 100644 --- a/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb +++ b/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb @@ -17,7 +17,7 @@ class BackfillDeploymentClustersFromDeployments < ActiveRecord::Migration[6.0] class Deployment < ActiveRecord::Base include EachBatch - default_scope { where('cluster_id IS NOT NULL') } + default_scope { where('cluster_id IS NOT NULL') } # rubocop:disable Cop/DefaultScope self.table_name = 'deployments' end diff --git a/db/post_migrate/20200408132152_remove_namespaces_trial_ends_on.rb b/db/post_migrate/20200408132152_remove_namespaces_trial_ends_on.rb new file mode 100644 index 00000000000..cfe0daaf50f --- /dev/null +++ b/db/post_migrate/20200408132152_remove_namespaces_trial_ends_on.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class RemoveNamespacesTrialEndsOn < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :namespaces, 'index_namespaces_on_trial_ends_on' + + with_lock_retries do + remove_column :namespaces, :trial_ends_on + end + end + + def down + unless column_exists?(:namespaces, :trial_ends_on) + with_lock_retries do + add_column :namespaces, :trial_ends_on, :datetime_with_timezone + end + end + + add_concurrent_index :namespaces, :trial_ends_on, using: 'btree', where: 'trial_ends_on IS NOT NULL' + end +end diff --git a/db/post_migrate/20200421195234_backfill_status_page_published_incidents.rb b/db/post_migrate/20200421195234_backfill_status_page_published_incidents.rb new file mode 100644 index 00000000000..fa7a5a9d924 --- /dev/null +++ b/db/post_migrate/20200421195234_backfill_status_page_published_incidents.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class BackfillStatusPagePublishedIncidents < ActiveRecord::Migration[6.0] + DOWNTIME = false + + disable_ddl_transaction! + + class Incident < ActiveRecord::Base + self.table_name = 'status_page_published_incidents' + end + + class StatusPageIssue < ActiveRecord::Base + include ::EachBatch + + self.table_name = 'issues' + + scope :published_only, -> do + joins('INNER JOIN status_page_settings ON status_page_settings.project_id = issues.project_id') + .where('status_page_settings.enabled = true') + .where(confidential: false) + end + end + + def up + current_time = Time.current + + StatusPageIssue.published_only.each_batch do |batch| + incidents = batch.map do |status_page_issue| + { + issue_id: status_page_issue.id, + created_at: current_time, + updated_at: current_time + } + end + + Incident.insert_all(incidents, unique_by: :issue_id) + end + end + + def down + # no op + + # While we expect this table to be empty at the point of + # the up migration, there is no reliable way to determine + # whether records were added as a part of the migration + # or after it has run. + end +end diff --git a/db/post_migrate/20200518114540_schedule_fix_ruby_object_in_audit_events.rb b/db/post_migrate/20200518114540_schedule_fix_ruby_object_in_audit_events.rb new file mode 100644 index 00000000000..e4335089540 --- /dev/null +++ b/db/post_migrate/20200518114540_schedule_fix_ruby_object_in_audit_events.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class ScheduleFixRubyObjectInAuditEvents < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_audit_events_on_ruby_object_in_details' + INTERVAL = 2.minutes.to_i + BATCH_SIZE = 1_000 + MIGRATION = 'FixRubyObjectInAuditEvents' + + disable_ddl_transaction! + + class AuditEvent < ActiveRecord::Base + self.table_name = 'audit_events' + + include ::EachBatch + end + + def up + return unless Gitlab.ee? + + # create temporary index for audit_events with ruby/object in details field, may take well over 1h + add_concurrent_index(:audit_events, :id, where: "details ~~ '%ruby/object%'", name: INDEX_NAME) + + relation = AuditEvent.where("details ~~ '%ruby/object%'") + + queue_background_migration_jobs_by_range_at_intervals( + relation, + MIGRATION, + INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # temporary index is to be dropped in a different migration in an upcoming release + # https://gitlab.com/gitlab-org/gitlab/issues/196842 + remove_concurrent_index_by_name(:audit_events, INDEX_NAME) + end +end diff --git a/db/post_migrate/20200518133123_add_index_on_starting_ending_at_to_metrics_dashboard_annotations.rb b/db/post_migrate/20200518133123_add_index_on_starting_ending_at_to_metrics_dashboard_annotations.rb new file mode 100644 index 00000000000..3094fff0d1d --- /dev/null +++ b/db/post_migrate/20200518133123_add_index_on_starting_ending_at_to_metrics_dashboard_annotations.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexOnStartingEndingAtToMetricsDashboardAnnotations < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_metrics_dashboard_annotations_on_timespan_end' + + disable_ddl_transaction! + + def up + add_concurrent_index :metrics_dashboard_annotations, 'COALESCE(ending_at, starting_at)', name: INDEX_NAME + end + + def down + remove_concurrent_index :metrics_dashboard_annotations, 'COALESCE(ending_at, starting_at)', name: INDEX_NAME + end +end diff --git a/db/post_migrate/20200519171058_update_index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial.rb b/db/post_migrate/20200519171058_update_index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial.rb new file mode 100644 index 00000000000..e09ad4bdadf --- /dev/null +++ b/db/post_migrate/20200519171058_update_index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class UpdateIndexCiBuildsOnCommitIdAndArtifactsExpireatandidpartial < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial' + NEW_INDEX_NAME = 'index_ci_builds_on_commit_id_artifacts_expired_at_and_id' + + OLD_CLAUSE = "type::text = 'Ci::Build'::text AND (retried = false OR retried IS NULL) AND + (name::text = ANY (ARRAY['sast'::character varying, + 'dependency_scanning'::character varying, + 'sast:container'::character varying, + 'container_scanning'::character varying, + 'dast'::character varying]::text[]))" + + NEW_CLAUSE = "type::text = 'Ci::Build'::text AND (retried = false OR retried IS NULL) AND + (name::text = ANY (ARRAY['sast'::character varying, + 'secret_detection'::character varying, + 'dependency_scanning'::character varying, + 'container_scanning'::character varying, + 'dast'::character varying]::text[]))" + + def up + add_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], name: NEW_INDEX_NAME, where: NEW_CLAUSE + remove_concurrent_index_by_name :ci_builds, OLD_INDEX_NAME + end + + def down + add_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], name: OLD_INDEX_NAME, where: OLD_CLAUSE + remove_concurrent_index_by_name :ci_builds, NEW_INDEX_NAME + end +end diff --git a/db/post_migrate/20200525121014_drop_users_ghost_column.rb b/db/post_migrate/20200525121014_drop_users_ghost_column.rb new file mode 100644 index 00000000000..1f80bc74b9d --- /dev/null +++ b/db/post_migrate/20200525121014_drop_users_ghost_column.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class DropUsersGhostColumn < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :users, 'index_users_on_ghost' + + with_lock_retries do + remove_column :users, :ghost + end + end + + def down + unless column_exists?(:users, :ghost) + with_lock_retries do + add_column :users, :ghost, :boolean # rubocop:disable Migration/AddColumnsToWideTables + end + end + + execute 'UPDATE users set ghost = TRUE WHERE user_type = 5' + + add_concurrent_index :users, :ghost + end +end diff --git a/db/post_migrate/20200525144525_migrate_stuck_import_jobs_queue_to_stuck_project_import_jobs.rb b/db/post_migrate/20200525144525_migrate_stuck_import_jobs_queue_to_stuck_project_import_jobs.rb new file mode 100644 index 00000000000..57e25c928f1 --- /dev/null +++ b/db/post_migrate/20200525144525_migrate_stuck_import_jobs_queue_to_stuck_project_import_jobs.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class MigrateStuckImportJobsQueueToStuckProjectImportJobs < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + sidekiq_queue_migrate 'cronjob:stuck_import_jobs', to: 'cronjob:import_stuck_project_import_jobs' + end + + def down + sidekiq_queue_migrate 'cronjob:import_stuck_project_import_jobs', to: 'cronjob:stuck_import_jobs' + end +end diff --git a/db/post_migrate/20200526000407_seed_repository_storages_weighted.rb b/db/post_migrate/20200526000407_seed_repository_storages_weighted.rb new file mode 100644 index 00000000000..e5a0acb9cd8 --- /dev/null +++ b/db/post_migrate/20200526000407_seed_repository_storages_weighted.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class SeedRepositoryStoragesWeighted < ActiveRecord::Migration[6.0] + class ApplicationSetting < ActiveRecord::Base + serialize :repository_storages + self.table_name = 'application_settings' + end + + def up + ApplicationSetting.all.each do |settings| + storages = Gitlab.config.repositories.storages.keys.collect do |storage| + weight = settings.repository_storages.include?(storage) ? 100 : 0 + [storage, weight] + end + + settings.repository_storages_weighted = Hash[storages] + settings.save! + end + end + + def down + end +end diff --git a/db/post_migrate/20200527094322_drop_vulnerability_confidence_index.rb b/db/post_migrate/20200527094322_drop_vulnerability_confidence_index.rb new file mode 100644 index 00000000000..e9a9dd5eff8 --- /dev/null +++ b/db/post_migrate/20200527094322_drop_vulnerability_confidence_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class DropVulnerabilityConfidenceIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + INDEX_NAME = 'index_vulnerability_on_id_and_confidence_eq_zero' + + def up + Gitlab::BackgroundMigration.steal('RemoveUndefinedVulnerabilityConfidenceLevel') + + remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME + end + + def down + add_concurrent_index(:vulnerabilities, :id, where: 'confidence = 0', name: INDEX_NAME) + end +end diff --git a/db/post_migrate/20200527095401_drop_vulnerability_occurrence_confidence_index.rb b/db/post_migrate/20200527095401_drop_vulnerability_occurrence_confidence_index.rb new file mode 100644 index 00000000000..99fe4da7686 --- /dev/null +++ b/db/post_migrate/20200527095401_drop_vulnerability_occurrence_confidence_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class DropVulnerabilityOccurrenceConfidenceIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + INDEX_NAME = 'index_vulnerability_occurrences_on_id_and_confidence_eq_zero' + + def up + Gitlab::BackgroundMigration.steal('RemoveUndefinedOccurrenceConfidenceLevel') + + remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME + end + + def down + add_concurrent_index(:vulnerability_occurrences, :id, where: 'confidence = 0', name: INDEX_NAME) + end +end diff --git a/db/post_migrate/20200528123703_add_merge_request_partial_index_to_events.rb b/db/post_migrate/20200528123703_add_merge_request_partial_index_to_events.rb new file mode 100644 index 00000000000..bf2269e77ab --- /dev/null +++ b/db/post_migrate/20200528123703_add_merge_request_partial_index_to_events.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddMergeRequestPartialIndexToEvents < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_events_on_author_id_and_created_at_merge_requests' + + def up + add_concurrent_index( + :events, + [:author_id, :created_at], + name: INDEX_NAME, + where: "(target_type = 'MergeRequest')" + ) + end + + def down + remove_concurrent_index :events, INDEX_NAME + end +end diff --git a/db/post_migrate/20200602013900_add_limit_to_designs_filename.rb b/db/post_migrate/20200602013900_add_limit_to_designs_filename.rb new file mode 100644 index 00000000000..88732648965 --- /dev/null +++ b/db/post_migrate/20200602013900_add_limit_to_designs_filename.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddLimitToDesignsFilename < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit(:design_management_designs, :filename, 255, validate: false) + end + + def down + remove_text_limit(:design_management_designs, :filename) + end +end diff --git a/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb b/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb new file mode 100644 index 00000000000..0458481c6bd --- /dev/null +++ b/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class CapDesignsFilenameLengthToNewLimit < ActiveRecord::Migration[6.0] + DOWNTIME = false + + CHAR_LENGTH = 255 + MODIFIED_NAME = 'gitlab-modified-' + MODIFIED_EXTENSION = '.jpg' + + def up + arel_table = Arel::Table.new(:design_management_designs) + + # Design filenames larger than the limit will be renamed to "gitlab-modified-{id}.jpg", + # which will be valid and unique. The design file itself will appear broken, as it is + # understood that no designs with filenames that exceed this limit will be legitimate. + # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33565/diffs#note_355789080 + new_value_clause = Arel::Nodes::NamedFunction.new( + 'CONCAT', + [ + Arel::Nodes.build_quoted(MODIFIED_NAME), + arel_table[:id], + Arel::Nodes.build_quoted(MODIFIED_EXTENSION) + ] + ) + where_clause = Arel::Nodes::NamedFunction.new( + 'CHAR_LENGTH', + [arel_table[:filename]] + ).gt(CHAR_LENGTH) + + update_arel = Arel::UpdateManager.new.table(arel_table) + .set([[arel_table[:filename], new_value_clause]]) + .where(where_clause) + + ActiveRecord::Base.connection.execute(update_arel.to_sql) + end + + def down + # no-op : the original filename is lost forever + end +end diff --git a/db/post_migrate/20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb b/db/post_migrate/20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb new file mode 100644 index 00000000000..1935eaa1237 --- /dev/null +++ b/db/post_migrate/20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb @@ -0,0 +1,178 @@ +# frozen_string_literal: true + +# This migration adds or updates the routes for all the entities affected by +# post-migration '20200511083541_cleanup_projects_with_missing_namespace' +# - A route is added for the 'lost-and-found' group +# - A route is added for the Ghost user (if not already defined) +# - The routes for all the orphaned projects that were moved under the 'lost-and-found' +# group are updated to reflect the new path +class UpdateRoutesForLostAndFoundGroupAndOrphanedProjects < ActiveRecord::Migration[6.0] + DOWNTIME = false + + class User < ActiveRecord::Base + self.table_name = 'users' + + LOST_AND_FOUND_GROUP = 'lost-and-found' + USER_TYPE_GHOST = 5 + ACCESS_LEVEL_OWNER = 50 + + has_one :namespace, -> { where(type: nil) }, + foreign_key: :owner_id, inverse_of: :owner, autosave: true, + class_name: 'UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace' + + def lost_and_found_group + # Find the 'lost-and-found' group + # There should only be one Group owned by the Ghost user starting with 'lost-and-found' + Group + .joins('INNER JOIN members ON namespaces.id = members.source_id') + .where('namespaces.type = ?', 'Group') + .where('members.type = ?', 'GroupMember') + .where('members.source_type = ?', 'Namespace') + .where('members.user_id = ?', self.id) + .where('members.access_level = ?', ACCESS_LEVEL_OWNER) + .find_by(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%")) + end + + class << self + # Return the ghost user + def ghost + User.find_by(user_type: USER_TYPE_GHOST) + end + end + end + + # Temporary Concern to not repeat the same methods twice + module HasPath + extend ActiveSupport::Concern + + def full_path + if parent && path + parent.full_path + '/' + path + else + path + end + end + + def full_name + if parent && name + parent.full_name + ' / ' + name + else + name + end + end + end + + class Namespace < ActiveRecord::Base + include HasPath + + self.table_name = 'namespaces' + + belongs_to :owner, class_name: 'UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::User' + belongs_to :parent, class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace" + has_many :children, foreign_key: :parent_id, + class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace" + has_many :projects, class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Project" + + def ensure_route! + unless Route.for_source('Namespace', self.id) + Route.create!( + source_id: self.id, + source_type: 'Namespace', + path: self.full_path, + name: self.full_name + ) + end + end + + def generate_unique_path + # Generate a unique path if there is no route for the namespace + # (an existing route guarantees that the path is already unique) + unless Route.for_source('Namespace', self.id) + self.path = Uniquify.new.string(self.path) do |str| + Route.where(path: str).exists? + end + end + end + end + + class Group < Namespace + # Disable STI to allow us to manually set "type = 'Group'" + # Otherwise rails forces "type = CleanupProjectsWithMissingNamespace::Group" + self.inheritance_column = :_type_disabled + end + + class Route < ActiveRecord::Base + self.table_name = 'routes' + + def self.for_source(source_type, source_id) + Route.find_by(source_type: source_type, source_id: source_id) + end + end + + class Project < ActiveRecord::Base + include HasPath + + self.table_name = 'projects' + + belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id', + class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Group" + belongs_to :namespace, + class_name: "UpdateRoutesForLostAndFoundGroupAndOrphanedProjects::Namespace" + + alias_method :parent, :namespace + alias_attribute :parent_id, :namespace_id + + def ensure_route! + Route.find_or_initialize_by(source_type: 'Project', source_id: self.id).tap do |record| + record.path = self.full_path + record.name = self.full_name + record.save! + end + end + end + + def up + # Reset the column information of all the models that update the database + # to ensure the Active Record's knowledge of the table structure is current + Namespace.reset_column_information + Route.reset_column_information + + # Find the ghost user, its namespace and the "lost and found" group + ghost_user = User.ghost + return unless ghost_user # No reason to continue if there is no Ghost user + + ghost_namespace = ghost_user.namespace + lost_and_found_group = ghost_user.lost_and_found_group + + # No reason to continue if there is no 'lost-and-found' group + # 1. No orphaned projects were found in this instance, or + # 2. The 'lost-and-found' group and the orphaned projects have been already deleted + return unless lost_and_found_group + + # Update the 'lost-and-found' group description to be more self-explanatory + lost_and_found_group.generate_unique_path + lost_and_found_group.description = + 'Group for storing projects that were not properly deleted. '\ + 'It should be considered as a system level Group with non-working '\ + 'projects inside it. The contents may be deleted with a future update. '\ + 'More info: gitlab.com/gitlab-org/gitlab/-/issues/198603' + lost_and_found_group.save! + + # Update the routes for the Ghost user, the "lost and found" group + # and all the orphaned projects + ghost_namespace.ensure_route! + lost_and_found_group.ensure_route! + + # The following does a fast index scan by namespace_id + # No reason to process in batches: + # - 66 projects in GitLab.com, less than 1ms execution time to fetch them + # with a constant update time for each + lost_and_found_group.projects.each do |project| + project.ensure_route! + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb b/db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb new file mode 100644 index 00000000000..0566524fa90 --- /dev/null +++ b/db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +class BackfillImportedSnippetRepositories < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 200 + MIGRATION = 'BackfillSnippetRepositories' + + disable_ddl_transaction! + + class Snippet < ActiveRecord::Base + include EachBatch + + self.table_name = 'snippets' + self.inheritance_column = :_type_disabled + end + + class SnippetRepository < ActiveRecord::Base + self.table_name = 'snippet_repositories' + end + + def up + index = 1 + + Snippet.select(:id).where.not(id: SnippetRepository.select(:snippet_id)).each_batch(of: BATCH_SIZE, column: 'id') do |batch| + split_in_consecutive_batches(batch).each do |ids_batch| + migrate_in(index * DELAY_INTERVAL, MIGRATION, [ids_batch.first, ids_batch.last]) + + index += 1 + end + end + end + + def down + # no-op + end + + private + + def split_in_consecutive_batches(relation) + ids = relation.pluck(:id) + + (ids.first..ids.last).to_a.split {|i| !ids.include?(i) }.select(&:present?) + end +end diff --git a/db/post_migrate/20200608075553_add_index_on_user_id_and_created_at_and_source_to_ci_pipelines.rb b/db/post_migrate/20200608075553_add_index_on_user_id_and_created_at_and_source_to_ci_pipelines.rb new file mode 100644 index 00000000000..5df9cacdff6 --- /dev/null +++ b/db/post_migrate/20200608075553_add_index_on_user_id_and_created_at_and_source_to_ci_pipelines.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddIndexOnUserIdAndCreatedAtAndSourceToCiPipelines < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :ci_pipelines, [:user_id, :created_at, :source] + remove_concurrent_index :ci_pipelines, [:user_id, :created_at] + end + + def down + add_concurrent_index :ci_pipelines, [:user_id, :created_at] + remove_concurrent_index :ci_pipelines, [:user_id, :created_at, :source] + end +end diff --git a/db/post_migrate/20200609002841_add_partial_index_on_locked_state_id_to_merge_requests.rb b/db/post_migrate/20200609002841_add_partial_index_on_locked_state_id_to_merge_requests.rb new file mode 100644 index 00000000000..076c8fd8715 --- /dev/null +++ b/db/post_migrate/20200609002841_add_partial_index_on_locked_state_id_to_merge_requests.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddPartialIndexOnLockedStateIdToMergeRequests < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = "idx_merge_requests_on_target_project_id_and_locked_state" + LOCKED_STATE_ID = 4 + + disable_ddl_transaction! + + def up + add_concurrent_index :merge_requests, :target_project_id, where: "(state_id = #{LOCKED_STATE_ID})", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :merge_requests, name: INDEX_NAME + end +end |