diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /db/post_migrate | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'db/post_migrate')
215 files changed, 2674 insertions, 3331 deletions
diff --git a/db/post_migrate/20210602164044_schedule_latest_pipeline_id_population.rb b/db/post_migrate/20210602164044_schedule_latest_pipeline_id_population.rb deleted file mode 100644 index dfd2806fece..00000000000 --- a/db/post_migrate/20210602164044_schedule_latest_pipeline_id_population.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class ScheduleLatestPipelineIdPopulation < ActiveRecord::Migration[6.1] - def up - # no-op: This migration has been marked as no-op and replaced by - # `ReScheduleLatestPipelineIdPopulation` as we've found some problems. - # For more information: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65280 - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210604070207_retry_backfill_traversal_ids.rb b/db/post_migrate/20210604070207_retry_backfill_traversal_ids.rb deleted file mode 100644 index 5e540c7f359..00000000000 --- a/db/post_migrate/20210604070207_retry_backfill_traversal_ids.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class RetryBackfillTraversalIds < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - ROOTS_MIGRATION = 'BackfillNamespaceTraversalIdsRoots' - CHILDREN_MIGRATION = 'BackfillNamespaceTraversalIdsChildren' - DOWNTIME = false - DELAY_INTERVAL = 2.minutes - - disable_ddl_transaction! - - def up - duration = requeue_background_migration_jobs_by_range_at_intervals(ROOTS_MIGRATION, DELAY_INTERVAL) - requeue_background_migration_jobs_by_range_at_intervals(CHILDREN_MIGRATION, DELAY_INTERVAL, initial_delay: duration) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210604133651_schedule_merge_request_diff_users_background_migration.rb b/db/post_migrate/20210604133651_schedule_merge_request_diff_users_background_migration.rb deleted file mode 100644 index b9b694012f2..00000000000 --- a/db/post_migrate/20210604133651_schedule_merge_request_diff_users_background_migration.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class ScheduleMergeRequestDiffUsersBackgroundMigration < ActiveRecord::Migration[6.1] - def up - # no-op - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210606143426_add_index_for_container_registry_access_level.rb b/db/post_migrate/20210606143426_add_index_for_container_registry_access_level.rb deleted file mode 100644 index 64d37054eb8..00000000000 --- a/db/post_migrate/20210606143426_add_index_for_container_registry_access_level.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -class AddIndexForContainerRegistryAccessLevel < ActiveRecord::Migration[6.1] - include Gitlab::Database::SchemaHelpers - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - INDEX = 'index_project_features_on_project_id_include_container_registry' - - def up - if index_exists_by_name?('project_features', INDEX) - Gitlab::AppLogger.warn "Index not created because it already exists (this may be due to an aborted migration or similar): table_name: project_features, index_name: #{INDEX}" - return - end - - begin - disable_statement_timeout do - execute "CREATE UNIQUE INDEX CONCURRENTLY #{INDEX} ON project_features " \ - 'USING btree (project_id) INCLUDE (container_registry_access_level)' - end - rescue ActiveRecord::StatementInvalid => ex - raise "The index #{INDEX} couldn't be added: #{ex.message}" - end - - create_comment( - 'INDEX', - INDEX, - 'Included column (container_registry_access_level) improves performance of the ContainerRepository.for_group_and_its_subgroups scope query' - ) - end - - def down - remove_concurrent_index_by_name('project_features', INDEX) - end -end diff --git a/db/post_migrate/20210609125005_drop_non_partitioned_web_hook_logs.rb b/db/post_migrate/20210609125005_drop_non_partitioned_web_hook_logs.rb deleted file mode 100644 index 596b643e079..00000000000 --- a/db/post_migrate/20210609125005_drop_non_partitioned_web_hook_logs.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -class DropNonPartitionedWebHookLogs < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers - - DOWNTIME = false - - def up - drop_nonpartitioned_archive_table(:web_hook_logs) - end - - def down - execute(<<~SQL) - CREATE TABLE web_hook_logs_archived ( - id integer NOT NULL, - web_hook_id integer NOT NULL, - trigger character varying, - url character varying, - request_headers text, - request_data text, - response_headers text, - response_body text, - response_status character varying, - execution_duration double precision, - internal_error_message character varying, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL - ); - - ALTER TABLE ONLY web_hook_logs_archived ADD CONSTRAINT web_hook_logs_archived_pkey PRIMARY KEY (id); - - CREATE INDEX index_web_hook_logs_on_created_at_and_web_hook_id ON web_hook_logs_archived USING btree (created_at, web_hook_id); - CREATE INDEX index_web_hook_logs_on_web_hook_id ON web_hook_logs_archived USING btree (web_hook_id); - - ALTER TABLE ONLY web_hook_logs_archived ADD CONSTRAINT fk_rails_666826e111 FOREIGN KEY (web_hook_id) REFERENCES web_hooks(id) ON DELETE CASCADE; - SQL - - with_lock_retries do - create_trigger_to_sync_tables(:web_hook_logs, :web_hook_logs_archived, 'id') - end - end -end diff --git a/db/post_migrate/20210609202501_schedule_backfill_draft_status_on_merge_requests.rb b/db/post_migrate/20210609202501_schedule_backfill_draft_status_on_merge_requests.rb deleted file mode 100644 index ed9a64c84ab..00000000000 --- a/db/post_migrate/20210609202501_schedule_backfill_draft_status_on_merge_requests.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class ScheduleBackfillDraftStatusOnMergeRequests < ActiveRecord::Migration[6.1] - def up - # noop - # - end - - def down - # noop - # - end -end diff --git a/db/post_migrate/20210610042700_remove_clusters_applications_fluentd_table.rb b/db/post_migrate/20210610042700_remove_clusters_applications_fluentd_table.rb deleted file mode 100644 index 9d37180326f..00000000000 --- a/db/post_migrate/20210610042700_remove_clusters_applications_fluentd_table.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class RemoveClustersApplicationsFluentdTable < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - drop_table :clusters_applications_fluentd - end - - def down - create_table :clusters_applications_fluentd do |t| - t.integer :protocol, null: false, limit: 2 - t.integer :status, null: false - t.integer :port, null: false - t.references :cluster, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade } - t.timestamps_with_timezone null: false - t.string :version, null: false, limit: 255 - t.string :host, null: false, limit: 255 - t.boolean :cilium_log_enabled, default: true, null: false - t.boolean :waf_log_enabled, default: true, null: false - t.text :status_reason # rubocop:disable Migration/AddLimitToTextColumns - end - end -end diff --git a/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb b/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb deleted file mode 100644 index 47a6e39e87a..00000000000 --- a/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class MigrateProtectedAttributeToPendingBuilds < ActiveRecord::Migration[6.1] - include ::Gitlab::Database::DynamicModelHelpers - - disable_ddl_transaction! - - def up - return unless Gitlab.dev_or_test_env? || Gitlab.com? - - each_batch_range('ci_pending_builds', connection: connection, of: 1000) do |min, max| - execute <<~SQL - UPDATE ci_pending_builds - SET protected = true - FROM ci_builds - WHERE ci_pending_builds.build_id = ci_builds.id - AND ci_builds.protected = true - AND ci_pending_builds.id BETWEEN #{min} AND #{max} - SQL - end - end - - def down - # no op - end -end diff --git a/db/post_migrate/20210610113229_add_index_to_protected_pending_builds.rb b/db/post_migrate/20210610113229_add_index_to_protected_pending_builds.rb deleted file mode 100644 index 140bf7df4e6..00000000000 --- a/db/post_migrate/20210610113229_add_index_to_protected_pending_builds.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddIndexToProtectedPendingBuilds < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - INDEX_NAME = 'index_ci_pending_builds_id_on_protected_partial' - - disable_ddl_transaction! - - def up - add_concurrent_index :ci_pending_builds, :id, where: 'protected = true', name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :ci_pending_builds, INDEX_NAME - end -end diff --git a/db/post_migrate/20210610141711_disable_expiration_policies_linked_to_no_container_images.rb b/db/post_migrate/20210610141711_disable_expiration_policies_linked_to_no_container_images.rb deleted file mode 100644 index f4827c0bbc0..00000000000 --- a/db/post_migrate/20210610141711_disable_expiration_policies_linked_to_no_container_images.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class DisableExpirationPoliciesLinkedToNoContainerImages < ActiveRecord::Migration[6.1] - disable_ddl_transaction! - - BATCH_SIZE = 1000 - - class ContainerExpirationPolicy < ActiveRecord::Base - include ::EachBatch - self.table_name = 'container_expiration_policies' - end - - def up - ContainerExpirationPolicy.where(enabled: true).each_batch(of: BATCH_SIZE) do |batch, _| - sql = <<-SQL - WITH batched_relation AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} (#{batch.limit(BATCH_SIZE).to_sql}) - UPDATE container_expiration_policies - SET enabled = FALSE - FROM batched_relation - WHERE container_expiration_policies.project_id = batched_relation.project_id - AND NOT EXISTS (SELECT 1 FROM "container_repositories" WHERE container_repositories.project_id = container_expiration_policies.project_id) - SQL - execute(sql) - end - end - - def down - # no-op - - # we can't accuretaly know which policies were previously enabled during `#up` - end -end diff --git a/db/post_migrate/20210611080951_fix_missing_traversal_ids.rb b/db/post_migrate/20210611080951_fix_missing_traversal_ids.rb deleted file mode 100644 index 45728ef26f5..00000000000 --- a/db/post_migrate/20210611080951_fix_missing_traversal_ids.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -class FixMissingTraversalIds < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - ROOTS_MIGRATION = 'BackfillNamespaceTraversalIdsRoots' - CHILDREN_MIGRATION = 'BackfillNamespaceTraversalIdsChildren' - DOWNTIME = false - BATCH_SIZE = 1_000 - SUB_BATCH_SIZE = 50 - DELAY_INTERVAL = 2.minutes - ROOT_NS_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_root_namespaces' - CHILD_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_child_namespaces' - - disable_ddl_transaction! - - def up - add_concurrent_index :namespaces, :id, where: "parent_id IS NULL AND traversal_ids = '{}'", name: ROOT_NS_INDEX_NAME - add_concurrent_index :namespaces, :id, where: "parent_id IS NOT NULL AND traversal_ids = '{}'", name: CHILD_INDEX_NAME - - # Personal namespaces and top-level groups - final_delay = queue_background_migration_jobs_by_range_at_intervals( - ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsRoots::Namespace.base_query.where("traversal_ids = '{}'"), - ROOTS_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - other_job_arguments: [SUB_BATCH_SIZE], - track_jobs: true - ) - final_delay += DELAY_INTERVAL - - # Subgroups - queue_background_migration_jobs_by_range_at_intervals( - ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsChildren::Namespace.base_query.where("traversal_ids = '{}'"), - CHILDREN_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - initial_delay: final_delay, - other_job_arguments: [SUB_BATCH_SIZE], - track_jobs: true - ) - end - - def down - remove_concurrent_index_by_name :namespaces, ROOT_NS_INDEX_NAME - remove_concurrent_index_by_name :namespaces, CHILD_INDEX_NAME - end -end diff --git a/db/post_migrate/20210614124111_add_devops_adoption_sast_dast_indexes.rb b/db/post_migrate/20210614124111_add_devops_adoption_sast_dast_indexes.rb deleted file mode 100644 index 9d40fe30ed6..00000000000 --- a/db/post_migrate/20210614124111_add_devops_adoption_sast_dast_indexes.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class AddDevopsAdoptionSastDastIndexes < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - INDEX_SAST = 'index_ci_job_artifacts_sast_for_devops_adoption' - INDEX_DAST = 'index_ci_job_artifacts_dast_for_devops_adoption' - - def up - add_concurrent_index :ci_job_artifacts, [:project_id, :created_at], where: "file_type = 5", name: INDEX_SAST - add_concurrent_index :ci_job_artifacts, [:project_id, :created_at], where: "file_type = 8", name: INDEX_DAST - end - - def down - remove_concurrent_index_by_name :ci_job_artifacts, INDEX_SAST - remove_concurrent_index_by_name :ci_job_artifacts, INDEX_DAST - end -end diff --git a/db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb b/db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb deleted file mode 100644 index 818aea39762..00000000000 --- a/db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class FixBatchedMigrationsOldFormatJobArguments < ActiveRecord::Migration[6.1] - class BatchedMigration < ActiveRecord::Base - self.table_name = 'batched_background_migrations' - end - - def up - # rubocop:disable Style/WordArray - [ - ['events', 'id', ['id', 'id_convert_to_bigint'], [['id'], ['id_convert_to_bigint']]], - ['push_event_payloads', 'event_id', ['event_id', 'event_id_convert_to_bigint'], [['event_id'], ['event_id_convert_to_bigint']]] - ].each do |table_name, column_name, legacy_job_arguments, current_job_arguments| - base_scope = BatchedMigration - .where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob', table_name: table_name, column_name: column_name) - # rubocop:enable Style/WordArray - - # rubocop:disable Rails/WhereEquals - base_scope - .where('job_arguments = ?', Gitlab::Json.dump(legacy_job_arguments)) - .where('NOT EXISTS (?)', base_scope.select('1').where('job_arguments = ?', Gitlab::Json.dump(current_job_arguments))) - .update_all(job_arguments: current_job_arguments) - # rubocop:enable Rails/WhereEquals - end - end - - def down - # No-op, there is no way to know were the existing record migrated from - # legacy job arguments, or were using the current format from the start. - # There is no reason to go back anyway. - end -end diff --git a/db/post_migrate/20210616145254_add_partial_index_for_ci_builds_token.rb b/db/post_migrate/20210616145254_add_partial_index_for_ci_builds_token.rb deleted file mode 100644 index 6e169a6f0e1..00000000000 --- a/db/post_migrate/20210616145254_add_partial_index_for_ci_builds_token.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddPartialIndexForCiBuildsToken < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - NAME = 'index_ci_builds_on_token_partial' - - def up - add_concurrent_index :ci_builds, :token, unique: true, where: 'token IS NOT NULL', name: NAME - end - - def down - remove_concurrent_index_by_name :ci_builds, NAME - end -end diff --git a/db/post_migrate/20210621111747_add_ci_artifacts_devops_adoption_index.rb b/db/post_migrate/20210621111747_add_ci_artifacts_devops_adoption_index.rb deleted file mode 100644 index 71fd61072ac..00000000000 --- a/db/post_migrate/20210621111747_add_ci_artifacts_devops_adoption_index.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true -# -class AddCiArtifactsDevopsAdoptionIndex < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - NEW_INDEX = 'index_ci_job_artifacts_on_file_type_for_devops_adoption' - - def up - add_concurrent_index :ci_job_artifacts, [:file_type, :project_id, :created_at], name: NEW_INDEX, where: 'file_type IN (5,6,8,23)' - end - - def down - remove_concurrent_index_by_name :ci_job_artifacts, NEW_INDEX - end -end diff --git a/db/post_migrate/20210621155328_replace_project_authorizations_project_id_index.rb b/db/post_migrate/20210621155328_replace_project_authorizations_project_id_index.rb deleted file mode 100644 index 498090c3ab9..00000000000 --- a/db/post_migrate/20210621155328_replace_project_authorizations_project_id_index.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class ReplaceProjectAuthorizationsProjectIdIndex < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - OLD_INDEX_NAME = 'index_project_authorizations_on_project_id' - NEW_INDEX_NAME = 'index_project_authorizations_on_project_id_user_id' - - def up - add_concurrent_index(:project_authorizations, [:project_id, :user_id], name: NEW_INDEX_NAME) - remove_concurrent_index_by_name(:project_authorizations, OLD_INDEX_NAME) - end - - def down - add_concurrent_index(:project_authorizations, :project_id, name: OLD_INDEX_NAME) - remove_concurrent_index_by_name(:project_authorizations, NEW_INDEX_NAME) - end -end diff --git a/db/post_migrate/20210621164210_drop_remove_on_close_from_labels.rb b/db/post_migrate/20210621164210_drop_remove_on_close_from_labels.rb deleted file mode 100644 index 0430c8447d9..00000000000 --- a/db/post_migrate/20210621164210_drop_remove_on_close_from_labels.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class DropRemoveOnCloseFromLabels < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - def up - # Migration that adds column was reverted, but run in Gitlab SaaS stg and prod - return unless column_exists?(:labels, :remove_on_close) - - with_lock_retries do - remove_column :labels, :remove_on_close - end - end - - def down - # No rollback as the original migration was reverted in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62056 - # up simply removes the column from envs where the original migration was run - end -end diff --git a/db/post_migrate/20210621223000_steal_background_jobs_that_reference_services.rb b/db/post_migrate/20210621223000_steal_background_jobs_that_reference_services.rb deleted file mode 100644 index 8d326036a68..00000000000 --- a/db/post_migrate/20210621223000_steal_background_jobs_that_reference_services.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class StealBackgroundJobsThatReferenceServices < ActiveRecord::Migration[6.1] - def up - Gitlab::BackgroundMigration.steal('BackfillJiraTrackerDeploymentType2') - Gitlab::BackgroundMigration.steal('FixProjectsWithoutPrometheusService') - Gitlab::BackgroundMigration.steal('MigrateIssueTrackersSensitiveData') - Gitlab::BackgroundMigration.steal('RemoveDuplicateServices') - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210621223242_finalize_rename_services_to_integrations.rb b/db/post_migrate/20210621223242_finalize_rename_services_to_integrations.rb deleted file mode 100644 index 803a6fa0aca..00000000000 --- a/db/post_migrate/20210621223242_finalize_rename_services_to_integrations.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class FinalizeRenameServicesToIntegrations < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - finalize_table_rename(:services, :integrations) - end - - def down - undo_finalize_table_rename(:services, :integrations) - end -end diff --git a/db/post_migrate/20210622041846_finalize_push_event_payloads_bigint_conversion.rb b/db/post_migrate/20210622041846_finalize_push_event_payloads_bigint_conversion.rb deleted file mode 100644 index f37c446f66c..00000000000 --- a/db/post_migrate/20210622041846_finalize_push_event_payloads_bigint_conversion.rb +++ /dev/null @@ -1,75 +0,0 @@ -# frozen_string_literal: true - -class FinalizePushEventPayloadsBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'push_event_payloads' - INDEX_NAME = 'index_push_event_payloads_on_event_id_convert_to_bigint' - - def up - return unless should_run? - - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'event_id', - job_arguments: [["event_id"], ["event_id_convert_to_bigint"]] - ) - - swap_columns - end - - def down - return unless should_run? - - swap_columns - end - - private - - def should_run? - Gitlab.dev_or_test_env? || Gitlab.com? - end - - def swap_columns - add_concurrent_index TABLE_NAME, :event_id_convert_to_bigint, unique: true, name: INDEX_NAME - - # Add a foreign key on `event_id_convert_to_bigint` before we swap the columns and drop the old FK (fk_36c74129da) - add_concurrent_foreign_key TABLE_NAME, :events, column: :event_id_convert_to_bigint, on_delete: :cascade - - with_lock_retries(raise_on_exhaustion: true) do - # Swap column names - temp_name = 'event_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:event_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:event_id_convert_to_bigint)} TO #{quote_column_name(:event_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:event_id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:event_id, :event_id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - change_column_default TABLE_NAME, :event_id, nil - change_column_default TABLE_NAME, :event_id_convert_to_bigint, 0 - - # Swap PK constraint - execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT push_event_payloads_pkey" - rename_index TABLE_NAME, INDEX_NAME, 'push_event_payloads_pkey' - execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT push_event_payloads_pkey PRIMARY KEY USING INDEX push_event_payloads_pkey" - - # Drop original FK on the old int4 `event_id` (fk_36c74129da) - remove_foreign_key TABLE_NAME, name: concurrent_foreign_key_name(TABLE_NAME, :event_id) - # We swapped the columns but the FK for event_id is still using the old name for the event_id_convert_to_bigint column - # So we have to also swap the FK name now that we dropped the other one with the same - rename_constraint( - TABLE_NAME, - concurrent_foreign_key_name(TABLE_NAME, :event_id_convert_to_bigint), - concurrent_foreign_key_name(TABLE_NAME, :event_id) - ) - end - end -end diff --git a/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb b/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb deleted file mode 100644 index 1f0bdfc5012..00000000000 --- a/db/post_migrate/20210622045705_finalize_events_bigint_conversion.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -class FinalizeEventsBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'events' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [["id"], ["id_convert_to_bigint"]] - ) - - swap - end - - def down - swap - end - - private - - def swap - # This is to replace the existing "events_pkey" PRIMARY KEY, btree (id) - add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: 'index_events_on_id_convert_to_bigint' - # This is to replace the existing "index_events_on_project_id_and_id" btree (project_id, id) - add_concurrent_index TABLE_NAME, [:project_id, :id_convert_to_bigint], name: 'index_events_on_project_id_and_id_convert_to_bigint' - # This is to replace the existing "index_events_on_project_id_and_id_desc_on_merged_action" btree (project_id, id DESC) WHERE action = 7 - add_concurrent_index TABLE_NAME, [:project_id, :id_convert_to_bigint], order: { id_convert_to_bigint: :desc }, - where: "action = 7", name: 'index_events_on_project_id_and_id_bigint_desc_on_merged_action' - - # Add a FK on `push_event_payloads(event_id)` to `id_convert_to_bigint`, the old FK (fk_36c74129da) - # will be removed when events_pkey constraint is droppped. - fk_event_id = concurrent_foreign_key_name(:push_event_payloads, :event_id) - fk_event_id_tmp = "#{fk_event_id}_tmp" - add_concurrent_foreign_key :push_event_payloads, TABLE_NAME, - column: :event_id, target_column: :id_convert_to_bigint, - name: fk_event_id_tmp, on_delete: :cascade, reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start. - # Lock order should be - # 1. events - # 2. push_event_payloads - # in order to match the order in EventCreateService#create_push_event, - # and avoid deadlocks. - execute "LOCK TABLE #{TABLE_NAME}, push_event_payloads IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id_convert_to_bigint)} TO #{quote_column_name(:id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:id, :id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - execute "ALTER SEQUENCE events_id_seq OWNED BY #{TABLE_NAME}.id" - change_column_default TABLE_NAME, :id, -> { "nextval('events_id_seq'::regclass)" } - change_column_default TABLE_NAME, :id_convert_to_bigint, 0 - - # Swap PK constraint - execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT events_pkey CASCADE" # this will drop fk_36c74129da - rename_index TABLE_NAME, 'index_events_on_id_convert_to_bigint', 'events_pkey' - execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT events_pkey PRIMARY KEY USING INDEX events_pkey" - - # Rename the rest of the indexes (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here - execute 'DROP INDEX index_events_on_project_id_and_id' - rename_index TABLE_NAME, 'index_events_on_project_id_and_id_convert_to_bigint', 'index_events_on_project_id_and_id' - execute 'DROP INDEX index_events_on_project_id_and_id_desc_on_merged_action' - rename_index TABLE_NAME, 'index_events_on_project_id_and_id_bigint_desc_on_merged_action', 'index_events_on_project_id_and_id_desc_on_merged_action' - - # Change the name of the temporary FK - rename_constraint(:push_event_payloads, fk_event_id_tmp, fk_event_id) - end - end -end diff --git a/db/post_migrate/20210622141148_schedule_delete_orphaned_deployments.rb b/db/post_migrate/20210622141148_schedule_delete_orphaned_deployments.rb deleted file mode 100644 index a38cb68ff08..00000000000 --- a/db/post_migrate/20210622141148_schedule_delete_orphaned_deployments.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class ScheduleDeleteOrphanedDeployments < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'DeleteOrphanedDeployments' - BATCH_SIZE = 100_000 - DELAY_INTERVAL = 2.minutes - - disable_ddl_transaction! - - def up - # no-op. - # This background migration is rescheduled in 20210722010101_cleanup_delete_orphaned_deployments_background_migration.rb - # with a smaller batch size, because the initial attempt caused - # 80 failures out of 1639 batches (faiulre rate is 4.88%) due to statement timeouts, - # that takes approx. 1 hour to perform a cleanup/sync migration. - # See https://gitlab.com/gitlab-org/gitlab/-/issues/335071#note_618380503 for more information. - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210628124505_reset_job_token_scope_enabled.rb b/db/post_migrate/20210628124505_reset_job_token_scope_enabled.rb deleted file mode 100644 index 1176e704d0a..00000000000 --- a/db/post_migrate/20210628124505_reset_job_token_scope_enabled.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class ResetJobTokenScopeEnabled < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - with_lock_retries do - remove_column :project_ci_cd_settings, :job_token_scope_enabled - add_column :project_ci_cd_settings, :job_token_scope_enabled, :boolean, default: false, null: false - end - end - - def down - # Irreversible - end -end diff --git a/db/post_migrate/20210629101712_remove_deprecated_modsecurity_columns.rb b/db/post_migrate/20210629101712_remove_deprecated_modsecurity_columns.rb deleted file mode 100644 index 371298aef62..00000000000 --- a/db/post_migrate/20210629101712_remove_deprecated_modsecurity_columns.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class RemoveDeprecatedModsecurityColumns < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - INDEX_NAME = 'index_clusters_applications_ingress_on_modsecurity' - - def up - remove_column :clusters_applications_ingress, :modsecurity_enabled if column_exists?(:clusters_applications_ingress, :modsecurity_enabled) - remove_column :clusters_applications_ingress, :modsecurity_mode if column_exists?(:clusters_applications_ingress, :modsecurity_mode) - end - - def down - add_column :clusters_applications_ingress, :modsecurity_enabled, :boolean unless column_exists?(:clusters_applications_ingress, :modsecurity_enabled) - add_column :clusters_applications_ingress, :modsecurity_mode, :smallint, null: false, default: 0 unless column_exists?(:clusters_applications_ingress, :modsecurity_mode) - - add_concurrent_index :clusters_applications_ingress, [:modsecurity_enabled, :modsecurity_mode, :cluster_id], name: INDEX_NAME - end -end diff --git a/db/post_migrate/20210629104933_drop_index_on_ci_builds_for_token.rb b/db/post_migrate/20210629104933_drop_index_on_ci_builds_for_token.rb deleted file mode 100644 index cc26db924fe..00000000000 --- a/db/post_migrate/20210629104933_drop_index_on_ci_builds_for_token.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class DropIndexOnCiBuildsForToken < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - INDEXNAME = :index_ci_builds_on_token - - def up - remove_concurrent_index_by_name :ci_builds, INDEXNAME - end - - def down - add_concurrent_index :ci_builds, :token, unique: true, name: INDEXNAME - end -end diff --git a/db/post_migrate/20210630025020_migrate_push_event_payloads_event_id_back_to_integer_for_gitlab_com.rb b/db/post_migrate/20210630025020_migrate_push_event_payloads_event_id_back_to_integer_for_gitlab_com.rb deleted file mode 100644 index 834a23a5c7a..00000000000 --- a/db/post_migrate/20210630025020_migrate_push_event_payloads_event_id_back_to_integer_for_gitlab_com.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require Rails.root.join('db', 'post_migrate', '20210622041846_finalize_push_event_payloads_bigint_conversion') - -class MigratePushEventPayloadsEventIdBackToIntegerForGitlabCom < ActiveRecord::Migration[6.1] - disable_ddl_transaction! - - def up - FinalizePushEventPayloadsBigintConversion.new.down - end - - def down - FinalizePushEventPayloadsBigintConversion.new.up - end -end diff --git a/db/post_migrate/20210701033622_finalize_ci_builds_needs_bigint_conversion.rb b/db/post_migrate/20210701033622_finalize_ci_builds_needs_bigint_conversion.rb deleted file mode 100644 index 89a39660a04..00000000000 --- a/db/post_migrate/20210701033622_finalize_ci_builds_needs_bigint_conversion.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -class FinalizeCiBuildsNeedsBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_build_needs' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [['build_id'], ['build_id_convert_to_bigint']] - ) - - swap - end - - def down - swap - end - - private - - def swap - # This is to replace the existing "index_ci_build_needs_on_build_id_and_name" UNIQUE, btree (build_id, name) - add_concurrent_index TABLE_NAME, [:build_id_convert_to_bigint, :name], unique: true, name: 'index_ci_build_needs_on_build_id_convert_to_bigint_and_name' - - # Add a foreign key on `build_id_convert_to_bigint` before we swap the columns and drop the old FK (fk_rails_3cf221d4ed) - add_concurrent_foreign_key TABLE_NAME, :ci_builds, - column: :build_id_convert_to_bigint, on_delete: :cascade, - name: 'fk_rails_3cf221d4ed_tmp', reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start - execute "LOCK TABLE ci_builds, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'build_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:build_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:build_id_convert_to_bigint)} TO #{quote_column_name(:build_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:build_id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - change_column_default TABLE_NAME, :build_id, nil - change_column_default TABLE_NAME, :build_id_convert_to_bigint, 0 - - # Rename the index on the `bigint` column to match the new column name - # (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here) - execute 'DROP INDEX index_ci_build_needs_on_build_id_and_name' - rename_index TABLE_NAME, 'index_ci_build_needs_on_build_id_convert_to_bigint_and_name', 'index_ci_build_needs_on_build_id_and_name' - - # Drop original FK on the old int4 `build_id` (fk_rails_3cf221d4ed) - remove_foreign_key TABLE_NAME, name: 'fk_rails_3cf221d4ed' - # We swapped the columns but the FK for buil_id is still using the temporary name for the buil_id_convert_to_bigint column - # So we have to also swap the FK name now that we dropped the other one with the same - rename_constraint(TABLE_NAME, 'fk_rails_3cf221d4ed_tmp', 'fk_rails_3cf221d4ed') - end - end -end diff --git a/db/post_migrate/20210701111909_backfill_issues_upvotes_count.rb b/db/post_migrate/20210701111909_backfill_issues_upvotes_count.rb deleted file mode 100644 index 0afc0bc1d08..00000000000 --- a/db/post_migrate/20210701111909_backfill_issues_upvotes_count.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class BackfillIssuesUpvotesCount < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - MIGRATION = 'BackfillUpvotesCountOnIssues' - DELAY_INTERVAL = 2.minutes - BATCH_SIZE = 5_000 - - def up - scope = Issue.joins("INNER JOIN award_emoji e ON e.awardable_id = issues.id AND e.awardable_type = 'Issue' AND e.name = 'thumbsup'") - - queue_background_migration_jobs_by_range_at_intervals( - scope, - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb b/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb deleted file mode 100644 index 776f1ad545d..00000000000 --- a/db/post_migrate/20210701141346_finalize_ci_builds_stage_id_bigint_conversion.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true - -class FinalizeCiBuildsStageIdBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_builds' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [%w[id stage_id], %w[id_convert_to_bigint stage_id_convert_to_bigint]] - ) - - swap_columns - end - - def down - swap_columns - end - - private - - def swap_columns - # Create a copy of the original column's index on the new column - add_concurrent_index TABLE_NAME, :stage_id_convert_to_bigint, name: :index_ci_builds_on_converted_stage_id # rubocop:disable Migration/PreventIndexCreation - - # Create a copy of the original column's FK on the new column - add_concurrent_foreign_key TABLE_NAME, :ci_stages, column: :stage_id_convert_to_bigint, on_delete: :cascade, - reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - quoted_table_name = quote_table_name(TABLE_NAME) - quoted_referenced_table_name = quote_table_name(:ci_stages) - - # Acquire locks up-front, not just to the build table but the FK's referenced table - execute "LOCK TABLE #{quoted_referenced_table_name}, #{quoted_table_name} IN ACCESS EXCLUSIVE MODE" - - # Swap the column names of the two columns - temporary_name = 'stage_id_tmp' - execute "ALTER TABLE #{quoted_table_name} RENAME COLUMN #{quote_column_name(:stage_id)} TO #{quote_column_name(temporary_name)}" - execute "ALTER TABLE #{quoted_table_name} RENAME COLUMN #{quote_column_name(:stage_id_convert_to_bigint)} TO #{quote_column_name(:stage_id)}" - execute "ALTER TABLE #{quoted_table_name} RENAME COLUMN #{quote_column_name(temporary_name)} TO #{quote_column_name(:stage_id_convert_to_bigint)}" - - # Reset the function so PG drops the plan cache for the incorrect integer type - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection) - .name([:id, :stage_id], [:id_convert_to_bigint, :stage_id_convert_to_bigint]) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Remove the original column index, and rename the new column index to the original name - execute 'DROP INDEX index_ci_builds_on_stage_id' - rename_index TABLE_NAME, :index_ci_builds_on_converted_stage_id, :index_ci_builds_on_stage_id - - # Remove the original column foreign key, and rename the new column foreign key to the original name - remove_foreign_key TABLE_NAME, name: concurrent_foreign_key_name(TABLE_NAME, :stage_id) - rename_constraint( - TABLE_NAME, - concurrent_foreign_key_name(TABLE_NAME, :stage_id_convert_to_bigint), - concurrent_foreign_key_name(TABLE_NAME, :stage_id)) - end - end -end diff --git a/db/post_migrate/20210705143150_backfill_ci_builds_metadata_id_for_bigint_conversion.rb b/db/post_migrate/20210705143150_backfill_ci_builds_metadata_id_for_bigint_conversion.rb deleted file mode 100644 index a9f6d4ea2d9..00000000000 --- a/db/post_migrate/20210705143150_backfill_ci_builds_metadata_id_for_bigint_conversion.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class BackfillCiBuildsMetadataIdForBigintConversion < ActiveRecord::Migration[6.1] - disable_ddl_transaction! - - include Gitlab::Database::MigrationHelpers - - TABLE = :ci_builds_metadata - COLUMN = :id - - def up - backfill_conversion_of_integer_to_bigint TABLE, COLUMN, batch_size: 15000, sub_batch_size: 100 - end - - def down - revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMN - end -end diff --git a/db/post_migrate/20210706112800_remove_cloud_license_enabled_from_application_settings.rb b/db/post_migrate/20210706112800_remove_cloud_license_enabled_from_application_settings.rb deleted file mode 100644 index 7224e84c1b3..00000000000 --- a/db/post_migrate/20210706112800_remove_cloud_license_enabled_from_application_settings.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveCloudLicenseEnabledFromApplicationSettings < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - with_lock_retries do - remove_column :application_settings, :cloud_license_enabled - end - end - - def down - with_lock_retries do - add_column :application_settings, :cloud_license_enabled, :boolean, null: false, default: false - end - end -end diff --git a/db/post_migrate/20210706115312_add_upvotes_count_index_to_issues.rb b/db/post_migrate/20210706115312_add_upvotes_count_index_to_issues.rb deleted file mode 100644 index 65ec43930ea..00000000000 --- a/db/post_migrate/20210706115312_add_upvotes_count_index_to_issues.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddUpvotesCountIndexToIssues < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - INDEX_NAME = 'index_issues_on_project_id_and_upvotes_count' - - def up - add_concurrent_index :issues, [:project_id, :upvotes_count], name: INDEX_NAME - end - - def down - remove_concurrent_index :issues, [:project_id, :upvotes_count], name: INDEX_NAME - end -end diff --git a/db/post_migrate/20210706120847_remove_framework_column_from_compliance_management_frameworks.rb b/db/post_migrate/20210706120847_remove_framework_column_from_compliance_management_frameworks.rb deleted file mode 100644 index 73344ee061f..00000000000 --- a/db/post_migrate/20210706120847_remove_framework_column_from_compliance_management_frameworks.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class RemoveFrameworkColumnFromComplianceManagementFrameworks < ActiveRecord::Migration[6.1] - def change - remove_column :project_compliance_framework_settings, :framework, :smallint - end -end diff --git a/db/post_migrate/20210706142819_re_schedule_latest_pipeline_id_population.rb b/db/post_migrate/20210706142819_re_schedule_latest_pipeline_id_population.rb deleted file mode 100644 index 255b64f9bc7..00000000000 --- a/db/post_migrate/20210706142819_re_schedule_latest_pipeline_id_population.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class ReScheduleLatestPipelineIdPopulation < ActiveRecord::Migration[6.1] - def change - # no-op: This migration has been marked as no-op and replaced by - # `ReScheduleLatestPipelineIdPopulationWithLogging` as we've found some problems. - # For more information: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66050 - end -end diff --git a/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb b/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb deleted file mode 100644 index 11045348672..00000000000 --- a/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true - -# See https://docs.gitlab.com/ee/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class FinalizeCiJobArtifactsBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_job_artifacts' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]] - ) - - swap - end - - def down - swap - end - - private - - def swap - add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: 'index_ci_job_artifact_on_id_convert_to_bigint' - # This is to replace the existing "index_ci_job_artifacts_for_terraform_reports" btree (project_id, id) where (file_type = 18) - add_concurrent_index TABLE_NAME, [:project_id, :id_convert_to_bigint], name: 'index_ci_job_artifacts_for_terraform_reports_bigint', where: "file_type = 18" - # This is to replace the existing "index_ci_job_artifacts_id_for_terraform_reports" btree (id) where (file_type = 18) - add_concurrent_index TABLE_NAME, [:id_convert_to_bigint], name: 'index_ci_job_artifacts_id_for_terraform_reports_bigint', where: "file_type = 18" - - # Add a FK on `project_pages_metadata(artifacts_archive_id)` to `id_convert_to_bigint`, the old FK (fk_69366a119e) - # will be removed when ci_job_artifacts_pkey constraint is droppped. - fk_artifacts_archive_id = concurrent_foreign_key_name(:project_pages_metadata, :artifacts_archive_id) - fk_artifacts_archive_id_tmp = "#{fk_artifacts_archive_id}_tmp" - add_concurrent_foreign_key :project_pages_metadata, TABLE_NAME, - column: :artifacts_archive_id, target_column: :id_convert_to_bigint, - name: fk_artifacts_archive_id_tmp, - on_delete: :nullify, - reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start - execute "LOCK TABLE #{TABLE_NAME}, project_pages_metadata IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id_convert_to_bigint)} TO #{quote_column_name(:id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name([:id, :job_id], [:id_convert_to_bigint, :job_id_convert_to_bigint]) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - execute "ALTER SEQUENCE ci_job_artifacts_id_seq OWNED BY #{TABLE_NAME}.id" - change_column_default TABLE_NAME, :id, -> { "nextval('ci_job_artifacts_id_seq'::regclass)" } - change_column_default TABLE_NAME, :id_convert_to_bigint, 0 - - # Swap PK constraint - execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT ci_job_artifacts_pkey CASCADE" # this will drop ci_job_artifacts_pkey primary key - rename_index TABLE_NAME, 'index_ci_job_artifact_on_id_convert_to_bigint', 'ci_job_artifacts_pkey' - execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT ci_job_artifacts_pkey PRIMARY KEY USING INDEX ci_job_artifacts_pkey" - - # Rename the rest of the indexes (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here - execute 'DROP INDEX index_ci_job_artifacts_for_terraform_reports' - rename_index TABLE_NAME, 'index_ci_job_artifacts_for_terraform_reports_bigint', 'index_ci_job_artifacts_for_terraform_reports' - execute 'DROP INDEX index_ci_job_artifacts_id_for_terraform_reports' - rename_index TABLE_NAME, 'index_ci_job_artifacts_id_for_terraform_reports_bigint', 'index_ci_job_artifacts_id_for_terraform_reports' - - # Change the name of the temporary FK for project_pages_metadata(artifacts_archive_id) -> id - rename_constraint(:project_pages_metadata, fk_artifacts_archive_id_tmp, fk_artifacts_archive_id) - end - end -end diff --git a/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb b/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb deleted file mode 100644 index f3ce32ad9c8..00000000000 --- a/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -# See https://docs.gitlab.com/ee/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class FinalizeCiStagesBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - TABLE_NAME = 'ci_stages' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [['id'], ['id_convert_to_bigint']] - ) - - swap - end - - def down - swap - end - - def swap - # This will replace the existing ci_stages_pkey index for the primary key - add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: 'index_ci_stages_on_id_convert_to_bigint' - - # This will replace the existing ci_stages_on_pipeline_id_and_id index - add_concurrent_index TABLE_NAME, [:pipeline_id, :id_convert_to_bigint], - name: 'index_ci_stages_on_pipeline_id_and_id_convert_to_bigint', - where: 'status in (0, 1, 2, 8, 9, 10)' - - # Add a foreign key on ci_builds(stage_id_convert_to_bigint), which we'll rename later. Give it the correct final name - fk_stage_id = concurrent_foreign_key_name(:ci_builds, :stage_id) - fk_stage_id_tmp = "#{fk_stage_id}_tmp" - add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, - target_column: :id_convert_to_bigint, - name: fk_stage_id_tmp, - on_delete: :cascade, - reverse_lock_order: true - - # Now it's time to do things in a transaction - with_lock_retries(raise_on_exhaustion: true) do - execute "LOCK TABLE #{TABLE_NAME}, ci_builds IN ACCESS EXCLUSIVE MODE" - - temp_name = quote_column_name('id_tmp') - id_name = quote_column_name(:id) - id_convert_to_bigint_name = quote_column_name(:id_convert_to_bigint) - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_name} TO #{temp_name}" - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_convert_to_bigint_name} TO #{id_name}" - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{temp_name} TO #{id_convert_to_bigint_name}" - - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:id, :id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - execute "ALTER SEQUENCE ci_stages_id_seq OWNED BY #{TABLE_NAME}.id" - change_column_default TABLE_NAME, :id, -> { "nextval('ci_stages_id_seq'::regclass)" } - change_column_default TABLE_NAME, :id_convert_to_bigint, 0 - - # Swap pkey constraint - # This will drop fk_3a9eaa254d (ci_builds(stage_id) references ci_stages(id)) - execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT ci_stages_pkey CASCADE" - rename_index TABLE_NAME, 'index_ci_stages_on_id_convert_to_bigint', 'ci_stages_pkey' - execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT ci_stages_pkey PRIMARY KEY USING INDEX ci_stages_pkey" - - # Rename the other indexes - execute "DROP INDEX index_ci_stages_on_pipeline_id_and_id" - rename_index TABLE_NAME, 'index_ci_stages_on_pipeline_id_and_id_convert_to_bigint', 'index_ci_stages_on_pipeline_id_and_id' - - rename_constraint(:ci_builds, fk_stage_id_tmp, fk_stage_id) - end - end -end diff --git a/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb b/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb deleted file mode 100644 index 3879c3c368a..00000000000 --- a/db/post_migrate/20210708011426_finalize_ci_builds_metadata_bigint_conversion.rb +++ /dev/null @@ -1,113 +0,0 @@ -# frozen_string_literal: true - -class FinalizeCiBuildsMetadataBigintConversion < Gitlab::Database::Migration[1.0] - disable_ddl_transaction! - - TABLE_NAME = 'ci_builds_metadata' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [["id"], ["id_convert_to_bigint"]] - ) - - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [["build_id"], ["build_id_convert_to_bigint"]] - ) - - swap - end - - def down - swap - end - - private - - def swap - # Indexes were pre-created on gitlab.com to avoid slowing down deployments - # - # rubocop:disable Migration/PreventIndexCreation - add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: 'index_ci_builds_metadata_on_id_convert_to_bigint' - add_concurrent_index TABLE_NAME, :build_id_convert_to_bigint, where: 'has_exposed_artifacts IS TRUE', name: 'index_ci_builds_metadata_on_build_id_int8_and_exposed_artifacts' - create_covering_index TABLE_NAME, 'index_ci_builds_metadata_on_build_id_int8_where_interruptible' - add_concurrent_index TABLE_NAME, :build_id_convert_to_bigint, unique: true, name: 'index_ci_builds_metadata_on_build_id_convert_to_bigint' - # rubocop:enable Migration/PreventIndexCreation - - add_concurrent_foreign_key TABLE_NAME, :ci_builds, column: :build_id_convert_to_bigint, on_delete: :cascade, - reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - execute "LOCK TABLE ci_builds, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" - - # rubocop:disable Migration/WithLockRetriesDisallowedMethod - swap_column :id - swap_column :build_id - # rubocop:enable Migration/WithLockRetriesDisallowedMethod - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - execute "ALTER FUNCTION #{quote_table_name(Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:id, :id_convert_to_bigint))} RESET ALL" - execute "ALTER FUNCTION #{quote_table_name(Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint))} RESET ALL" - - # Swap defaults for PK - execute "ALTER SEQUENCE ci_builds_metadata_id_seq OWNED BY #{TABLE_NAME}.id" - change_column_default TABLE_NAME, :id, -> { "nextval('ci_builds_metadata_id_seq'::regclass)" } - change_column_default TABLE_NAME, :id_convert_to_bigint, 0 - - # Swap defaults for FK - change_column_default TABLE_NAME, :build_id, nil - change_column_default TABLE_NAME, :build_id_convert_to_bigint, 0 - - # Swap PK constraint - execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT ci_builds_metadata_pkey CASCADE" - rename_index TABLE_NAME, 'index_ci_builds_metadata_on_id_convert_to_bigint', 'ci_builds_metadata_pkey' - execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT ci_builds_metadata_pkey PRIMARY KEY USING INDEX ci_builds_metadata_pkey" - - # Rename the rest of the indexes (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here) - # rubocop:disable Migration/WithLockRetriesDisallowedMethod - swap_index 'index_ci_builds_metadata_on_build_id', 'index_ci_builds_metadata_on_build_id_convert_to_bigint' - swap_index 'index_ci_builds_metadata_on_build_id_and_has_exposed_artifacts', 'index_ci_builds_metadata_on_build_id_int8_and_exposed_artifacts' - swap_index 'index_ci_builds_metadata_on_build_id_and_id_and_interruptible', 'index_ci_builds_metadata_on_build_id_int8_where_interruptible' - # rubocop:enable Migration/WithLockRetriesDisallowedMethod - - # Swap FK constraint - remove_foreign_key TABLE_NAME, name: concurrent_foreign_key_name(TABLE_NAME, :build_id) - rename_constraint( - TABLE_NAME, - concurrent_foreign_key_name(TABLE_NAME, :build_id_convert_to_bigint), - concurrent_foreign_key_name(TABLE_NAME, :build_id) - ) - end - end - - def swap_index(old, new) - execute "DROP INDEX #{old}" - rename_index TABLE_NAME, new, old - end - - def swap_column(name) - temp_name = "#{name}_tmp" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(name)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:"#{name}_convert_to_bigint")} TO #{quote_column_name(name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:"#{name}_convert_to_bigint")}" - end - - def create_covering_index(table, name) - return if index_exists_by_name?(table, name) - - disable_statement_timeout do - execute <<~SQL - CREATE INDEX CONCURRENTLY #{name} - ON #{table} (build_id_convert_to_bigint) INCLUDE (id_convert_to_bigint) - WHERE interruptible = true - SQL - end - end -end diff --git a/db/post_migrate/20210708130419_reschedule_merge_request_diff_users_background_migration.rb b/db/post_migrate/20210708130419_reschedule_merge_request_diff_users_background_migration.rb deleted file mode 100644 index 53f13ca96d2..00000000000 --- a/db/post_migrate/20210708130419_reschedule_merge_request_diff_users_background_migration.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -class RescheduleMergeRequestDiffUsersBackgroundMigration < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - # The number of rows to process in a single migration job. - # - # The minimum interval for background migrations is two minutes. On staging we - # observed we can process roughly 20 000 rows in a minute. Based on the total - # number of rows on staging, this translates to a total processing time of - # roughly 14 days. - # - # By using a batch size of 40 000, we maintain a rate of roughly 20 000 rows - # per minute, hopefully keeping the total migration time under two weeks; - # instead of four weeks. - BATCH_SIZE = 40_000 - - MIGRATION_NAME = 'MigrateMergeRequestDiffCommitUsers' - - class MergeRequestDiff < ActiveRecord::Base - self.table_name = 'merge_request_diffs' - end - - def up - start = MergeRequestDiff.minimum(:id).to_i - max = MergeRequestDiff.maximum(:id).to_i - delay = BackgroundMigrationWorker.minimum_interval - - Gitlab::Database::BackgroundMigrationJob - .where(class_name: MIGRATION_NAME) - .delete_all - - # The table merge_request_diff_commits contains _a lot_ of rows (roughly 400 - # 000 000 on staging). Iterating a table that large to determine job ranges - # would take a while. - # - # To avoid that overhead, we simply schedule fixed ranges according to the - # minimum and maximum IDs. The background migration in turn only processes - # rows that actually exist. - while start < max - stop = start + BATCH_SIZE - - migrate_in(delay, MIGRATION_NAME, [start, stop]) - - Gitlab::Database::BackgroundMigrationJob - .create!(class_name: MIGRATION_NAME, arguments: [start, stop]) - - delay += BackgroundMigrationWorker.minimum_interval - start += BATCH_SIZE - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210709024048_finalize_push_event_payloads_bigint_conversion_2.rb b/db/post_migrate/20210709024048_finalize_push_event_payloads_bigint_conversion_2.rb deleted file mode 100644 index aa812151164..00000000000 --- a/db/post_migrate/20210709024048_finalize_push_event_payloads_bigint_conversion_2.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class FinalizePushEventPayloadsBigintConversion2 < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - # no-op due to https://gitlab.com/gitlab-com/gl-infra/production/-/issues/5256 - end - - def down - # no-op due to https://gitlab.com/gitlab-com/gl-infra/production/-/issues/5256 - end -end diff --git a/db/post_migrate/20210713042000_fix_ci_sources_pipelines_index_names.rb b/db/post_migrate/20210713042000_fix_ci_sources_pipelines_index_names.rb deleted file mode 100644 index 34701d8ba46..00000000000 --- a/db/post_migrate/20210713042000_fix_ci_sources_pipelines_index_names.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -# When the `ci_sources_pipelines` table was first introduced in GitLab -# 9.3 EE, the foreign key names generate for the table appeared to -# have been calculated via a hash using the table name -# `ci_pipeline_source_pipelines`. This led to a merge conflict and -# confusion during a CE to EE merge in GitLab 10.0, which regenerated -# the schema with the correct foreign key names. -# -# Hence anyone who installed GitLab prior to 10.0 may have been seeded -# the database with stale, incorrect foreign key names. -# -# During the Great BigInt Conversion of 2021, several migrations -# assumed that the foreign key `fk_be5624bf37` existed for -# `ci_sources_pipeline`. However, older installations may have had the -# correct foreign key under the name `fk_3f0c88d7dc`. -# -# To eliminate future confusion and migration failures, we now rename -# the foreign key constraints and index to what they should be today. -class FixCiSourcesPipelinesIndexNames < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_sources_pipelines' - - # GitLab 9.5.4: https://gitlab.com/gitlab-org/gitlab/-/blob/v9.5.4-ee/db/schema.rb#L2026-2030 - # GitLab 10.0: https://gitlab.com/gitlab-org/gitlab/-/blob/v10.0.0-ee/db/schema.rb#L2064-2068 - OLD_TO_NEW_FOREIGN_KEY_DEFS = { - 'fk_3f0c88d7dc' => { table: :ci_builds, column: :source_job_id, name: 'fk_be5624bf37' }, - 'fk_b8c0fac459' => { table: :ci_pipelines, column: :pipeline_id, name: 'fk_e1bad85861' }, - 'fk_3a3e3cb83a' => { table: :ci_pipelines, column: :source_pipeline_id, name: 'fk_d4e29af7d7' }, - 'fk_8868d0f3e4' => { table: :projects, column: :source_project_id, name: 'fk_acd9737679' }, - 'fk_83b4346e48' => { table: :projects, name: 'fk_1e53c97c0a' } - } - OLD_INDEX_NAME = 'index_ci_pipeline_source_pipelines_on_source_job_id' - NEW_INDEX_NAME = 'index_ci_sources_pipelines_on_source_job_id' - - def up - OLD_TO_NEW_FOREIGN_KEY_DEFS.each do |old_name, entry| - options = { column: entry[:column], name: old_name }.compact - - if foreign_key_exists?(TABLE_NAME, entry[:table], **options) - rename_constraint(TABLE_NAME, old_name, entry[:name]) - end - end - - if index_exists_by_name?(TABLE_NAME, OLD_INDEX_NAME) - if index_exists_by_name?(TABLE_NAME, NEW_INDEX_NAME) - remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME) - else - rename_index(TABLE_NAME, OLD_INDEX_NAME, NEW_INDEX_NAME) - end - end - end - - # There's no reason to revert this change since it should apply on stale schemas - def down; end -end diff --git a/db/post_migrate/20210713042153_finalize_ci_sources_pipelines_bigint_conversion.rb b/db/post_migrate/20210713042153_finalize_ci_sources_pipelines_bigint_conversion.rb deleted file mode 100644 index 38b7852b320..00000000000 --- a/db/post_migrate/20210713042153_finalize_ci_sources_pipelines_bigint_conversion.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -class FinalizeCiSourcesPipelinesBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_sources_pipelines' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [['source_job_id'], ['source_job_id_convert_to_bigint']] - ) - - swap - end - - def down - swap - end - - private - - def swap - # This is to replace the existing "index_ci_sources_pipelines_on_source_job_id" btree (source_job_id) - add_concurrent_index TABLE_NAME, :source_job_id_convert_to_bigint, name: 'index_ci_sources_pipelines_on_source_job_id_convert_to_bigint' - - # Add a foreign key on `source_job_id_convert_to_bigint` before we swap the columns and drop the old FK (fk_be5624bf37) - add_concurrent_foreign_key TABLE_NAME, :ci_builds, - column: :source_job_id_convert_to_bigint, on_delete: :cascade, - name: 'fk_be5624bf37_tmp', reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start - execute "LOCK TABLE ci_builds, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'source_job_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:source_job_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:source_job_id_convert_to_bigint)} TO #{quote_column_name(:source_job_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:source_job_id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:source_job_id, :source_job_id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # No need to swap defaults, both columns have no default value - - # Rename the index on the `bigint` column to match the new column name - # (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here) - execute 'DROP INDEX index_ci_sources_pipelines_on_source_job_id' - rename_index TABLE_NAME, 'index_ci_sources_pipelines_on_source_job_id_convert_to_bigint', 'index_ci_sources_pipelines_on_source_job_id' - - # Drop original FK on the old int4 `source_job_id` (fk_be5624bf37) - remove_foreign_key TABLE_NAME, name: 'fk_be5624bf37' - # We swapped the columns but the FK is still using the temporary name - # So we have to also swap the FK name now that we dropped the other one - rename_constraint(TABLE_NAME, 'fk_be5624bf37_tmp', 'fk_be5624bf37') - end - end -end diff --git a/db/post_migrate/20210713075117_re_schedule_latest_pipeline_id_population_with_logging.rb b/db/post_migrate/20210713075117_re_schedule_latest_pipeline_id_population_with_logging.rb deleted file mode 100644 index 457e7826f38..00000000000 --- a/db/post_migrate/20210713075117_re_schedule_latest_pipeline_id_population_with_logging.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class ReScheduleLatestPipelineIdPopulationWithLogging < ActiveRecord::Migration[6.1] - def up - # no-op: The content of the migration has been moved to - # `ReScheduleLatestPipelineIdPopulationWithAllSecurityRelatedArtifactTypes`. - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210714015537_finalize_ci_build_trace_chunks_bigint_conversion.rb b/db/post_migrate/20210714015537_finalize_ci_build_trace_chunks_bigint_conversion.rb deleted file mode 100644 index af17b35d47d..00000000000 --- a/db/post_migrate/20210714015537_finalize_ci_build_trace_chunks_bigint_conversion.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -class FinalizeCiBuildTraceChunksBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_build_trace_chunks' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [['build_id'], ['build_id_convert_to_bigint']] - ) - - swap - end - - def down - swap - end - - private - - def swap - # This is to replace the existing "index_ci_build_trace_chunks_on_build_id_and_chunk_index" UNIQUE, btree (build_id, chunk_index) - add_concurrent_index TABLE_NAME, [:build_id_convert_to_bigint, :chunk_index], unique: true, name: 'i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index' - - # Add a foreign key on `build_id_convert_to_bigint` before we swap the columns and drop the old FK () - add_concurrent_foreign_key TABLE_NAME, :ci_builds, column: :build_id_convert_to_bigint, on_delete: :cascade, name: 'fk_rails_1013b761f2_tmp' - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start - execute "LOCK TABLE #{TABLE_NAME}, ci_builds IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'build_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:build_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:build_id_convert_to_bigint)} TO #{quote_column_name(:build_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:build_id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - change_column_default TABLE_NAME, :build_id, nil - change_column_default TABLE_NAME, :build_id_convert_to_bigint, 0 - - # Rename the index on the `bigint` column to match the new column name - # (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here) - execute 'DROP INDEX index_ci_build_trace_chunks_on_build_id_and_chunk_index' - rename_index TABLE_NAME, 'i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index', 'index_ci_build_trace_chunks_on_build_id_and_chunk_index' - - # Drop original FK on the old int4 `build_id` (fk_rails_1013b761f2) - remove_foreign_key TABLE_NAME, name: 'fk_rails_1013b761f2' - # We swapped the columns but the FK for buil_id is still using the temporary name for the build_id_convert_to_bigint column - # So we have to also swap the FK name now that we dropped the other one with the same - rename_constraint(TABLE_NAME, 'fk_rails_1013b761f2_tmp', 'fk_rails_1013b761f2') - end - end -end diff --git a/db/post_migrate/20210721122840_remove_seat_link_enabled_from_application_settings.rb b/db/post_migrate/20210721122840_remove_seat_link_enabled_from_application_settings.rb deleted file mode 100644 index 20118dbbac8..00000000000 --- a/db/post_migrate/20210721122840_remove_seat_link_enabled_from_application_settings.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class RemoveSeatLinkEnabledFromApplicationSettings < ActiveRecord::Migration[6.1] - def up - remove_column :application_settings, :seat_link_enabled - end - - def down - add_column :application_settings, :seat_link_enabled, :boolean, null: false, default: true - end -end diff --git a/db/post_migrate/20210721125804_remove_signing_keys_from_packages_debian_project_distributions.rb b/db/post_migrate/20210721125804_remove_signing_keys_from_packages_debian_project_distributions.rb deleted file mode 100644 index 076a238381e..00000000000 --- a/db/post_migrate/20210721125804_remove_signing_keys_from_packages_debian_project_distributions.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class RemoveSigningKeysFromPackagesDebianProjectDistributions < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def change - remove_column :packages_debian_project_distributions, :encrypted_signing_keys, :text - remove_column :packages_debian_project_distributions, :encrypted_signing_keys_iv, :text - end -end diff --git a/db/post_migrate/20210721125820_remove_signing_keys_from_packages_debian_group_distributions.rb b/db/post_migrate/20210721125820_remove_signing_keys_from_packages_debian_group_distributions.rb deleted file mode 100644 index 4b751c06972..00000000000 --- a/db/post_migrate/20210721125820_remove_signing_keys_from_packages_debian_group_distributions.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class RemoveSigningKeysFromPackagesDebianGroupDistributions < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def change - remove_column :packages_debian_group_distributions, :encrypted_signing_keys, :text - remove_column :packages_debian_group_distributions, :encrypted_signing_keys_iv, :text - end -end diff --git a/db/post_migrate/20210721174521_add_non_null_constraint_for_escalation_rule_on_pending_alert_escalations.rb b/db/post_migrate/20210721174521_add_non_null_constraint_for_escalation_rule_on_pending_alert_escalations.rb deleted file mode 100644 index 5d42fd4896d..00000000000 --- a/db/post_migrate/20210721174521_add_non_null_constraint_for_escalation_rule_on_pending_alert_escalations.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -class AddNonNullConstraintForEscalationRuleOnPendingAlertEscalations < ActiveRecord::Migration[6.1] - ELAPSED_WHOLE_MINUTES_IN_SECONDS = <<~SQL - ABS(ROUND( - EXTRACT(EPOCH FROM (escalations.process_at - escalations.created_at))/60*60 - )) - SQL - - INSERT_RULES_FOR_ESCALATIONS_WITHOUT_RULES = <<~SQL - INSERT INTO incident_management_escalation_rules (policy_id, oncall_schedule_id, status, elapsed_time_seconds, is_removed) - SELECT - policies.id, - schedule_id, - status, - #{ELAPSED_WHOLE_MINUTES_IN_SECONDS} AS elapsed_time_seconds, - TRUE - FROM incident_management_pending_alert_escalations AS escalations - INNER JOIN incident_management_oncall_schedules AS schedules ON schedules.id = schedule_id - INNER JOIN incident_management_escalation_policies AS policies ON policies.project_id = schedules.project_id - WHERE rule_id IS NULL - GROUP BY policies.id, schedule_id, status, elapsed_time_seconds - ON CONFLICT DO NOTHING; - SQL - - UPDATE_EMPTY_RULE_IDS = <<~SQL - UPDATE incident_management_pending_alert_escalations AS escalations - SET rule_id = rules.id - FROM incident_management_pending_alert_escalations AS through_escalations - INNER JOIN incident_management_oncall_schedules AS schedules ON schedules.id = through_escalations.schedule_id - INNER JOIN incident_management_escalation_policies AS policies ON policies.project_id = schedules.project_id - INNER JOIN incident_management_escalation_rules AS rules ON rules.policy_id = policies.id - WHERE escalations.rule_id IS NULL - AND rules.status = escalations.status - AND rules.oncall_schedule_id = escalations.schedule_id - AND rules.elapsed_time_seconds = #{ELAPSED_WHOLE_MINUTES_IN_SECONDS}; - SQL - - DELETE_LEFTOVER_ESCALATIONS_WITHOUT_RULES = 'DELETE FROM incident_management_pending_alert_escalations WHERE rule_id IS NULL;' - - # For each alert which has a pending escalation without a corresponding rule, - # create a rule with the expected attributes for the project's policy. - # - # Deletes all escalations without rules/policy & adds non-null constraint for rule_id. - def up - exec_query INSERT_RULES_FOR_ESCALATIONS_WITHOUT_RULES - exec_query UPDATE_EMPTY_RULE_IDS - exec_query DELETE_LEFTOVER_ESCALATIONS_WITHOUT_RULES - - change_column_null :incident_management_pending_alert_escalations, :rule_id, false - end - - def down - change_column_null :incident_management_pending_alert_escalations, :rule_id, true - end -end diff --git a/db/post_migrate/20210722010101_reschedule_delete_orphaned_deployments.rb b/db/post_migrate/20210722010101_reschedule_delete_orphaned_deployments.rb deleted file mode 100644 index b0608f15ce1..00000000000 --- a/db/post_migrate/20210722010101_reschedule_delete_orphaned_deployments.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class RescheduleDeleteOrphanedDeployments < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - MIGRATION = 'DeleteOrphanedDeployments' - BATCH_SIZE = 10_000 - DELAY_INTERVAL = 2.minutes - - disable_ddl_transaction! - - def up - Gitlab::BackgroundMigration.steal(MIGRATION) - Gitlab::Database::BackgroundMigrationJob.for_migration_class(MIGRATION).delete_all - - queue_background_migration_jobs_by_range_at_intervals( - define_batchable_model('deployments'), - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - track_jobs: true - ) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb b/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb deleted file mode 100644 index b611b51e3ff..00000000000 --- a/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class UpdateIssuableSlasWhereIssueClosed < ActiveRecord::Migration[6.1] - ISSUE_CLOSED_STATUS = 2 - - class IssuableSla < ActiveRecord::Base - include EachBatch - - self.table_name = 'issuable_slas' - - belongs_to :issue, class_name: 'Issue' - end - - class Issue < ActiveRecord::Base - self.table_name = 'issues' - - has_one :issuable_sla, class_name: 'IssuableSla' - end - - def up - IssuableSla.each_batch(of: 50) do |relation| - relation.joins(:issue) - .where(issues: { state_id: ISSUE_CLOSED_STATUS } ) - .update_all(issuable_closed: true) - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210722055217_add_updated_at_index_on_merge_requests.rb b/db/post_migrate/20210722055217_add_updated_at_index_on_merge_requests.rb deleted file mode 100644 index c66c14d1900..00000000000 --- a/db/post_migrate/20210722055217_add_updated_at_index_on_merge_requests.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddUpdatedAtIndexOnMergeRequests < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - INDEX_NAME = 'index_merge_requests_on_target_project_id_and_updated_at_and_id' - - disable_ddl_transaction! - - def up - add_concurrent_index :merge_requests, [:target_project_id, :updated_at, :id], name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :merge_requests, INDEX_NAME - end -end diff --git a/db/post_migrate/20210722110515_revert_backfill_ci_build_trace_sections_for_bigint_conversion.rb b/db/post_migrate/20210722110515_revert_backfill_ci_build_trace_sections_for_bigint_conversion.rb deleted file mode 100644 index 78ae4f23286..00000000000 --- a/db/post_migrate/20210722110515_revert_backfill_ci_build_trace_sections_for_bigint_conversion.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class RevertBackfillCiBuildTraceSectionsForBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE = :ci_build_trace_sections - COLUMN = :build_id - - def up - revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMN, primary_key: COLUMN - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210722155635_finalize_convert_geo_job_artifact_deleted_events_bigint.rb b/db/post_migrate/20210722155635_finalize_convert_geo_job_artifact_deleted_events_bigint.rb deleted file mode 100644 index 5bf6a9e7911..00000000000 --- a/db/post_migrate/20210722155635_finalize_convert_geo_job_artifact_deleted_events_bigint.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -class FinalizeConvertGeoJobArtifactDeletedEventsBigint < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'geo_job_artifact_deleted_events' - COLUMN_NAME = 'job_artifact_id' - COLUMN_NAME_CONVERTED = "#{COLUMN_NAME}_convert_to_bigint" - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [[COLUMN_NAME], [COLUMN_NAME_CONVERTED]] - ) - - swap - end - - def down - swap - end - - def swap - old_index_name = 'index_geo_job_artifact_deleted_events_on_job_artifact_id' - - bigint_index_name = 'index_geo_job_artifact_deleted_events_on_job_artifact_id_bigint' - add_concurrent_index TABLE_NAME, COLUMN_NAME_CONVERTED, name: bigint_index_name - - with_lock_retries(raise_on_exhaustion: true) do - execute("LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE") - - temp_name = quote_column_name("#{COLUMN_NAME}_tmp") - old_column_name = quote_column_name(COLUMN_NAME) - new_column_name = quote_column_name(COLUMN_NAME_CONVERTED) - - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{old_column_name} TO #{temp_name}" - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{new_column_name} TO #{old_column_name}" - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{temp_name} TO #{new_column_name}" - - change_column_default TABLE_NAME, COLUMN_NAME, nil - change_column_default TABLE_NAME, COLUMN_NAME_CONVERTED, 0 - - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(COLUMN_NAME, COLUMN_NAME_CONVERTED) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - execute "DROP INDEX #{old_index_name}" - - rename_index TABLE_NAME, bigint_index_name, old_index_name - end - end -end diff --git a/db/post_migrate/20210727113447_backfill_integrations_type_new.rb b/db/post_migrate/20210727113447_backfill_integrations_type_new.rb deleted file mode 100644 index 47238bae4d5..00000000000 --- a/db/post_migrate/20210727113447_backfill_integrations_type_new.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class BackfillIntegrationsTypeNew < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - MIGRATION = 'BackfillIntegrationsTypeNew' - INTERVAL = 2.minutes - - def up - queue_batched_background_migration( - MIGRATION, - :integrations, - :id, - job_interval: INTERVAL - ) - end - - def down - delete_batched_background_migration(MIGRATION, :integrations, :id, []) - end -end diff --git a/db/post_migrate/20210727175201_remove_unused_columns_from_elastic_reindexing_tasks.rb b/db/post_migrate/20210727175201_remove_unused_columns_from_elastic_reindexing_tasks.rb deleted file mode 100644 index d4ce1e7024f..00000000000 --- a/db/post_migrate/20210727175201_remove_unused_columns_from_elastic_reindexing_tasks.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class RemoveUnusedColumnsFromElasticReindexingTasks < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - remove_column :elastic_reindexing_tasks, :documents_count, :integer - remove_column :elastic_reindexing_tasks, :index_name_from, :text - remove_column :elastic_reindexing_tasks, :index_name_to, :text - remove_column :elastic_reindexing_tasks, :elastic_task, :text - remove_column :elastic_reindexing_tasks, :documents_count_target, :integer - end - - def down - add_column :elastic_reindexing_tasks, :documents_count, :integer - add_column :elastic_reindexing_tasks, :index_name_from, :text - add_column :elastic_reindexing_tasks, :index_name_to, :text - add_column :elastic_reindexing_tasks, :elastic_task, :text - add_column :elastic_reindexing_tasks, :documents_count_target, :integer - - add_text_limit :elastic_reindexing_tasks, :index_name_from, 255 - add_text_limit :elastic_reindexing_tasks, :index_name_to, 255 - add_text_limit :elastic_reindexing_tasks, :elastic_task, 255 - end -end diff --git a/db/post_migrate/20210729163312_re_schedule_latest_pipeline_id_population_with_all_security_related_artifact_types.rb b/db/post_migrate/20210729163312_re_schedule_latest_pipeline_id_population_with_all_security_related_artifact_types.rb deleted file mode 100644 index 8ec608453a0..00000000000 --- a/db/post_migrate/20210729163312_re_schedule_latest_pipeline_id_population_with_all_security_related_artifact_types.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class ReScheduleLatestPipelineIdPopulationWithAllSecurityRelatedArtifactTypes < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DELAY_INTERVAL = 2.minutes.to_i - BATCH_SIZE = 100 - MIGRATION = 'PopulateLatestPipelineIds' - - disable_ddl_transaction! - - def up - return unless Gitlab.ee? - - Gitlab::BackgroundMigration.steal(MIGRATION) - - queue_background_migration_jobs_by_range_at_intervals( - Gitlab::BackgroundMigration::PopulateLatestPipelineIds::ProjectSetting.has_vulnerabilities_without_latest_pipeline_set, - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - primary_column_name: 'project_id' - ) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210729192959_drop_ci_test_case_failures_table.rb b/db/post_migrate/20210729192959_drop_ci_test_case_failures_table.rb deleted file mode 100644 index ad6676a1704..00000000000 --- a/db/post_migrate/20210729192959_drop_ci_test_case_failures_table.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class DropCiTestCaseFailuresTable < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - drop_table :ci_test_case_failures - end - - def down - create_table :ci_test_case_failures do |t| - t.datetime_with_timezone :failed_at - t.bigint :test_case_id, null: false - t.bigint :build_id, null: false - - t.index [:test_case_id, :failed_at, :build_id], name: 'index_test_case_failures_unique_columns', unique: true, order: { failed_at: :desc } - t.index :build_id - end - end -end diff --git a/db/post_migrate/20210729193056_drop_ci_test_cases_table.rb b/db/post_migrate/20210729193056_drop_ci_test_cases_table.rb deleted file mode 100644 index 2de1749721d..00000000000 --- a/db/post_migrate/20210729193056_drop_ci_test_cases_table.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class DropCiTestCasesTable < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - drop_table :ci_test_cases - end - - def down - create_table_with_constraints :ci_test_cases do |t| - t.bigint :project_id, null: false - t.text :key_hash, null: false - t.text_limit :key_hash, 64 - - t.index [:project_id, :key_hash], unique: true - end - end -end diff --git a/db/post_migrate/20210730104800_schedule_extract_project_topics_into_separate_table.rb b/db/post_migrate/20210730104800_schedule_extract_project_topics_into_separate_table.rb deleted file mode 100644 index 3102561a129..00000000000 --- a/db/post_migrate/20210730104800_schedule_extract_project_topics_into_separate_table.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -class ScheduleExtractProjectTopicsIntoSeparateTable < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 1_000 - DELAY_INTERVAL = 2.minutes - MIGRATION = 'ExtractProjectTopicsIntoSeparateTable' - INDEX_NAME = 'tmp_index_taggings_on_id_where_taggable_type_project' - INDEX_CONDITION = "taggable_type = 'Project'" - - disable_ddl_transaction! - - class Tagging < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'taggings' - end - - def up - # this index is used in 20210730104800_schedule_extract_project_topics_into_separate_table - add_concurrent_index :taggings, :id, where: INDEX_CONDITION, name: INDEX_NAME # rubocop:disable Migration/PreventIndexCreation - - queue_background_migration_jobs_by_range_at_intervals( - Tagging.where(taggable_type: 'Project'), - MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE, - track_jobs: true - ) - end - - def down - remove_concurrent_index_by_name :taggings, INDEX_NAME - end -end diff --git a/db/post_migrate/20210730170823_schedule_security_setting_creation.rb b/db/post_migrate/20210730170823_schedule_security_setting_creation.rb deleted file mode 100644 index cea7b976bf9..00000000000 --- a/db/post_migrate/20210730170823_schedule_security_setting_creation.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class ScheduleSecuritySettingCreation < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - MIGRATION = 'CreateSecuritySetting' - BATCH_SIZE = 1000 - INTERVAL = 5.minutes.to_i - - disable_ddl_transaction! - - def up - return unless Gitlab.ee? # Security Settings available only in EE version - - queue_background_migration_jobs_by_range_at_intervals( - define_batchable_model('projects'), - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE - ) - end - - # We're adding data so no need for rollback - def down - end -end diff --git a/db/post_migrate/20210731132939_backfill_stage_event_hash.rb b/db/post_migrate/20210731132939_backfill_stage_event_hash.rb deleted file mode 100644 index e4966cc0e6d..00000000000 --- a/db/post_migrate/20210731132939_backfill_stage_event_hash.rb +++ /dev/null @@ -1,115 +0,0 @@ -# frozen_string_literal: true - -class BackfillStageEventHash < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - BATCH_SIZE = 100 - EVENT_ID_IDENTIFIER_MAPPING = { - 1 => :issue_created, - 2 => :issue_first_mentioned_in_commit, - 3 => :issue_closed, - 4 => :issue_first_added_to_board, - 5 => :issue_first_associated_with_milestone, - 7 => :issue_last_edited, - 8 => :issue_label_added, - 9 => :issue_label_removed, - 10 => :issue_deployed_to_production, - 100 => :merge_request_created, - 101 => :merge_request_first_deployed_to_production, - 102 => :merge_request_last_build_finished, - 103 => :merge_request_last_build_started, - 104 => :merge_request_merged, - 105 => :merge_request_closed, - 106 => :merge_request_last_edited, - 107 => :merge_request_label_added, - 108 => :merge_request_label_removed, - 109 => :merge_request_first_commit_at, - 1000 => :code_stage_start, - 1001 => :issue_stage_end, - 1002 => :plan_stage_start - }.freeze - - LABEL_BASED_EVENTS = Set.new([8, 9, 107, 108]).freeze - - class GroupStage < ActiveRecord::Base - include EachBatch - - self.table_name = 'analytics_cycle_analytics_group_stages' - end - - class ProjectStage < ActiveRecord::Base - include EachBatch - - self.table_name = 'analytics_cycle_analytics_project_stages' - end - - class StageEventHash < ActiveRecord::Base - self.table_name = 'analytics_cycle_analytics_stage_event_hashes' - end - - def up - GroupStage.reset_column_information - ProjectStage.reset_column_information - StageEventHash.reset_column_information - - update_stage_table(GroupStage) - update_stage_table(ProjectStage) - - add_not_null_constraint :analytics_cycle_analytics_group_stages, :stage_event_hash_id - add_not_null_constraint :analytics_cycle_analytics_project_stages, :stage_event_hash_id - end - - def down - remove_not_null_constraint :analytics_cycle_analytics_group_stages, :stage_event_hash_id - remove_not_null_constraint :analytics_cycle_analytics_project_stages, :stage_event_hash_id - end - - private - - def update_stage_table(klass) - klass.each_batch(of: BATCH_SIZE) do |relation| - klass.transaction do - records = relation.where(stage_event_hash_id: nil).lock!.to_a # prevent concurrent modification (unlikely to happen) - records = delete_invalid_records(records) - next if records.empty? - - hashes_by_stage = records.index_with { |stage| calculate_stage_events_hash(stage) } - hashes = hashes_by_stage.values.uniq - - StageEventHash.insert_all(hashes.map { |hash| { hash_sha256: hash } }) - - stage_event_hashes_by_hash = StageEventHash.where(hash_sha256: hashes).index_by(&:hash_sha256) - records.each do |stage| - stage.update!(stage_event_hash_id: stage_event_hashes_by_hash[hashes_by_stage[stage]].id) - end - end - end - end - - def calculate_stage_events_hash(stage) - start_event_hash = calculate_event_hash(stage.start_event_identifier, stage.start_event_label_id) - end_event_hash = calculate_event_hash(stage.end_event_identifier, stage.end_event_label_id) - - Digest::SHA256.hexdigest("#{start_event_hash}-#{end_event_hash}") - end - - def calculate_event_hash(event_identifier, label_id = nil) - str = EVENT_ID_IDENTIFIER_MAPPING.fetch(event_identifier).to_s - str << "-#{label_id}" if LABEL_BASED_EVENTS.include?(event_identifier) - - Digest::SHA256.hexdigest(str) - end - - # Invalid records are safe to delete, since they are not working properly anyway - def delete_invalid_records(records) - to_be_deleted = records.select do |record| - EVENT_ID_IDENTIFIER_MAPPING[record.start_event_identifier].nil? || - EVENT_ID_IDENTIFIER_MAPPING[record.end_event_identifier].nil? - end - - to_be_deleted.each(&:delete) - records - to_be_deleted - end -end diff --git a/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb b/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb deleted file mode 100644 index 289b77f0a5c..00000000000 --- a/db/post_migrate/20210802043253_finalize_push_event_payloads_bigint_conversion_3.rb +++ /dev/null @@ -1,87 +0,0 @@ -# frozen_string_literal: true - -class FinalizePushEventPayloadsBigintConversion3 < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'push_event_payloads' - INDEX_NAME = 'index_push_event_payloads_on_event_id_convert_to_bigint' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'event_id', - job_arguments: [["event_id"], ["event_id_convert_to_bigint"]] - ) - - return if already_swapped? - - swap_columns - end - - def down - swap_columns - end - - private - - def already_swapped? - push_event_payloads_columns = columns(TABLE_NAME) - event_id = push_event_payloads_columns.find { |c| c.name == 'event_id' } - event_id_convert_to_bigint = push_event_payloads_columns.find { |c| c.name == 'event_id_convert_to_bigint' } - - event_id.sql_type == 'bigint' && event_id_convert_to_bigint.sql_type == 'integer' - end - - def swap_columns - add_concurrent_index TABLE_NAME, :event_id_convert_to_bigint, unique: true, name: INDEX_NAME - - # Add a foreign key on `event_id_convert_to_bigint` before we swap the columns and drop the old FK (fk_36c74129da) - add_concurrent_foreign_key TABLE_NAME, :events, column: :event_id_convert_to_bigint, - on_delete: :cascade, reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start. - # Lock order should be - # 1. events - # 2. push_event_payloads - # in order to match the order in EventCreateService#create_push_event, - # and avoid deadlocks. - execute "LOCK TABLE events, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'event_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:event_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:event_id_convert_to_bigint)} TO #{quote_column_name(:event_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:event_id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:event_id, :event_id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - change_column_default TABLE_NAME, :event_id, nil - change_column_default TABLE_NAME, :event_id_convert_to_bigint, 0 - - # Swap PK constraint - execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT push_event_payloads_pkey" - rename_index TABLE_NAME, INDEX_NAME, 'push_event_payloads_pkey' - execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT push_event_payloads_pkey PRIMARY KEY USING INDEX push_event_payloads_pkey" - - # Drop original FK on the old int4 `event_id` (fk_36c74129da) - remove_foreign_key TABLE_NAME, name: concurrent_foreign_key_name(TABLE_NAME, :event_id) - # We swapped the columns but the FK for event_id is still using the old name for the event_id_convert_to_bigint column - # So we have to also swap the FK name now that we dropped the other one with the same - rename_constraint( - TABLE_NAME, - concurrent_foreign_key_name(TABLE_NAME, :event_id_convert_to_bigint), - concurrent_foreign_key_name(TABLE_NAME, :event_id) - ) - end - end -end diff --git a/db/post_migrate/20210802112233_add_index_issues_on_project_id_and_state_id_and_created_at_and_id.rb b/db/post_migrate/20210802112233_add_index_issues_on_project_id_and_state_id_and_created_at_and_id.rb deleted file mode 100644 index 318d9e8a218..00000000000 --- a/db/post_migrate/20210802112233_add_index_issues_on_project_id_and_state_id_and_created_at_and_id.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddIndexIssuesOnProjectIdAndStateIdAndCreatedAtAndId < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - INDEX_NAME = 'index_issues_on_project_id_and_state_id_and_created_at_and_id' - - disable_ddl_transaction! - - def up - add_concurrent_index :issues, [:project_id, :state_id, :created_at, :id], name: INDEX_NAME - end - - def down - remove_concurrent_index_by_name :issues, INDEX_NAME - end -end diff --git a/db/post_migrate/20210802131812_finalize_convert_deployments_bigint.rb b/db/post_migrate/20210802131812_finalize_convert_deployments_bigint.rb deleted file mode 100644 index 067b7166cf3..00000000000 --- a/db/post_migrate/20210802131812_finalize_convert_deployments_bigint.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -class FinalizeConvertDeploymentsBigint < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'deployments' - COLUMN_NAME = 'deployable_id' - COLUMN_NAME_BIGINT = "#{COLUMN_NAME}_convert_to_bigint" - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [[COLUMN_NAME], [COLUMN_NAME_BIGINT]] - ) - - swap - end - - def down - swap - end - - def swap - old_index_name = 'index_deployments_on_deployable_type_and_deployable_id' - bigint_index_name = 'index_deployments_on_deployable_type_and_deployable_id_bigint' - add_concurrent_index TABLE_NAME, ['deployable_type', COLUMN_NAME_BIGINT], name: bigint_index_name - - with_lock_retries(raise_on_exhaustion: true) do - # Swap columns - temp_name = "#{COLUMN_NAME}_tmp" - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(COLUMN_NAME)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(COLUMN_NAME_BIGINT)} TO #{quote_column_name(COLUMN_NAME)}" - execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(COLUMN_NAME_BIGINT)}" - - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(COLUMN_NAME, COLUMN_NAME_BIGINT) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - execute "DROP INDEX #{old_index_name}" - rename_index TABLE_NAME, bigint_index_name, old_index_name - end - end -end diff --git a/db/post_migrate/20210804150624_remove_cluster_image_scanning_from_approval_project_rules.rb b/db/post_migrate/20210804150624_remove_cluster_image_scanning_from_approval_project_rules.rb deleted file mode 100644 index a2736a563c7..00000000000 --- a/db/post_migrate/20210804150624_remove_cluster_image_scanning_from_approval_project_rules.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class RemoveClusterImageScanningFromApprovalProjectRules < ActiveRecord::Migration[6.1] - def up - execute("update approval_project_rules set scanners = array_remove(scanners, 'cluster_image_scanning') where scanners @> '{cluster_image_scanning}'") - end - - def down - # nothing to do here - end -end diff --git a/db/post_migrate/20210804151444_prepare_indexes_for_ci_job_artifact_bigint_conversion.rb b/db/post_migrate/20210804151444_prepare_indexes_for_ci_job_artifact_bigint_conversion.rb deleted file mode 100644 index 81e73effe7b..00000000000 --- a/db/post_migrate/20210804151444_prepare_indexes_for_ci_job_artifact_bigint_conversion.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -class PrepareIndexesForCiJobArtifactBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - prepare_async_index :ci_job_artifacts, :id_convert_to_bigint, unique: true, - name: :index_ci_job_artifact_on_id_convert_to_bigint - - prepare_async_index :ci_job_artifacts, - [:project_id, :id_convert_to_bigint], - where: 'file_type = 18', name: :index_ci_job_artifacts_for_terraform_reports_bigint - - prepare_async_index :ci_job_artifacts, :id_convert_to_bigint, - where: 'file_type = 18', - name: :index_ci_job_artifacts_id_for_terraform_reports_bigint - - prepare_async_index :ci_job_artifacts, - [:expire_at, :job_id_convert_to_bigint], - name: :index_ci_job_artifacts_on_expire_at_and_job_id_bigint - - prepare_async_index :ci_job_artifacts, - [:job_id_convert_to_bigint, :file_type], - unique: true, name: :index_ci_job_artifacts_on_job_id_and_file_type_bigint - end - - def down - unprepare_async_index_by_name :ci_job_artifacts, :index_ci_job_artifacts_on_job_id_and_file_type_bigint - - unprepare_async_index_by_name :ci_job_artifacts, :index_ci_job_artifacts_on_expire_at_and_job_id_bigint - - unprepare_async_index_by_name :ci_job_artifacts, :index_ci_job_artifacts_id_for_terraform_reports_bigint - - unprepare_async_index_by_name :ci_job_artifacts, :index_ci_job_artifacts_for_terraform_reports_bigint - - unprepare_async_index_by_name :ci_job_artifacts, :index_ci_job_artifact_on_id_convert_to_bigint - end -end diff --git a/db/post_migrate/20210804153307_prepare_indexes_for_tagging_bigint_conversion.rb b/db/post_migrate/20210804153307_prepare_indexes_for_tagging_bigint_conversion.rb deleted file mode 100644 index ab6691dea1f..00000000000 --- a/db/post_migrate/20210804153307_prepare_indexes_for_tagging_bigint_conversion.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class PrepareIndexesForTaggingBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - prepare_async_index :taggings, :id_convert_to_bigint, unique: true, - name: :index_taggings_on_id_convert_to_bigint - - prepare_async_index :taggings, [:taggable_id_convert_to_bigint, :taggable_type], - name: :i_taggings_on_taggable_id_convert_to_bigint_and_taggable_type - - prepare_async_index :taggings, [:taggable_id_convert_to_bigint, :taggable_type, :context], - name: :i_taggings_on_taggable_bigint_and_taggable_type_and_context - - prepare_async_index :taggings, [:tag_id, :taggable_id_convert_to_bigint, :taggable_type, :context, :tagger_id, :tagger_type], - unique: true, name: :taggings_idx_tmp - end - - def down - unprepare_async_index_by_name :taggings, :taggings_idx_tmp - - unprepare_async_index_by_name :taggings, :i_taggings_on_taggable_bigint_and_taggable_type_and_context - - unprepare_async_index_by_name :taggings, :i_taggings_on_taggable_id_convert_to_bigint_and_taggable_type - - unprepare_async_index_by_name :taggings, :index_taggings_on_id_convert_to_bigint - end -end diff --git a/db/post_migrate/20210804154407_prepare_indexes_for_ci_stage_bigint_conversion.rb b/db/post_migrate/20210804154407_prepare_indexes_for_ci_stage_bigint_conversion.rb deleted file mode 100644 index 16f3e87000c..00000000000 --- a/db/post_migrate/20210804154407_prepare_indexes_for_ci_stage_bigint_conversion.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class PrepareIndexesForCiStageBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - prepare_async_index :ci_stages, :id_convert_to_bigint, unique: true, - name: :index_ci_stages_on_id_convert_to_bigint - - prepare_async_index :ci_stages, [:pipeline_id, :id_convert_to_bigint], - where: 'status in (0, 1, 2, 8, 9, 10)', - name: :index_ci_stages_on_pipeline_id_and_id_convert_to_bigint - end - - def down - unprepare_async_index_by_name :ci_stages, - :index_ci_stages_on_pipeline_id_and_id_convert_to_bigint - - unprepare_async_index_by_name :ci_stages, :index_ci_stages_on_id_convert_to_bigint - end -end diff --git a/db/post_migrate/20210805131510_finalize_ci_builds_runner_session_bigint_conversion.rb b/db/post_migrate/20210805131510_finalize_ci_builds_runner_session_bigint_conversion.rb deleted file mode 100644 index 5e18450f465..00000000000 --- a/db/post_migrate/20210805131510_finalize_ci_builds_runner_session_bigint_conversion.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -class FinalizeCiBuildsRunnerSessionBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_builds_runner_session' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [['build_id'], ['build_id_convert_to_bigint']] - ) - - swap - end - - def down - swap - end - - private - - def swap - add_concurrent_index TABLE_NAME, :build_id_convert_to_bigint, unique: true, name: 'index_ci_builds_runner_session_on_build_id_convert_to_bigint' - - # Add a foreign key on `build_id_convert_to_bigint` before we swap the columns and drop the old FK () - add_concurrent_foreign_key TABLE_NAME, :ci_builds, column: :build_id_convert_to_bigint, on_delete: :cascade, name: 'fk_rails_70707857d3_tmp', reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start - execute "LOCK TABLE ci_builds, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'build_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:build_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:build_id_convert_to_bigint)} TO #{quote_column_name(:build_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:build_id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name(:build_id, :build_id_convert_to_bigint) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - change_column_default TABLE_NAME, :build_id, nil - change_column_default TABLE_NAME, :build_id_convert_to_bigint, 0 - - # Rename the index on the `bigint` column to match the new column name - # (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here) - execute 'DROP INDEX index_ci_builds_runner_session_on_build_id' - rename_index TABLE_NAME, 'index_ci_builds_runner_session_on_build_id_convert_to_bigint', 'index_ci_builds_runner_session_on_build_id' - - # Drop original FK on the old int4 `build_id` (fk_rails_70707857d3) - remove_foreign_key TABLE_NAME, name: 'fk_rails_70707857d3' - - # We swapped the columns but the FK for buil_id is still using the temporary name for the build_id_convert_to_bigint column - # So we have to also swap the FK name now that we dropped the other one with the same - rename_constraint(TABLE_NAME, 'fk_rails_70707857d3_tmp', 'fk_rails_70707857d3') - end - end -end diff --git a/db/post_migrate/20210805192450_update_trial_plans_ci_daily_pipeline_schedule_triggers.rb b/db/post_migrate/20210805192450_update_trial_plans_ci_daily_pipeline_schedule_triggers.rb deleted file mode 100644 index f27f61729a3..00000000000 --- a/db/post_migrate/20210805192450_update_trial_plans_ci_daily_pipeline_schedule_triggers.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -class UpdateTrialPlansCiDailyPipelineScheduleTriggers < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - PREMIUM_TRIAL = 'premium_trial' - ULTIMATE_TRIAL = 'ultimate_trial' - EVERY_5_MINUTES = (1.day.in_minutes / 5).to_i - - class Plan < ActiveRecord::Base - self.table_name = 'plans' - self.inheritance_column = :_type_disabled - - has_one :limits, class_name: 'PlanLimits' - end - - class PlanLimits < ActiveRecord::Base - self.table_name = 'plan_limits' - self.inheritance_column = :_type_disabled - - belongs_to :plan - end - - def plan_limits_present? - premium_trial_plan = Plan.find_by(name: PREMIUM_TRIAL) - ultimate_trial_plan = Plan.find_by(name: ULTIMATE_TRIAL) - - premium_trial_plan && premium_trial_plan.limits && ultimate_trial_plan && ultimate_trial_plan.limits - end - - def up - return unless Gitlab.com? - - if plan_limits_present? - create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', PREMIUM_TRIAL, EVERY_5_MINUTES) - create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', ULTIMATE_TRIAL, EVERY_5_MINUTES) - end - end - - def down - return unless Gitlab.com? - - if plan_limits_present? - create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', PREMIUM_TRIAL, 0) - create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', ULTIMATE_TRIAL, 0) - end - end -end diff --git a/db/post_migrate/20210806011811_schedule_backfill_draft_column_on_merge_requests_rerun.rb b/db/post_migrate/20210806011811_schedule_backfill_draft_column_on_merge_requests_rerun.rb deleted file mode 100644 index 90bca79624d..00000000000 --- a/db/post_migrate/20210806011811_schedule_backfill_draft_column_on_merge_requests_rerun.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class ScheduleBackfillDraftColumnOnMergeRequestsRerun < ActiveRecord::Migration[6.1] - def up - # noop - # - end - - def down - # noop - # - end -end diff --git a/db/post_migrate/20210806131706_finalize_taggins_bigint_conversion.rb b/db/post_migrate/20210806131706_finalize_taggins_bigint_conversion.rb deleted file mode 100644 index 5f094e48ed4..00000000000 --- a/db/post_migrate/20210806131706_finalize_taggins_bigint_conversion.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -class FinalizeTagginsBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'taggings' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [%w[id taggable_id], %w[id_convert_to_bigint taggable_id_convert_to_bigint]] - ) - - swap - end - - def down - swap - end - - private - - def swap - # rubocop:disable Migration/PreventIndexCreation - add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: 'index_taggings_on_id_convert_to_bigint' - - # This is to replace the existing "index_taggings_on_taggable_id_and_taggable_type" btree (taggable_id, taggable_type) - add_concurrent_index TABLE_NAME, [:taggable_id_convert_to_bigint, :taggable_type], name: 'i_taggings_on_taggable_id_convert_to_bigint_and_taggable_type' - - # This is to replace the existing "index_taggings_on_taggable_id_and_taggable_type_and_context" btree (taggable_id, taggable_type, context) - add_concurrent_index TABLE_NAME, [:taggable_id_convert_to_bigint, :taggable_type, :context], name: 'i_taggings_on_taggable_bigint_and_taggable_type_and_context' - - # This is to replace the existing "taggings_idx" btree (tag_id, taggable_id, taggable_type, context, tagger_id, tagger_type) - add_concurrent_index TABLE_NAME, [:tag_id, :taggable_id_convert_to_bigint, :taggable_type, :context, :tagger_id, :tagger_type], unique: true, name: 'taggings_idx_tmp' - - # This is to replace the existing "tmp_index_taggings_on_id_where_taggable_type_project" btree (id) WHERE taggable_type::text = 'Project'::text - add_concurrent_index TABLE_NAME, :id_convert_to_bigint, where: "taggable_type = 'Project'", name: 'tmp_index_taggings_on_id_bigint_where_taggable_type_project' - # rubocop:enable Migration/PreventIndexCreation - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start - execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" - - # Swap column names - temp_name = 'taggable_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:taggable_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:taggable_id_convert_to_bigint)} TO #{quote_column_name(:taggable_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:taggable_id_convert_to_bigint)}" - - temp_name = 'id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id_convert_to_bigint)} TO #{quote_column_name(:id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name([:id, :taggable_id], [:id_convert_to_bigint, :taggable_id_convert_to_bigint]) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - execute "ALTER SEQUENCE taggings_id_seq OWNED BY #{TABLE_NAME}.id" - change_column_default TABLE_NAME, :id, -> { "nextval('taggings_id_seq'::regclass)" } - change_column_default TABLE_NAME, :id_convert_to_bigint, 0 - - # Swap PK constraint - execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT taggings_pkey CASCADE" - rename_index TABLE_NAME, 'index_taggings_on_id_convert_to_bigint', 'taggings_pkey' - execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT taggings_pkey PRIMARY KEY USING INDEX taggings_pkey" - - # Rename the index on the `bigint` column to match the new column name - # (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here) - execute 'DROP INDEX IF EXISTS index_taggings_on_taggable_id_and_taggable_type' - rename_index TABLE_NAME, 'i_taggings_on_taggable_id_convert_to_bigint_and_taggable_type', 'index_taggings_on_taggable_id_and_taggable_type' - execute 'DROP INDEX IF EXISTS index_taggings_on_taggable_id_and_taggable_type_and_context' - rename_index TABLE_NAME, 'i_taggings_on_taggable_bigint_and_taggable_type_and_context', 'index_taggings_on_taggable_id_and_taggable_type_and_context' - execute 'DROP INDEX IF EXISTS taggings_idx' - rename_index TABLE_NAME, 'taggings_idx_tmp', 'taggings_idx' - execute 'DROP INDEX IF EXISTS tmp_index_taggings_on_id_where_taggable_type_project' - rename_index TABLE_NAME, 'tmp_index_taggings_on_id_bigint_where_taggable_type_project', 'tmp_index_taggings_on_id_where_taggable_type_project' - end - end -end diff --git a/db/post_migrate/20210809123658_orphaned_invite_tokens_cleanup.rb b/db/post_migrate/20210809123658_orphaned_invite_tokens_cleanup.rb deleted file mode 100644 index ddbafaf32a9..00000000000 --- a/db/post_migrate/20210809123658_orphaned_invite_tokens_cleanup.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -class OrphanedInviteTokensCleanup < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TMP_INDEX_NAME = 'tmp_idx_orphaned_invite_tokens' - - def up - add_concurrent_index('members', :id, where: query_condition, name: TMP_INDEX_NAME) - - membership.where(query_condition).pluck(:id).each_slice(10) do |group| - membership.where(id: group).where(query_condition).update_all(invite_token: nil) - end - - remove_concurrent_index_by_name('members', TMP_INDEX_NAME) - end - - def down - remove_concurrent_index_by_name('members', TMP_INDEX_NAME) if index_exists_by_name?('members', TMP_INDEX_NAME) - - # This migration is irreversible - end - - private - - def membership - @membership ||= define_batchable_model('members') - end - - # We need to ensure we're comparing timestamp with time zones across - # the board since that is an immutable comparison. Some database - # schemas have a mix of timestamp without time zones and and timestamp - # with time zones: https://gitlab.com/groups/gitlab-org/-/epics/2473 - def query_condition - "invite_token IS NOT NULL and invite_accepted_at IS NOT NULL and #{timestamptz("invite_accepted_at")} < #{timestamptz("created_at")}" - end - - def timestamptz(name) - if column_type(name) == "timestamp without time zone" - "TIMEZONE('UTC', #{name})" - else - name - end - end - - def column_type(name) - membership.columns_hash[name].sql_type - end -end diff --git a/db/post_migrate/20210809143931_finalize_job_id_conversion_to_bigint_for_ci_job_artifacts.rb b/db/post_migrate/20210809143931_finalize_job_id_conversion_to_bigint_for_ci_job_artifacts.rb deleted file mode 100644 index 5cec6fa30b8..00000000000 --- a/db/post_migrate/20210809143931_finalize_job_id_conversion_to_bigint_for_ci_job_artifacts.rb +++ /dev/null @@ -1,79 +0,0 @@ -# frozen_string_literal: true - -class FinalizeJobIdConversionToBigintForCiJobArtifacts < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE_NAME = 'ci_job_artifacts' - - def up - ensure_batched_background_migration_is_finished( - job_class_name: 'CopyColumnUsingBackgroundMigrationJob', - table_name: TABLE_NAME, - column_name: 'id', - job_arguments: [%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]] - ) - - swap - end - - def down - swap - end - - private - - def swap - # This is to replace the existing "index_ci_job_artifacts_on_expire_at_and_job_id" btree (expire_at, job_id) - add_concurrent_index TABLE_NAME, [:expire_at, :job_id_convert_to_bigint], name: 'index_ci_job_artifacts_on_expire_at_and_job_id_bigint' - # This is to replace the existing "index_ci_job_artifacts_on_job_id_and_file_type" btree (job_id, file_type) - add_concurrent_index TABLE_NAME, [:job_id_convert_to_bigint, :file_type], name: 'index_ci_job_artifacts_on_job_id_and_file_type_bigint', unique: true - - # # Add a FK on `job_id_convert_to_bigint` to `ci_builds(id)`, the old FK (fk_rails_c5137cb2c1) - # # is removed below since it won't be dropped automatically. - fk_ci_builds_job_id = concurrent_foreign_key_name(TABLE_NAME, :job_id, prefix: 'fk_rails_') - fk_ci_builds_job_id_tmp = "#{fk_ci_builds_job_id}_tmp" - - add_concurrent_foreign_key TABLE_NAME, :ci_builds, - column: :job_id_convert_to_bigint, - name: fk_ci_builds_job_id_tmp, - on_delete: :cascade, - reverse_lock_order: true - - with_lock_retries(raise_on_exhaustion: true) do - # We'll need ACCESS EXCLUSIVE lock on the related tables, - # lets make sure it can be acquired from the start - - execute "LOCK TABLE ci_builds, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" - - temp_name = 'job_id_tmp' - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:job_id)} TO #{quote_column_name(temp_name)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:job_id_convert_to_bigint)} TO #{quote_column_name(:job_id)}" - execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:job_id_convert_to_bigint)}" - - # We need to update the trigger function in order to make PostgreSQL to - # regenerate the execution plan for it. This is to avoid type mismatch errors like - # "type of parameter 15 (bigint) does not match that when preparing the plan (integer)" - function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection).name([:id, :job_id], [:id_convert_to_bigint, :job_id_convert_to_bigint]) - execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" - - # Swap defaults - change_column_default TABLE_NAME, :job_id, nil - change_column_default TABLE_NAME, :job_id_convert_to_bigint, 0 - - # Rename the rest of the indexes (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here - execute 'DROP INDEX index_ci_job_artifacts_on_expire_at_and_job_id' - rename_index TABLE_NAME, 'index_ci_job_artifacts_on_expire_at_and_job_id_bigint', 'index_ci_job_artifacts_on_expire_at_and_job_id' - execute 'DROP INDEX index_ci_job_artifacts_on_job_id_and_file_type' - rename_index TABLE_NAME, 'index_ci_job_artifacts_on_job_id_and_file_type_bigint', 'index_ci_job_artifacts_on_job_id_and_file_type' - - # Drop original FK on the old int4 `job_id` (fk_rails_c5137cb2c1) - remove_foreign_key TABLE_NAME, name: fk_ci_builds_job_id - - # We swapped the columns but the FK for job_id is still using the temporary name for the job_id_convert_to_bigint column - # So we have to also swap the FK name now that we dropped the other one with the same - rename_constraint(TABLE_NAME, fk_ci_builds_job_id_tmp, fk_ci_builds_job_id) - end - end -end diff --git a/db/post_migrate/20210811122206_update_external_project_bots.rb b/db/post_migrate/20210811122206_update_external_project_bots.rb deleted file mode 100644 index dc2e3d316b0..00000000000 --- a/db/post_migrate/20210811122206_update_external_project_bots.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class UpdateExternalProjectBots < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - class User < ActiveRecord::Base - self.table_name = 'users' - end - - disable_ddl_transaction! - - TMP_INDEX_NAME = 'tmp_idx_update_external_project_bots' - - def up - add_concurrent_index('users', 'id', name: TMP_INDEX_NAME, where: 'external = true') - - ids = ActiveRecord::Base.connection - .execute("SELECT u.id FROM users u JOIN users u2 on u2.id = u.created_by_id WHERE u.user_type = 6 AND u2.external = true") - .map { |result| result['id'] } - - ids.each_slice(10) do |group| - UpdateExternalProjectBots::User.where(id: group).update_all(external: true) - end - - remove_concurrent_index_by_name('users', TMP_INDEX_NAME) - end - - def down - remove_concurrent_index_by_name('users', TMP_INDEX_NAME) if index_exists_by_name?('users', TMP_INDEX_NAME) - - # This migration is irreversible - end -end diff --git a/db/post_migrate/20210811214811_schedule_copy_ci_builds_columns_to_security_scans.rb b/db/post_migrate/20210811214811_schedule_copy_ci_builds_columns_to_security_scans.rb deleted file mode 100644 index 106d1430dca..00000000000 --- a/db/post_migrate/20210811214811_schedule_copy_ci_builds_columns_to_security_scans.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class ScheduleCopyCiBuildsColumnsToSecurityScans < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - # no-op as we found an issue with bg migration, we fixed it and rescheduling it again. - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210812013042_remove_duplicate_project_authorizations.rb b/db/post_migrate/20210812013042_remove_duplicate_project_authorizations.rb deleted file mode 100644 index 1c2e2b52e8b..00000000000 --- a/db/post_migrate/20210812013042_remove_duplicate_project_authorizations.rb +++ /dev/null @@ -1,112 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicateProjectAuthorizations < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - BATCH_SIZE = 10_000 - OLD_INDEX_NAME = 'index_project_authorizations_on_project_id_user_id' - INDEX_NAME = 'index_unique_project_authorizations_on_project_id_user_id' - - class ProjectAuthorization < ActiveRecord::Base - self.table_name = 'project_authorizations' - end - - disable_ddl_transaction! - - def up - batch do |first_record, last_record| - break if first_record.blank? - - # construct a range query where we filter records between the first and last records - rows = ActiveRecord::Base.connection.execute <<~SQL - SELECT user_id, project_id - FROM project_authorizations - WHERE - #{start_condition(first_record)} - #{end_condition(last_record)} - GROUP BY user_id, project_id - HAVING COUNT(*) > 1 - SQL - - rows.each do |row| - deduplicate_item(row['project_id'], row['user_id']) - end - end - - add_concurrent_index :project_authorizations, [:project_id, :user_id], unique: true, name: INDEX_NAME - remove_concurrent_index_by_name :project_authorizations, OLD_INDEX_NAME - end - - def down - add_concurrent_index(:project_authorizations, [:project_id, :user_id], name: OLD_INDEX_NAME) - remove_concurrent_index_by_name(:project_authorizations, INDEX_NAME) - end - - private - - def start_condition(record) - "(user_id, project_id) >= (#{Integer(record.user_id)}, #{Integer(record.project_id)})" - end - - def end_condition(record) - return "" unless record - - "AND (user_id, project_id) <= (#{Integer(record.user_id)}, #{Integer(record.project_id)})" - end - - def batch(&block) - order = Gitlab::Pagination::Keyset::Order.build( - [ - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: 'user_id', - order_expression: ProjectAuthorization.arel_table[:user_id].asc, - nullable: :not_nullable, - distinct: false - ), - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: 'project_id', - order_expression: ProjectAuthorization.arel_table[:project_id].asc, - nullable: :not_nullable, - distinct: false - ), - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: 'access_level', - order_expression: ProjectAuthorization.arel_table[:access_level].asc, - nullable: :not_nullable, - distinct: true - ) - ]) - - scope = ProjectAuthorization.order(order) - cursor = {} - loop do - current_scope = scope.dup - - relation = order.apply_cursor_conditions(current_scope, cursor) - first_record = relation.take - last_record = relation.offset(BATCH_SIZE).take - - yield first_record, last_record - - break if last_record.blank? - - cursor = order.cursor_attributes_for_node(last_record) - end - end - - def deduplicate_item(project_id, user_id) - auth_records = ProjectAuthorization.where(project_id: project_id, user_id: user_id).order(access_level: :desc).to_a - - ActiveRecord::Base.transaction do - # Keep the highest access level and destroy the rest. - auth_records[1..].each do |record| - ProjectAuthorization - .where( - project_id: record.project_id, - user_id: record.user_id, - access_level: record.access_level - ).delete_all - end - end - end -end diff --git a/db/post_migrate/20210812145010_reset_job_token_scope_enabled_again.rb b/db/post_migrate/20210812145010_reset_job_token_scope_enabled_again.rb deleted file mode 100644 index 6b4c69efa2b..00000000000 --- a/db/post_migrate/20210812145010_reset_job_token_scope_enabled_again.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class ResetJobTokenScopeEnabledAgain < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - with_lock_retries do - remove_column :project_ci_cd_settings, :job_token_scope_enabled - add_column :project_ci_cd_settings, :job_token_scope_enabled, :boolean, default: false, null: false - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210813151908_replace_external_wiki_triggers.rb b/db/post_migrate/20210813151908_replace_external_wiki_triggers.rb deleted file mode 100644 index d11baae42e2..00000000000 --- a/db/post_migrate/20210813151908_replace_external_wiki_triggers.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -class ReplaceExternalWikiTriggers < ActiveRecord::Migration[6.1] - include Gitlab::Database::SchemaHelpers - - def up - replace_triggers('type_new', 'Integrations::ExternalWiki') - - # we need an extra trigger to handle when type_new is updated by the - # `integrations_set_type_new` trigger. - # This can be removed when this trigger has been removed. - execute(<<~SQL.squish) - CREATE TRIGGER #{trigger_name(:type_new_updated)} - AFTER UPDATE OF type_new ON integrations FOR EACH ROW - WHEN ((new.type_new)::text = 'Integrations::ExternalWiki'::text AND new.project_id IS NOT NULL) - EXECUTE FUNCTION set_has_external_wiki(); - SQL - end - - def down - execute("DROP TRIGGER IF EXISTS #{trigger_name(:type_new_updated)} ON integrations;") - replace_triggers('type', 'ExternalWikiService') - end - - private - - def replace_triggers(column_name, value) - triggers(column_name, value).each do |event, condition| - trigger = trigger_name(event) - - # create duplicate trigger, using the defined condition - execute(<<~SQL.squish) - CREATE TRIGGER #{trigger}_new AFTER #{event.upcase} ON integrations FOR EACH ROW - WHEN (#{condition}) - EXECUTE FUNCTION set_has_external_wiki(); - SQL - - # Swap the triggers in place, so that the new trigger has the canonical name - execute("ALTER TRIGGER #{trigger} ON integrations RENAME TO #{trigger}_old;") - execute("ALTER TRIGGER #{trigger}_new ON integrations RENAME TO #{trigger};") - - # remove the old, now redundant trigger - execute("DROP TRIGGER IF EXISTS #{trigger}_old ON integrations;") - end - end - - def trigger_name(event) - "trigger_has_external_wiki_on_#{event}" - end - - def triggers(column_name, value) - { - delete: "#{matches_value('old', column_name, value)} AND #{project_not_null('old')}", - insert: "(new.active = true) AND #{matches_value('new', column_name, value)} AND #{project_not_null('new')}", - update: "#{matches_value('new', column_name, value)} AND (old.active <> new.active) AND #{project_not_null('new')}" - } - end - - def project_not_null(row) - "(#{row}.project_id IS NOT NULL)" - end - - def matches_value(row, column_name, value) - "((#{row}.#{column_name})::text = '#{value}'::text)" - end -end diff --git a/db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb b/db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb deleted file mode 100644 index 0e6f1c50534..00000000000 --- a/db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class ScheduleRecalculateUuidOnVulnerabilitiesOccurrences3 < ActiveRecord::Migration[6.0] - def up - # no-op - # superseded by db/post_migrate/20211207125231_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb b/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb deleted file mode 100644 index 074ba97da65..00000000000 --- a/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class ScheduleCopyCiBuildsColumnsToSecurityScans2 < ActiveRecord::Migration[6.1] - def up - # no-op: Must have run before %"15.X" as it is not compatible with decomposed CI database - end - - def down - # noop - end -end diff --git a/db/post_migrate/20210817024335_prepare_indexes_for_events_bigint_conversion.rb b/db/post_migrate/20210817024335_prepare_indexes_for_events_bigint_conversion.rb deleted file mode 100644 index e1ed28f6826..00000000000 --- a/db/post_migrate/20210817024335_prepare_indexes_for_events_bigint_conversion.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class PrepareIndexesForEventsBigintConversion < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - TABLE_NAME = 'events' - - def up - prepare_async_index TABLE_NAME, :id_convert_to_bigint, unique: true, - name: :index_events_on_id_convert_to_bigint - - prepare_async_index TABLE_NAME, [:project_id, :id_convert_to_bigint], - name: :index_events_on_project_id_and_id_convert_to_bigint - - prepare_async_index TABLE_NAME, [:project_id, :id_convert_to_bigint], - order: { id_convert_to_bigint: :desc }, - where: 'action = 7', name: :index_events_on_project_id_and_id_bigint_desc_on_merged_action - end - - def down - unprepare_async_index_by_name TABLE_NAME, :index_events_on_id_convert_to_bigint - unprepare_async_index_by_name TABLE_NAME, :index_events_on_project_id_and_id_convert_to_bigint - unprepare_async_index_by_name TABLE_NAME, :index_events_on_project_id_and_id_bigint_desc_on_merged_action - end -end diff --git a/db/post_migrate/20210818185845_backfill_projects_with_coverage.rb b/db/post_migrate/20210818185845_backfill_projects_with_coverage.rb deleted file mode 100644 index d86d49f4393..00000000000 --- a/db/post_migrate/20210818185845_backfill_projects_with_coverage.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class BackfillProjectsWithCoverage < ActiveRecord::Migration[6.1] - def up - # noop - end - - def down - # noop - end -end diff --git a/db/post_migrate/20210819145000_drop_temporary_columns_and_triggers_for_ci_builds_runner_session.rb b/db/post_migrate/20210819145000_drop_temporary_columns_and_triggers_for_ci_builds_runner_session.rb deleted file mode 100644 index bbcee556020..00000000000 --- a/db/post_migrate/20210819145000_drop_temporary_columns_and_triggers_for_ci_builds_runner_session.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class DropTemporaryColumnsAndTriggersForCiBuildsRunnerSession < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE = 'ci_builds_runner_session' - TEMPORARY_COLUMN = 'build_id_convert_to_bigint' - MAIN_COLUMN = 'build_id' - - # rubocop:disable Migration/WithLockRetriesDisallowedMethod - def up - with_lock_retries do - cleanup_conversion_of_integer_to_bigint(TABLE, MAIN_COLUMN) - end - end - - def down - check_trigger_permissions!(TABLE) - - with_lock_retries do - add_column(TABLE, TEMPORARY_COLUMN, :int, default: 0, null: false) - install_rename_triggers(TABLE, MAIN_COLUMN, TEMPORARY_COLUMN) - end - end - # rubocop:enable Migration/WithLockRetriesDisallowedMethod -end diff --git a/db/post_migrate/20210819183128_reset_severity_levels_to_new_default.rb b/db/post_migrate/20210819183128_reset_severity_levels_to_new_default.rb deleted file mode 100644 index cdfd92ac0d7..00000000000 --- a/db/post_migrate/20210819183128_reset_severity_levels_to_new_default.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class ResetSeverityLevelsToNewDefault < ActiveRecord::Migration[6.1] - ALL_SEVERITY_LEVELS = 6 # ::Enums::Vulnerability::SEVERITY_LEVELS.count - - def up - execute(<<~SQL.squish) - UPDATE approval_project_rules - SET severity_levels = '{unknown, high, critical}' - WHERE array_length(severity_levels, 1) = #{ALL_SEVERITY_LEVELS}; - SQL - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210823113259_steal_merge_request_diff_commit_users_migration.rb b/db/post_migrate/20210823113259_steal_merge_request_diff_commit_users_migration.rb deleted file mode 100644 index 7e893d62c28..00000000000 --- a/db/post_migrate/20210823113259_steal_merge_request_diff_commit_users_migration.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -# See https://docs.gitlab.com/ee/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class StealMergeRequestDiffCommitUsersMigration < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - def up - job = Gitlab::Database::BackgroundMigrationJob - .for_migration_class('MigrateMergeRequestDiffCommitUsers') - .pending - .last - - return unless job - - # We schedule in one hour so we don't end up running the migrations while a - # deployment is still wrapping up. Not that that really matters, but it - # prevents from too much happening during a deployment window. - migrate_in(1.hour, 'StealMigrateMergeRequestDiffCommitUsers', job.arguments) - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20210823132600_remove_duplicate_dast_site_tokens.rb b/db/post_migrate/20210823132600_remove_duplicate_dast_site_tokens.rb deleted file mode 100644 index 35cf3b55200..00000000000 --- a/db/post_migrate/20210823132600_remove_duplicate_dast_site_tokens.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicateDastSiteTokens < ActiveRecord::Migration[6.1] - disable_ddl_transaction! - - class DastSiteToken < ApplicationRecord - self.table_name = 'dast_site_tokens' - self.inheritance_column = :_type_disabled - - scope :duplicates, -> do - all_duplicates = select(:project_id, :url) - .distinct - .group(:project_id, :url) - .having('count(*) > 1') - .pluck('array_agg(id) as ids') - - duplicate_ids = extract_duplicate_ids(all_duplicates) - - where(id: duplicate_ids) - end - - def self.extract_duplicate_ids(duplicates) - duplicates.flat_map { |ids| ids.first(ids.size - 1) } - end - end - - def up - DastSiteToken.duplicates.delete_all - end - - def down - end -end diff --git a/db/post_migrate/20210823142036_drop_temporary_trigger_for_ci_job_artifacts.rb b/db/post_migrate/20210823142036_drop_temporary_trigger_for_ci_job_artifacts.rb deleted file mode 100644 index 42b25a192d5..00000000000 --- a/db/post_migrate/20210823142036_drop_temporary_trigger_for_ci_job_artifacts.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -class DropTemporaryTriggerForCiJobArtifacts < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TABLE = 'ci_job_artifacts' - TEMPORARY_COLUMNS = %w(id_convert_to_bigint job_id_convert_to_bigint) - MAIN_COLUMNS = %w(id job_id) - TRIGGER = 'trigger_be1804f21693' - - # rubocop:disable Migration/WithLockRetriesDisallowedMethod - def up - check_trigger_permissions!(TABLE) - - with_lock_retries do - remove_rename_triggers(TABLE, TRIGGER) - end - end - - def down - check_trigger_permissions!(TABLE) - - with_lock_retries do - install_rename_triggers(TABLE, MAIN_COLUMNS, TEMPORARY_COLUMNS, trigger_name: TRIGGER) - end - end - # rubocop:enable Migration/WithLockRetriesDisallowedMethod -end diff --git a/db/post_migrate/20210823193234_remove_allow_editing_commit_messages_from_project_settings.rb b/db/post_migrate/20210823193234_remove_allow_editing_commit_messages_from_project_settings.rb deleted file mode 100644 index 638361d0e83..00000000000 --- a/db/post_migrate/20210823193234_remove_allow_editing_commit_messages_from_project_settings.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RemoveAllowEditingCommitMessagesFromProjectSettings < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - return unless column_exists?(:project_settings, :allow_editing_commit_messages) - - with_lock_retries do - remove_column :project_settings, :allow_editing_commit_messages - end - end - - def down - with_lock_retries do - add_column :project_settings, :allow_editing_commit_messages, :boolean, default: false, null: false - end - end -end diff --git a/db/post_migrate/20210824102624_add_project_namespace_index_to_project.rb b/db/post_migrate/20210824102624_add_project_namespace_index_to_project.rb deleted file mode 100644 index d88a31fca7d..00000000000 --- a/db/post_migrate/20210824102624_add_project_namespace_index_to_project.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class AddProjectNamespaceIndexToProject < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - INDEX_NAME = 'index_projects_on_project_namespace_id' - - def up - add_concurrent_index :projects, :project_namespace_id, name: INDEX_NAME, unique: true - end - - def down - remove_concurrent_index_by_name :projects, INDEX_NAME - end -end diff --git a/db/post_migrate/20210824102750_add_project_namespace_foreign_key_to_project.rb b/db/post_migrate/20210824102750_add_project_namespace_foreign_key_to_project.rb deleted file mode 100644 index 5cb42fd61a7..00000000000 --- a/db/post_migrate/20210824102750_add_project_namespace_foreign_key_to_project.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class AddProjectNamespaceForeignKeyToProject < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TARGET_COLUMN = :project_namespace_id - - def up - add_concurrent_foreign_key :projects, :namespaces, column: TARGET_COLUMN, on_delete: :cascade - end - - def down - with_lock_retries do - remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN) - end - end -end diff --git a/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb b/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb deleted file mode 100644 index bf95aa98295..00000000000 --- a/db/post_migrate/20210824174615_prepare_ci_builds_metadata_and_ci_build_async_indexes.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -class PrepareCiBuildsMetadataAndCiBuildAsyncIndexes < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - def up - prepare_async_index :ci_builds_metadata, :id_convert_to_bigint, unique: true, - name: :index_ci_builds_metadata_on_id_convert_to_bigint - - prepare_async_index :ci_builds_metadata, :build_id_convert_to_bigint, unique: true, - name: :index_ci_builds_metadata_on_build_id_convert_to_bigint - - prepare_async_index :ci_builds_metadata, :build_id_convert_to_bigint, where: 'has_exposed_artifacts IS TRUE', - name: :index_ci_builds_metadata_on_build_id_int8_and_exposed_artifacts - - prepare_async_index_from_sql(:ci_builds_metadata, :index_ci_builds_metadata_on_build_id_int8_where_interruptible, <<~SQL.squish) - CREATE INDEX CONCURRENTLY "index_ci_builds_metadata_on_build_id_int8_where_interruptible" - ON "ci_builds_metadata" ("build_id_convert_to_bigint") INCLUDE ("id_convert_to_bigint") - WHERE interruptible = true - SQL - - prepare_async_index :ci_builds, :id_convert_to_bigint, unique: true, - name: :index_ci_builds_on_converted_id - end - - def down - unprepare_async_index_by_name :ci_builds, :index_ci_builds_on_converted_id - - unprepare_async_index_by_name :ci_builds_metadata, :index_ci_builds_metadata_on_build_id_int8_where_interruptible - - unprepare_async_index_by_name :ci_builds_metadata, :index_ci_builds_metadata_on_build_id_int8_and_exposed_artifacts - - unprepare_async_index_by_name :ci_builds_metadata, :index_ci_builds_metadata_on_build_id_convert_to_bigint - - unprepare_async_index_by_name :ci_builds_metadata, :index_ci_builds_metadata_on_id_convert_to_bigint - end - - private - - def prepare_async_index_from_sql(table_name, index_name, definition) - return unless async_index_creation_available? - - return if index_name_exists?(table_name, index_name) - - async_index = Gitlab::Database::AsyncIndexes::PostgresAsyncIndex.find_or_create_by!(name: index_name) do |rec| - rec.table_name = table_name - rec.definition = definition - end - - Gitlab::AppLogger.info( - message: 'Prepared index for async creation', - table_name: async_index.table_name, - index_name: async_index.name) - end -end diff --git a/db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb b/db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb deleted file mode 100644 index d892e6897af..00000000000 --- a/db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class CleanupRemainingOrphanInvites < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - TMP_INDEX_NAME = 'tmp_idx_members_with_orphaned_invites' - - QUERY_CONDITION = "invite_token IS NOT NULL AND user_id IS NOT NULL" - - def up - membership = define_batchable_model('members') - - add_concurrent_index :members, :id, where: QUERY_CONDITION, name: TMP_INDEX_NAME - - membership.where(QUERY_CONDITION).pluck(:id).each_slice(10) do |group| - membership.where(id: group).where(QUERY_CONDITION).update_all(invite_token: nil) - end - - remove_concurrent_index_by_name :members, TMP_INDEX_NAME - end - - def down - remove_concurrent_index_by_name :members, TMP_INDEX_NAME if index_exists_by_name?(:members, TMP_INDEX_NAME) - end -end diff --git a/db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb b/db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb deleted file mode 100644 index 4d8e18ba8ed..00000000000 --- a/db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class RemoveDuplicateDastSiteTokensWithSameToken < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - INDEX_NAME = 'index_dast_site_token_on_token' - - # rubocop: disable Migration/AddIndex - def up - execute("WITH duplicate_tokens AS( - SELECT id, rank() OVER (PARTITION BY token ORDER BY id) r FROM dast_site_tokens - ) - DELETE FROM dast_site_tokens c USING duplicate_tokens t - WHERE c.id = t.id AND t.r > 1;") - - add_index :dast_site_tokens, :token, name: INDEX_NAME, unique: true - end - - # rubocop: disable Migration/RemoveIndex - def down - remove_index :dast_site_tokens, :token, name: INDEX_NAME - end -end diff --git a/db/post_migrate/20210825193548_add_fk_to_iteration_cadence_id_on_boards.rb b/db/post_migrate/20210825193548_add_fk_to_iteration_cadence_id_on_boards.rb deleted file mode 100644 index eb879d9bc7a..00000000000 --- a/db/post_migrate/20210825193548_add_fk_to_iteration_cadence_id_on_boards.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class AddFkToIterationCadenceIdOnBoards < Gitlab::Database::Migration[1.0] - disable_ddl_transaction! - - INDEX_NAME = 'index_boards_on_iteration_cadence_id' - - def up - add_concurrent_index :boards, :iteration_cadence_id, name: INDEX_NAME - add_concurrent_foreign_key :boards, :iterations_cadences, column: :iteration_cadence_id - end - - def down - with_lock_retries do - remove_foreign_key_if_exists :boards, column: :iteration_cadence_id - end - remove_concurrent_index_by_name :boards, INDEX_NAME - end -end diff --git a/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb b/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb deleted file mode 100644 index 1f6650140d4..00000000000 --- a/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -class BackfillCadenceIdForBoardsScopedToIteration < Gitlab::Database::Migration[1.0] - disable_ddl_transaction! - - BATCH_SIZE = 1000 - DELAY = 2.minutes.to_i - MIGRATION = 'BackfillIterationCadenceIdForBoards' - - class MigrationBoard < ApplicationRecord - include EachBatch - - self.table_name = 'boards' - end - - def up - schedule_backfill_group_boards - schedule_backfill_project_boards - end - - def down - MigrationBoard.where.not(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pick(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')) - delay = index * DELAY - - migrate_in(delay, MIGRATION, ['none', 'down', *range]) - end - end - - private - - def schedule_backfill_project_boards - MigrationBoard.where(iteration_id: -4).where.not(project_id: nil).where(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pick(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')) - delay = index * DELAY - - migrate_in(delay, MIGRATION, ['project', 'up', *range]) - end - end - - def schedule_backfill_group_boards - MigrationBoard.where(iteration_id: -4).where.not(group_id: nil).where(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index| - range = batch.pick(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')) - delay = index * DELAY - - migrate_in(delay, MIGRATION, ['group', 'up', *range]) - end - end -end diff --git a/db/post_migrate/20210826110839_prepare_indexes_for_ci_job_artifacts_expire_at_unlocked.rb b/db/post_migrate/20210826110839_prepare_indexes_for_ci_job_artifacts_expire_at_unlocked.rb deleted file mode 100644 index e11bb25d83c..00000000000 --- a/db/post_migrate/20210826110839_prepare_indexes_for_ci_job_artifacts_expire_at_unlocked.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class PrepareIndexesForCiJobArtifactsExpireAtUnlocked < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - TABLE_NAME = 'ci_job_artifacts' - INDEX_NAME = 'ci_job_artifacts_expire_at_unlocked_idx' - - def up - prepare_async_index TABLE_NAME, [:expire_at], where: 'locked = 0', name: INDEX_NAME - end - - def down - unprepare_async_index_by_name TABLE_NAME, INDEX_NAME - end -end diff --git a/db/post_migrate/20210826171758_initialize_throttle_unauthenticated_api_columns.rb b/db/post_migrate/20210826171758_initialize_throttle_unauthenticated_api_columns.rb deleted file mode 100644 index 7615931464b..00000000000 --- a/db/post_migrate/20210826171758_initialize_throttle_unauthenticated_api_columns.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# Initialize the new `throttle_unauthenticated_api_*` columns with the current values -# from the `throttle_unauthenticated_*` columns, which will now only apply to web requests. -# -# The columns for the unauthenticated web rate limit will be renamed later -# in https://gitlab.com/gitlab-org/gitlab/-/issues/340031. -class InitializeThrottleUnauthenticatedApiColumns < ActiveRecord::Migration[6.1] - class ApplicationSetting < ActiveRecord::Base - self.table_name = :application_settings - end - - def up - ApplicationSetting.update_all(%q{ - throttle_unauthenticated_api_enabled = throttle_unauthenticated_enabled, - throttle_unauthenticated_api_requests_per_period = throttle_unauthenticated_requests_per_period, - throttle_unauthenticated_api_period_in_seconds = throttle_unauthenticated_period_in_seconds - }) - end - - def down - end -end diff --git a/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb b/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb index 37e6a21abed..a576f9e860f 100644 --- a/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb +++ b/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb @@ -4,6 +4,8 @@ class TruncateTimelineEventTagsTable < Gitlab::Database::Migration[2.0] disable_ddl_transaction! def up + return unless Gitlab::Database.gitlab_schemas_for_connection(connection).include?(:gitlab_main) + execute('TRUNCATE TABLE incident_management_timeline_event_tags, incident_management_timeline_event_tag_links') end diff --git a/db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb b/db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb index f98be3f036f..d409a4dfdd1 100644 --- a/db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb +++ b/db/post_migrate/20221110045406_sanitize_confidential_note_todos.rb @@ -3,29 +3,13 @@ class SanitizeConfidentialNoteTodos < Gitlab::Database::Migration[2.0] restrict_gitlab_migration gitlab_schema: :gitlab_main - MIGRATION = 'SanitizeConfidentialTodos' - DELAY_INTERVAL = 2.minutes.to_i - BATCH_SIZE = 200 - MAX_BATCH_SIZE = 1000 - SUB_BATCH_SIZE = 20 - - disable_ddl_transaction! - restrict_gitlab_migration gitlab_schema: :gitlab_main - def up - queue_batched_background_migration( - MIGRATION, - :notes, - :id, - job_interval: DELAY_INTERVAL, - batch_size: BATCH_SIZE, - max_batch_size: MAX_BATCH_SIZE, - sub_batch_size: SUB_BATCH_SIZE, - gitlab_schema: :gitlab_main - ) + # no-op: this empty migration is left here only for compatibility reasons. + # It was a temporary migration which used not-isolated code. + # https://gitlab.com/gitlab-org/gitlab/-/issues/382557 end def down - delete_batched_background_migration(MIGRATION, :notes, :id, []) + # no-op end end diff --git a/db/post_migrate/20221116134611_add_namespaces_emails_enabled_column_data.rb b/db/post_migrate/20221116134611_add_namespaces_emails_enabled_column_data.rb new file mode 100644 index 00000000000..e3efc18f3fd --- /dev/null +++ b/db/post_migrate/20221116134611_add_namespaces_emails_enabled_column_data.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true +class AddNamespacesEmailsEnabledColumnData < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + MIGRATION = 'AddNamespacesEmailsEnabledColumnData' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 200 + MAX_BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 20 + + def up + queue_batched_background_migration( + MIGRATION, + :namespaces, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE, + gitlab_schema: :gitlab_main + ) + end + + def down + delete_batched_background_migration(MIGRATION, :namespaces, :id, []) + end +end diff --git a/db/post_migrate/20221116134633_add_projects_emails_enabled_column_data.rb b/db/post_migrate/20221116134633_add_projects_emails_enabled_column_data.rb new file mode 100644 index 00000000000..9f0edbd0707 --- /dev/null +++ b/db/post_migrate/20221116134633_add_projects_emails_enabled_column_data.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true +class AddProjectsEmailsEnabledColumnData < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + MIGRATION = 'AddProjectsEmailsEnabledColumnData' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 200 + MAX_BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 20 + + def up + queue_batched_background_migration( + MIGRATION, + :projects, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE, + gitlab_schema: :gitlab_main + ) + end + + def down + delete_batched_background_migration(MIGRATION, :projects, :id, []) + end +end diff --git a/db/post_migrate/20230104222438_add_partition_index_to_builds_metadata.rb b/db/post_migrate/20230104222438_add_partition_index_to_builds_metadata.rb new file mode 100644 index 00000000000..474f6f8540b --- /dev/null +++ b/db/post_migrate/20230104222438_add_partition_index_to_builds_metadata.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddPartitionIndexToBuildsMetadata < Gitlab::Database::Migration[2.1] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'p_ci_builds_metadata_on_runner_machine_id_idx' + + def up + add_concurrent_partitioned_index :p_ci_builds_metadata, :runner_machine_id, name: INDEX_NAME, + where: 'runner_machine_id IS NOT NULL' + end + + def down + remove_concurrent_partitioned_index_by_name :p_ci_builds_metadata, INDEX_NAME + end +end diff --git a/db/post_migrate/20230104222514_add_foreign_key_to_builds_metadata.rb b/db/post_migrate/20230104222514_add_foreign_key_to_builds_metadata.rb new file mode 100644 index 00000000000..b9c78e4eeb9 --- /dev/null +++ b/db/post_migrate/20230104222514_add_foreign_key_to_builds_metadata.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddForeignKeyToBuildsMetadata < Gitlab::Database::Migration[2.1] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_partitioned_foreign_key :p_ci_builds_metadata, + :ci_runner_machines, + column: :runner_machine_id, + on_delete: :nullify + end + + def down + remove_foreign_key_if_exists :p_ci_builds_metadata, column: :runner_machine_id + end +end diff --git a/db/post_migrate/20230109100044_cleanup_web_hook_calls_column_rename.rb b/db/post_migrate/20230109100044_cleanup_web_hook_calls_column_rename.rb new file mode 100644 index 00000000000..eca75bff199 --- /dev/null +++ b/db/post_migrate/20230109100044_cleanup_web_hook_calls_column_rename.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CleanupWebHookCallsColumnRename < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + # noop, related incident: https://gitlab.com/gitlab-com/gl-infra/production/-/issues/8264 + end + + def down + undo_cleanup_concurrent_column_rename :plan_limits, :web_hook_calls, :web_hook_calls_high + end +end diff --git a/db/post_migrate/20230109144915_remove_push_rules_application_settings_push_rule_id_fk.rb b/db/post_migrate/20230109144915_remove_push_rules_application_settings_push_rule_id_fk.rb new file mode 100644 index 00000000000..7ac492a6e62 --- /dev/null +++ b/db/post_migrate/20230109144915_remove_push_rules_application_settings_push_rule_id_fk.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemovePushRulesApplicationSettingsPushRuleIdFk < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + return unless foreign_key_exists?(:application_settings, :push_rules, name: "fk_693b8795e4") + + with_lock_retries do + execute('LOCK push_rules, application_settings IN ACCESS EXCLUSIVE MODE') if transaction_open? + + remove_foreign_key_if_exists(:application_settings, :push_rules, name: "fk_693b8795e4") + end + end + + def down + add_concurrent_foreign_key(:application_settings, :push_rules, + name: "fk_693b8795e4", column: :push_rule_id, + target_column: :id, on_delete: :nullify) + end +end diff --git a/db/post_migrate/20230109144928_remove_users_application_settings_usage_stats_set_by_user_id_fk.rb b/db/post_migrate/20230109144928_remove_users_application_settings_usage_stats_set_by_user_id_fk.rb new file mode 100644 index 00000000000..a8b9b48dbc7 --- /dev/null +++ b/db/post_migrate/20230109144928_remove_users_application_settings_usage_stats_set_by_user_id_fk.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveUsersApplicationSettingsUsageStatsSetByUserIdFk < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + return unless foreign_key_exists?(:application_settings, :users, name: "fk_964370041d") + + with_lock_retries do + execute('LOCK users, application_settings IN ACCESS EXCLUSIVE MODE') if transaction_open? + + remove_foreign_key_if_exists(:application_settings, :users, name: "fk_964370041d") + end + end + + def down + add_concurrent_foreign_key(:application_settings, :users, + name: "fk_964370041d", column: :usage_stats_set_by_user_id, + target_column: :id, on_delete: :nullify) + end +end diff --git a/db/post_migrate/20230109144941_remove_namespaces_application_settings_instance_administrators_group_id_fk.rb b/db/post_migrate/20230109144941_remove_namespaces_application_settings_instance_administrators_group_id_fk.rb new file mode 100644 index 00000000000..82f0d8a2e47 --- /dev/null +++ b/db/post_migrate/20230109144941_remove_namespaces_application_settings_instance_administrators_group_id_fk.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveNamespacesApplicationSettingsInstanceAdministratorsGroupIdFk < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + return unless foreign_key_exists?(:application_settings, :namespaces, name: "fk_e8a145f3a7") + + with_lock_retries do + execute('LOCK namespaces, application_settings IN ACCESS EXCLUSIVE MODE') if transaction_open? + + remove_foreign_key_if_exists(:application_settings, :namespaces, name: "fk_e8a145f3a7") + end + end + + def down + add_concurrent_foreign_key(:application_settings, :namespaces, + name: "fk_e8a145f3a7", column: :instance_administrators_group_id, + target_column: :id, on_delete: :nullify) + end +end diff --git a/db/post_migrate/20230109144953_remove_projects_application_settings_file_template_project_id_fk.rb b/db/post_migrate/20230109144953_remove_projects_application_settings_file_template_project_id_fk.rb new file mode 100644 index 00000000000..8527930e5a7 --- /dev/null +++ b/db/post_migrate/20230109144953_remove_projects_application_settings_file_template_project_id_fk.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveProjectsApplicationSettingsFileTemplateProjectIdFk < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + return unless foreign_key_exists?(:application_settings, :projects, name: "fk_ec757bd087") + + with_lock_retries do + execute('LOCK projects, application_settings IN ACCESS EXCLUSIVE MODE') if transaction_open? + + remove_foreign_key_if_exists(:application_settings, :projects, name: "fk_ec757bd087") + end + end + + def down + add_concurrent_foreign_key(:application_settings, :projects, + name: "fk_ec757bd087", column: :file_template_project_id, + target_column: :id, on_delete: :nullify) + end +end diff --git a/db/post_migrate/20230109145005_remove_projects_application_settings_instance_administration_project_id_fk.rb b/db/post_migrate/20230109145005_remove_projects_application_settings_instance_administration_project_id_fk.rb new file mode 100644 index 00000000000..e91769a90bb --- /dev/null +++ b/db/post_migrate/20230109145005_remove_projects_application_settings_instance_administration_project_id_fk.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveProjectsApplicationSettingsInstanceAdministrationProjectIdFk < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + return unless foreign_key_exists?(:application_settings, :projects, name: "fk_rails_7e112a9599") + + with_lock_retries do + execute('LOCK projects, application_settings IN ACCESS EXCLUSIVE MODE') if transaction_open? + + remove_foreign_key_if_exists(:application_settings, :projects, name: "fk_rails_7e112a9599") + end + end + + def down + add_concurrent_foreign_key(:application_settings, :projects, + name: "fk_rails_7e112a9599", column: :instance_administration_project_id, + target_column: :id, on_delete: :nullify) + end +end diff --git a/db/post_migrate/20230109145018_remove_namespaces_application_settings_custom_project_templates_group_id_fk.rb b/db/post_migrate/20230109145018_remove_namespaces_application_settings_custom_project_templates_group_id_fk.rb new file mode 100644 index 00000000000..cfc915f57b4 --- /dev/null +++ b/db/post_migrate/20230109145018_remove_namespaces_application_settings_custom_project_templates_group_id_fk.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveNamespacesApplicationSettingsCustomProjectTemplatesGroupIdFk < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + return unless foreign_key_exists?(:application_settings, :namespaces, name: "fk_rails_b53e481273") + + with_lock_retries do + execute('LOCK namespaces, application_settings IN ACCESS EXCLUSIVE MODE') if transaction_open? + + remove_foreign_key_if_exists(:application_settings, :namespaces, name: "fk_rails_b53e481273") + end + end + + def down + add_concurrent_foreign_key(:application_settings, :namespaces, + name: "fk_rails_b53e481273", column: :custom_project_templates_group_id, + target_column: :id, on_delete: :nullify) + end +end diff --git a/db/post_migrate/20230112051854_add_not_null_constraint_to_o_auth_access_tokens_expires_in.rb b/db/post_migrate/20230112051854_add_not_null_constraint_to_o_auth_access_tokens_expires_in.rb new file mode 100644 index 00000000000..21028993f5d --- /dev/null +++ b/db/post_migrate/20230112051854_add_not_null_constraint_to_o_auth_access_tokens_expires_in.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddNotNullConstraintToOAuthAccessTokensExpiresIn < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + # validate: false ensures that existing records are not affected + # https://docs.gitlab.com/ee/development/database/not_null_constraints.html#prevent-new-invalid-records-current-release + add_not_null_constraint :oauth_access_tokens, :expires_in, validate: false + change_column_default :oauth_access_tokens, :expires_in, 7200 + end + + def down + remove_not_null_constraint :oauth_access_tokens, :expires_in + change_column_default :oauth_access_tokens, :expires_in, nil + end +end diff --git a/db/post_migrate/20230112141236_schedule_vulnerabilities_feedback_migration2.rb b/db/post_migrate/20230112141236_schedule_vulnerabilities_feedback_migration2.rb new file mode 100644 index 00000000000..7d8cba96a91 --- /dev/null +++ b/db/post_migrate/20230112141236_schedule_vulnerabilities_feedback_migration2.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ScheduleVulnerabilitiesFeedbackMigration2 < Gitlab::Database::Migration[2.1] + MIGRATION = 'MigrateVulnerabilitiesFeedbackToVulnerabilitiesStateTransition' + TABLE_NAME = :vulnerability_feedback + BATCH_COLUMN = :id + DELAY_INTERVAL = 5.minutes + BATCH_SIZE = 250 + MAX_BATCH_SIZE = 250 + SUB_BATCH_SIZE = 50 + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + # rescheduled by 20230203122602_schedule_vulnerabilities_feedback_migration3.rb + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20230112144946_add_tmp_index_to_ci_build_need.rb b/db/post_migrate/20230112144946_add_tmp_index_to_ci_build_need.rb new file mode 100644 index 00000000000..d1e0ae6665f --- /dev/null +++ b/db/post_migrate/20230112144946_add_tmp_index_to_ci_build_need.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddTmpIndexToCiBuildNeed < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_build_needs_on_partition_id_and_id + TABLE_NAME = :ci_build_needs + + def up + return unless Gitlab.com? + + prepare_async_index(TABLE_NAME, [:partition_id, :id], where: 'partition_id = 101', name: INDEX_NAME) + end + + def down + return unless Gitlab.com? + + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230112145326_add_tmp_index_to_ci_pipeline_variable.rb b/db/post_migrate/20230112145326_add_tmp_index_to_ci_pipeline_variable.rb new file mode 100644 index 00000000000..920b70765cc --- /dev/null +++ b/db/post_migrate/20230112145326_add_tmp_index_to_ci_pipeline_variable.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddTmpIndexToCiPipelineVariable < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_pipeline_variables_on_partition_id_and_id + TABLE_NAME = :ci_pipeline_variables + + def up + return unless Gitlab.com? + + prepare_async_index(TABLE_NAME, [:partition_id, :id], where: 'partition_id = 101', name: INDEX_NAME) + end + + def down + return unless Gitlab.com? + + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230116160904_remove_user_details_fields_from_user.rb b/db/post_migrate/20230116160904_remove_user_details_fields_from_user.rb new file mode 100644 index 00000000000..8842f75e691 --- /dev/null +++ b/db/post_migrate/20230116160904_remove_user_details_fields_from_user.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class RemoveUserDetailsFieldsFromUser < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def change + %i[linkedin twitter skype website_url].each do |column| + remove_column :users, column, :string, null: false, default: '' + end + %i[location organization].each do |column| + remove_column :users, column, :string, null: true + end + end +end diff --git a/db/post_migrate/20230117092947_add_tmp_index_to_ci_build_report_results.rb b/db/post_migrate/20230117092947_add_tmp_index_to_ci_build_report_results.rb new file mode 100644 index 00000000000..a116562e9ec --- /dev/null +++ b/db/post_migrate/20230117092947_add_tmp_index_to_ci_build_report_results.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddTmpIndexToCiBuildReportResults < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_build_report_results_on_partition_id_and_id + TABLE_NAME = :ci_build_report_results + + def up + return unless Gitlab.com? + + prepare_async_index(TABLE_NAME, [:partition_id, :id], where: 'partition_id = 101', name: INDEX_NAME) + end + + def down + return unless Gitlab.com? + + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230117093222_add_tmp_index_to_ci_builds_on_partition_id.rb b/db/post_migrate/20230117093222_add_tmp_index_to_ci_builds_on_partition_id.rb new file mode 100644 index 00000000000..3a40e636ef9 --- /dev/null +++ b/db/post_migrate/20230117093222_add_tmp_index_to_ci_builds_on_partition_id.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddTmpIndexToCiBuildsOnPartitionId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_builds_on_partition_id_and_id + + def up + return unless Gitlab.com? + + prepare_async_index :ci_builds, [:partition_id, :id], name: INDEX_NAME, where: 'partition_id = 101' + end + + def down + return unless Gitlab.com? + + unprepare_async_index :ci_builds, [:partition_id, :id], name: INDEX_NAME, where: 'partition_id = 101' + end +end diff --git a/db/post_migrate/20230117093736_add_tmp_index_to_ci_pipelines_on_partition_id.rb b/db/post_migrate/20230117093736_add_tmp_index_to_ci_pipelines_on_partition_id.rb new file mode 100644 index 00000000000..a8e5da592af --- /dev/null +++ b/db/post_migrate/20230117093736_add_tmp_index_to_ci_pipelines_on_partition_id.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddTmpIndexToCiPipelinesOnPartitionId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_pipelines_on_partition_id_and_id + + def up + return unless Gitlab.com? + + prepare_async_index :ci_pipelines, [:partition_id, :id], name: INDEX_NAME, where: 'partition_id = 101' + end + + def down + return unless Gitlab.com? + + unprepare_async_index :ci_pipelines, [:partition_id, :id], name: INDEX_NAME, where: 'partition_id = 101' + end +end diff --git a/db/post_migrate/20230117093924_add_tmp_index_to_ci_stages_on_partition_id.rb b/db/post_migrate/20230117093924_add_tmp_index_to_ci_stages_on_partition_id.rb new file mode 100644 index 00000000000..33273ee2ba4 --- /dev/null +++ b/db/post_migrate/20230117093924_add_tmp_index_to_ci_stages_on_partition_id.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddTmpIndexToCiStagesOnPartitionId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_stages_on_partition_id_and_id + + def up + return unless Gitlab.com? + + prepare_async_index :ci_stages, [:partition_id, :id], name: INDEX_NAME, where: 'partition_id = 101' + end + + def down + return unless Gitlab.com? + + unprepare_async_index :ci_stages, [:partition_id, :id], name: INDEX_NAME, where: 'partition_id = 101' + end +end diff --git a/db/post_migrate/20230117094111_prepare_tmp_index_to_ci_build_trace_metadata.rb b/db/post_migrate/20230117094111_prepare_tmp_index_to_ci_build_trace_metadata.rb new file mode 100644 index 00000000000..93356b4eb3f --- /dev/null +++ b/db/post_migrate/20230117094111_prepare_tmp_index_to_ci_build_trace_metadata.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class PrepareTmpIndexToCiBuildTraceMetadata < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_build_trace_metadata_on_partition_id_and_id + TABLE_NAME = :ci_build_trace_metadata + + def up + return unless Gitlab.com? + + prepare_async_index(TABLE_NAME, [:partition_id, :build_id], where: 'partition_id = 101', name: INDEX_NAME) + end + + def down + return unless Gitlab.com? + + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230117094226_prepare_tmp_index_to_ci_job_artifact.rb b/db/post_migrate/20230117094226_prepare_tmp_index_to_ci_job_artifact.rb new file mode 100644 index 00000000000..db0c51e4cfd --- /dev/null +++ b/db/post_migrate/20230117094226_prepare_tmp_index_to_ci_job_artifact.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class PrepareTmpIndexToCiJobArtifact < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_job_artifacts_on_partition_id_and_id + TABLE_NAME = :ci_job_artifacts + + def up + return unless Gitlab.com? + + prepare_async_index(TABLE_NAME, [:partition_id, :id], where: 'partition_id = 101', name: INDEX_NAME) + end + + def down + return unless Gitlab.com? + + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230117094316_add_tmp_index_to_ci_job_variable.rb b/db/post_migrate/20230117094316_add_tmp_index_to_ci_job_variable.rb new file mode 100644 index 00000000000..96de0c9fed1 --- /dev/null +++ b/db/post_migrate/20230117094316_add_tmp_index_to_ci_job_variable.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddTmpIndexToCiJobVariable < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_job_variables_on_partition_id_and_id + TABLE_NAME = :ci_job_variables + + def up + return unless Gitlab.com? + + add_concurrent_index(TABLE_NAME, [:partition_id, :id], where: 'partition_id = 101', name: INDEX_NAME) + end + + def down + return unless Gitlab.com? + + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230117114739_clear_duplicate_jobs_cookies.rb b/db/post_migrate/20230117114739_clear_duplicate_jobs_cookies.rb new file mode 100644 index 00000000000..ce587e6c902 --- /dev/null +++ b/db/post_migrate/20230117114739_clear_duplicate_jobs_cookies.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# This is workaround for +# https://gitlab.com/gitlab-org/gitlab/-/issues/388253. During a +# zero-downtime upgrade, duplicate jobs cookies can fail to get deleted. +# This post-deployment migration deletes all such cookies. This can +# cause some jobs that normally would have been deduplicated to twice +# instead of once. +class ClearDuplicateJobsCookies < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + Gitlab::Redis::Queues.with do |redis| # rubocop:disable Cop/RedisQueueUsage + redis.scan_each(match: "resque:gitlab:duplicate:*:cookie:v2").each_slice(100) do |keys| + redis.del(keys) + end + end + end + + def down; end +end diff --git a/db/post_migrate/20230118083437_redefine_foreign_key_on_ci_unit_test_failure.rb b/db/post_migrate/20230118083437_redefine_foreign_key_on_ci_unit_test_failure.rb new file mode 100644 index 00000000000..220da0908a9 --- /dev/null +++ b/db/post_migrate/20230118083437_redefine_foreign_key_on_ci_unit_test_failure.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +class RedefineForeignKeyOnCiUnitTestFailure < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_unit_test_failures + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + OLD_FK_NAME = :fk_0f09856e1f_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: new_foreign_key_name, + on_update: :cascade + ) + + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: OLD_FK_NAME) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: OLD_FK_NAME + ) + + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: new_foreign_key_name) + end + end + + private + + def new_foreign_key_name + "#{concurrent_foreign_key_name(SOURCE_TABLE_NAME, [PARTITION_COLUMN, COLUMN])}_p" + end +end diff --git a/db/post_migrate/20230118083632_redefine_foreign_key_on_ci_build_pending_state.rb b/db/post_migrate/20230118083632_redefine_foreign_key_on_ci_build_pending_state.rb new file mode 100644 index 00000000000..002ec923989 --- /dev/null +++ b/db/post_migrate/20230118083632_redefine_foreign_key_on_ci_build_pending_state.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +class RedefineForeignKeyOnCiBuildPendingState < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_build_pending_states + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + OLD_FK_NAME = :fk_rails_0bbbfeaf9d_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: new_foreign_key_name, + on_update: :cascade + ) + + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: OLD_FK_NAME) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: OLD_FK_NAME + ) + + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: new_foreign_key_name) + end + end + + private + + def new_foreign_key_name + "#{concurrent_foreign_key_name(SOURCE_TABLE_NAME, [PARTITION_COLUMN, COLUMN])}_p" + end +end diff --git a/db/post_migrate/20230118083748_redefine_foreign_key_on_ci_build_trace_chunk.rb b/db/post_migrate/20230118083748_redefine_foreign_key_on_ci_build_trace_chunk.rb new file mode 100644 index 00000000000..3474e672dfa --- /dev/null +++ b/db/post_migrate/20230118083748_redefine_foreign_key_on_ci_build_trace_chunk.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +class RedefineForeignKeyOnCiBuildTraceChunk < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_build_trace_chunks + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + OLD_FK_NAME = :fk_rails_1013b761f2_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: new_foreign_key_name, + on_update: :cascade + ) + + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: OLD_FK_NAME) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: OLD_FK_NAME + ) + + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: new_foreign_key_name) + end + end + + private + + def new_foreign_key_name + "#{concurrent_foreign_key_name(SOURCE_TABLE_NAME, [PARTITION_COLUMN, COLUMN])}_p" + end +end diff --git a/db/post_migrate/20230119085509_add_index_to_ci_running_build.rb b/db/post_migrate/20230119085509_add_index_to_ci_running_build.rb new file mode 100644 index 00000000000..f340b78801f --- /dev/null +++ b/db/post_migrate/20230119085509_add_index_to_ci_running_build.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToCiRunningBuild < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_running_builds_on_partition_id_build_id + TABLE_NAME = :ci_running_builds + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230119085552_add_foreign_key_to_ci_running_build.rb b/db/post_migrate/20230119085552_add_foreign_key_to_ci_running_build.rb new file mode 100644 index 00000000000..94dfdc5b967 --- /dev/null +++ b/db/post_migrate/20230119085552_add_foreign_key_to_ci_running_build.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class AddForeignKeyToCiRunningBuild < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_running_builds + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_da45cfa165_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: FK_NAME, + on_update: :cascade + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME) + end + end +end diff --git a/db/post_migrate/20230119090944_add_index_to_ci_pending_build.rb b/db/post_migrate/20230119090944_add_index_to_ci_pending_build.rb new file mode 100644 index 00000000000..de58b6a0ef8 --- /dev/null +++ b/db/post_migrate/20230119090944_add_index_to_ci_pending_build.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToCiPendingBuild < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_pending_builds_on_partition_id_build_id + TABLE_NAME = :ci_pending_builds + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230119091027_add_foreign_key_to_ci_pending_build.rb b/db/post_migrate/20230119091027_add_foreign_key_to_ci_pending_build.rb new file mode 100644 index 00000000000..9f7f807e738 --- /dev/null +++ b/db/post_migrate/20230119091027_add_foreign_key_to_ci_pending_build.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class AddForeignKeyToCiPendingBuild < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_pending_builds + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_725a2644a3_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: FK_NAME, + on_update: :cascade + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME) + end + end +end diff --git a/db/post_migrate/20230119095022_add_fk_index_to_ci_builds_runner_session_on_partition_id_and_build_id.rb b/db/post_migrate/20230119095022_add_fk_index_to_ci_builds_runner_session_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..9fee62e55f2 --- /dev/null +++ b/db/post_migrate/20230119095022_add_fk_index_to_ci_builds_runner_session_on_partition_id_and_build_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiBuildsRunnerSessionOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_builds_runner_session_on_partition_id_build_id + TABLE_NAME = :ci_builds_runner_session + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME, unique: true) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230119095023_add_fk_to_ci_builds_runner_session_on_partition_id_and_build_id.rb b/db/post_migrate/20230119095023_add_fk_to_ci_builds_runner_session_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..e3aed238e0f --- /dev/null +++ b/db/post_migrate/20230119095023_add_fk_to_ci_builds_runner_session_on_partition_id_and_build_id.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class AddFkToCiBuildsRunnerSessionOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_builds_runner_session + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_70707857d3_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :cascade, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20230119095024_validate_fk_on_ci_builds_runner_session_partition_id_and_build_id.rb b/db/post_migrate/20230119095024_validate_fk_on_ci_builds_runner_session_partition_id_and_build_id.rb new file mode 100644 index 00000000000..07402b749ea --- /dev/null +++ b/db/post_migrate/20230119095024_validate_fk_on_ci_builds_runner_session_partition_id_and_build_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class ValidateFkOnCiBuildsRunnerSessionPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + TABLE_NAME = :ci_builds_runner_session + FK_NAME = :fk_rails_70707857d3_p + COLUMNS = [:partition_id, :build_id] + + def up + validate_foreign_key(TABLE_NAME, COLUMNS, name: FK_NAME) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20230119095025_remove_fk_to_ci_builds_ci_builds_runner_session_on_build_id.rb b/db/post_migrate/20230119095025_remove_fk_to_ci_builds_ci_builds_runner_session_on_build_id.rb new file mode 100644 index 00000000000..0707114d3a5 --- /dev/null +++ b/db/post_migrate/20230119095025_remove_fk_to_ci_builds_ci_builds_runner_session_on_build_id.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class RemoveFkToCiBuildsCiBuildsRunnerSessionOnBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_builds_runner_session + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_70707857d3 + + def up + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: COLUMN, + target_column: TARGET_COLUMN, + validate: true, + reverse_lock_order: true, + on_delete: :cascade, + name: FK_NAME + ) + end +end diff --git a/db/post_migrate/20230119123256_add_fk_index_to_ci_resources_on_partition_id_and_build_id.rb b/db/post_migrate/20230119123256_add_fk_index_to_ci_resources_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..8c1b8c81235 --- /dev/null +++ b/db/post_migrate/20230119123256_add_fk_index_to_ci_resources_on_partition_id_and_build_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiResourcesOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_resources_on_partition_id_build_id + TABLE_NAME = :ci_resources + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230119123257_add_fk_to_ci_resources_on_partition_id_and_build_id.rb b/db/post_migrate/20230119123257_add_fk_to_ci_resources_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..8279def779e --- /dev/null +++ b/db/post_migrate/20230119123257_add_fk_to_ci_resources_on_partition_id_and_build_id.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class AddFkToCiResourcesOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_resources + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_e169a8e3d5_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :nullify, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME) + end + end +end diff --git a/db/post_migrate/20230119123258_validate_fk_on_ci_resources_partition_id_and_build_id.rb b/db/post_migrate/20230119123258_validate_fk_on_ci_resources_partition_id_and_build_id.rb new file mode 100644 index 00000000000..3df7f27d921 --- /dev/null +++ b/db/post_migrate/20230119123258_validate_fk_on_ci_resources_partition_id_and_build_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class ValidateFkOnCiResourcesPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + TABLE_NAME = :ci_resources + FK_NAME = :fk_e169a8e3d5_p + COLUMNS = [:partition_id, :build_id] + + def up + validate_foreign_key(TABLE_NAME, COLUMNS, name: FK_NAME) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20230119123259_remove_fk_to_ci_builds_ci_resources_on_build_id.rb b/db/post_migrate/20230119123259_remove_fk_to_ci_builds_ci_resources_on_build_id.rb new file mode 100644 index 00000000000..fcf6989f30d --- /dev/null +++ b/db/post_migrate/20230119123259_remove_fk_to_ci_builds_ci_resources_on_build_id.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RemoveFkToCiBuildsCiResourcesOnBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_resources + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_e169a8e3d5 + + def up + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: COLUMN, + target_column: TARGET_COLUMN, + validate: true, + reverse_lock_order: true, + on_delete: :nullify, + name: FK_NAME + ) + end +end diff --git a/db/post_migrate/20230119123908_add_temporary_size_index_to_package_files.rb b/db/post_migrate/20230119123908_add_temporary_size_index_to_package_files.rb new file mode 100644 index 00000000000..dbd1f2ce112 --- /dev/null +++ b/db/post_migrate/20230119123908_add_temporary_size_index_to_package_files.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddTemporarySizeIndexToPackageFiles < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'tmp_idx_package_files_on_non_zero_size' + + disable_ddl_transaction! + + def up + # Temporary index to be removed in 16.0 https://gitlab.com/gitlab-org/gitlab/-/issues/386695 + add_concurrent_index :packages_package_files, + %i[package_id size], + where: 'size IS NOT NULL', + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :packages_package_files, INDEX_NAME + end +end diff --git a/db/post_migrate/20230119123937_queue_fix_incoherent_packages_size_on_project_statistics.rb b/db/post_migrate/20230119123937_queue_fix_incoherent_packages_size_on_project_statistics.rb new file mode 100644 index 00000000000..b00888e28d5 --- /dev/null +++ b/db/post_migrate/20230119123937_queue_fix_incoherent_packages_size_on_project_statistics.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class QueueFixIncoherentPackagesSizeOnProjectStatistics < Gitlab::Database::Migration[2.1] + MIGRATION = 'FixIncoherentPackagesSizeOnProjectStatistics' + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 17000 + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + class Package < MigrationRecord + self.table_name = 'packages_packages' + end + + def up + return unless ::QueueFixIncoherentPackagesSizeOnProjectStatistics::Package.exists? + + queue_batched_background_migration( + MIGRATION, + :project_statistics, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :project_statistics, :id, []) + end +end diff --git a/db/post_migrate/20230123095023_add_scan_result_policy_id_to_software_license_policies.rb b/db/post_migrate/20230123095023_add_scan_result_policy_id_to_software_license_policies.rb new file mode 100644 index 00000000000..7f61b3bfe85 --- /dev/null +++ b/db/post_migrate/20230123095023_add_scan_result_policy_id_to_software_license_policies.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddScanResultPolicyIdToSoftwareLicensePolicies < Gitlab::Database::Migration[2.1] + INDEX_NAME = "index_software_license_policies_on_scan_result_policy_id" + + def change + # rubocop:disable Migration/AddReference + add_reference :software_license_policies, + :scan_result_policy, + foreign_key: { on_delete: :cascade }, + index: { name: INDEX_NAME }, + null: true + # rubocop:enable Migration/AddReference + end +end diff --git a/db/post_migrate/20230124101832_remove_fk_to_ci_builds_ci_unit_test_failure_on_build_id.rb b/db/post_migrate/20230124101832_remove_fk_to_ci_builds_ci_unit_test_failure_on_build_id.rb new file mode 100644 index 00000000000..943c458d0fe --- /dev/null +++ b/db/post_migrate/20230124101832_remove_fk_to_ci_builds_ci_unit_test_failure_on_build_id.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class RemoveFkToCiBuildsCiUnitTestFailureOnBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_unit_test_failures + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_0f09856e1f + + def up + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: COLUMN, + target_column: TARGET_COLUMN, + validate: true, + reverse_lock_order: true, + on_delete: :cascade, + name: FK_NAME + ) + end +end diff --git a/db/post_migrate/20230124102131_remove_fk_to_ci_builds_ci_build_pending_state_on_build_id.rb b/db/post_migrate/20230124102131_remove_fk_to_ci_builds_ci_build_pending_state_on_build_id.rb new file mode 100644 index 00000000000..a969aec0968 --- /dev/null +++ b/db/post_migrate/20230124102131_remove_fk_to_ci_builds_ci_build_pending_state_on_build_id.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class RemoveFkToCiBuildsCiBuildPendingStateOnBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_build_pending_states + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_0bbbfeaf9d + + def up + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: COLUMN, + target_column: TARGET_COLUMN, + validate: true, + reverse_lock_order: true, + on_delete: :cascade, + name: FK_NAME + ) + end +end diff --git a/db/post_migrate/20230124102222_remove_fk_to_ci_builds_ci_build_trace_chunk_on_build_id.rb b/db/post_migrate/20230124102222_remove_fk_to_ci_builds_ci_build_trace_chunk_on_build_id.rb new file mode 100644 index 00000000000..3e03b0774ee --- /dev/null +++ b/db/post_migrate/20230124102222_remove_fk_to_ci_builds_ci_build_trace_chunk_on_build_id.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class RemoveFkToCiBuildsCiBuildTraceChunkOnBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_build_trace_chunks + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_1013b761f2 + + def up + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end + + def down + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: COLUMN, + target_column: TARGET_COLUMN, + validate: true, + reverse_lock_order: true, + on_delete: :cascade, + name: FK_NAME + ) + end +end diff --git a/db/post_migrate/20230124104310_prepare_web_hook_logs_id_created_at_async_index.rb b/db/post_migrate/20230124104310_prepare_web_hook_logs_id_created_at_async_index.rb new file mode 100644 index 00000000000..ea087265c90 --- /dev/null +++ b/db/post_migrate/20230124104310_prepare_web_hook_logs_id_created_at_async_index.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class PrepareWebHookLogsIdCreatedAtAsyncIndex < Gitlab::Database::Migration[2.1] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_web_hook_logs_on_web_hook_id_and_created_at' + + def up + # Since web_hook_logs is a partitioned table, we need to prepare the index + # for each partition individually. We can't use the `prepare_async_index` + # method directly because it will try to prepare the index for the whole + # table, which will fail. + + # In a future migration after this one, we will create the index on the + # parent table itself. + each_partition(:web_hook_logs) do |partition, partition_index_name| + prepare_async_index(partition.identifier, [:web_hook_id, :created_at], + name: partition_index_name) + end + end + + def down + each_partition(:web_hook_logs) do |partition, partition_index_name| + unprepare_async_index_by_name(partition.identifier, partition_index_name) + end + end + + private + + def each_partition(table_name) + partitioned_table = find_partitioned_table(table_name) + partitioned_table.postgres_partitions.order(:name).each do |partition| + partition_index_name = generated_index_name(partition.identifier, INDEX_NAME) + + yield partition, partition_index_name + end + end +end diff --git a/db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb b/db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb new file mode 100644 index 00000000000..aaea55ce331 --- /dev/null +++ b/db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RebalancePartitionIdCiPipeline < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes + TABLE = :ci_pipelines + BATCH_SIZE = 2_000 + SUB_BATCH_SIZE = 200 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :id, []) + end +end diff --git a/db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb b/db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb new file mode 100644 index 00000000000..6165c266a82 --- /dev/null +++ b/db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RebalancePartitionIdCiBuild < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes.freeze + TABLE = :ci_builds + BATCH_SIZE = 5_000 + SUB_BATCH_SIZE = 500 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :id, []) + end +end diff --git a/db/post_migrate/20230126091522_add_unique_index_to_ci_build_pending_state.rb b/db/post_migrate/20230126091522_add_unique_index_to_ci_build_pending_state.rb new file mode 100644 index 00000000000..484b64feb97 --- /dev/null +++ b/db/post_migrate/20230126091522_add_unique_index_to_ci_build_pending_state.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddUniqueIndexToCiBuildPendingState < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + OLD_INDEX_NAME = :index_ci_build_pending_states_on_partition_id_build_id + NEW_INDEX_NAME = :unique_index_ci_build_pending_states_on_partition_id_build_id + TABLE_NAME = :ci_build_pending_states + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, name: NEW_INDEX_NAME) + + remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME) + end + + def down + add_concurrent_index(TABLE_NAME, COLUMNS, name: OLD_INDEX_NAME) + + remove_concurrent_index_by_name(TABLE_NAME, NEW_INDEX_NAME) + end +end diff --git a/db/post_migrate/20230126133531_remove_not_null_constraints_for_tables_with_schema_differences_v3.rb b/db/post_migrate/20230126133531_remove_not_null_constraints_for_tables_with_schema_differences_v3.rb new file mode 100644 index 00000000000..04ed7a7ee12 --- /dev/null +++ b/db/post_migrate/20230126133531_remove_not_null_constraints_for_tables_with_schema_differences_v3.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveNotNullConstraintsForTablesWithSchemaDifferencesV3 < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + return unless Gitlab.com? + + change_column_null :integrations, :updated_at, true + change_column_null :integrations, :created_at, true + + change_column_null :project_settings, :show_default_award_emojis, true + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20230127101834_backfill_merge_request_metrics_for_bigint_conversion.rb b/db/post_migrate/20230127101834_backfill_merge_request_metrics_for_bigint_conversion.rb new file mode 100644 index 00000000000..02ef1c230da --- /dev/null +++ b/db/post_migrate/20230127101834_backfill_merge_request_metrics_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillMergeRequestMetricsForBigintConversion < Gitlab::Database::Migration[2.1] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + TABLE = :merge_request_metrics + COLUMNS = %i[id] + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, sub_batch_size: 200) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230127115607_add_hosted_plan_id_and_trial_index_to_gitlab_subscriptions.rb b/db/post_migrate/20230127115607_add_hosted_plan_id_and_trial_index_to_gitlab_subscriptions.rb new file mode 100644 index 00000000000..1b16ac5c187 --- /dev/null +++ b/db/post_migrate/20230127115607_add_hosted_plan_id_and_trial_index_to_gitlab_subscriptions.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddHostedPlanIdAndTrialIndexToGitlabSubscriptions < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_id_and_trial' + + disable_ddl_transaction! + + def up + add_concurrent_index :gitlab_subscriptions, [:hosted_plan_id, :trial], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :gitlab_subscriptions, INDEX_NAME + end +end diff --git a/db/post_migrate/20230127123947_add_fk_index_to_ci_sources_pipelines_on_source_partition_id_and_source_job_id.rb b/db/post_migrate/20230127123947_add_fk_index_to_ci_sources_pipelines_on_source_partition_id_and_source_job_id.rb new file mode 100644 index 00000000000..f2a9d362cc4 --- /dev/null +++ b/db/post_migrate/20230127123947_add_fk_index_to_ci_sources_pipelines_on_source_partition_id_and_source_job_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiSourcesPipelinesOnSourcePartitionIdAndSourceJobId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_sources_pipelines_on_source_partition_id_source_job_id + TABLE_NAME = :ci_sources_pipelines + COLUMNS = [:source_partition_id, :source_job_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230127123948_add_fk_to_ci_sources_pipelines_on_source_partition_id_and_source_job_id.rb b/db/post_migrate/20230127123948_add_fk_to_ci_sources_pipelines_on_source_partition_id_and_source_job_id.rb new file mode 100644 index 00000000000..7adf97268ff --- /dev/null +++ b/db/post_migrate/20230127123948_add_fk_to_ci_sources_pipelines_on_source_partition_id_and_source_job_id.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class AddFkToCiSourcesPipelinesOnSourcePartitionIdAndSourceJobId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_sources_pipelines + TARGET_TABLE_NAME = :ci_builds + COLUMN = :source_job_id + TARGET_COLUMN = :id + FK_NAME = :fk_be5624bf37_p + PARTITION_COLUMN = :source_partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [:partition_id, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :cascade, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20230127125018_remove_hosted_plan_id_index_from_gitlab_subscriptions.rb b/db/post_migrate/20230127125018_remove_hosted_plan_id_index_from_gitlab_subscriptions.rb new file mode 100644 index 00000000000..6cc21920748 --- /dev/null +++ b/db/post_migrate/20230127125018_remove_hosted_plan_id_index_from_gitlab_subscriptions.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveHostedPlanIdIndexFromGitlabSubscriptions < Gitlab::Database::Migration[2.1] + OLD_INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_id' + NEW_INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_id_and_trial' + TABLE = :gitlab_subscriptions + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name TABLE, OLD_INDEX_NAME if index_exists_by_name?(TABLE, NEW_INDEX_NAME) + end + + def down + add_concurrent_index TABLE, :hosted_plan_id, name: OLD_INDEX_NAME + end +end diff --git a/db/post_migrate/20230127131835_add_application_settings_git_users_alertlist_max_usernames_constraint.rb b/db/post_migrate/20230127131835_add_application_settings_git_users_alertlist_max_usernames_constraint.rb new file mode 100644 index 00000000000..77ef7e7eba5 --- /dev/null +++ b/db/post_migrate/20230127131835_add_application_settings_git_users_alertlist_max_usernames_constraint.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddApplicationSettingsGitUsersAlertlistMaxUsernamesConstraint < Gitlab::Database::Migration[2.1] + CONSTRAINT_NAME = 'app_settings_git_rate_limit_users_alertlist_max_usernames' + + disable_ddl_transaction! + + def up + add_check_constraint :application_settings, 'CARDINALITY(git_rate_limit_users_alertlist) <= 100', CONSTRAINT_NAME + end + + def down + remove_check_constraint :application_settings, CONSTRAINT_NAME + end +end diff --git a/db/post_migrate/20230127131915_add_namespace_settings_unique_project_download_limit_alertlist_size_constraint.rb b/db/post_migrate/20230127131915_add_namespace_settings_unique_project_download_limit_alertlist_size_constraint.rb new file mode 100644 index 00000000000..0777d31aa3b --- /dev/null +++ b/db/post_migrate/20230127131915_add_namespace_settings_unique_project_download_limit_alertlist_size_constraint.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddNamespaceSettingsUniqueProjectDownloadLimitAlertlistSizeConstraint < Gitlab::Database::Migration[2.1] + CONSTRAINT_NAME = 'namespace_settings_unique_project_download_limit_alertlist_size' + + disable_ddl_transaction! + + def up + add_check_constraint :namespace_settings, + 'CARDINALITY(unique_project_download_limit_alertlist) <= 100', + CONSTRAINT_NAME + end + + def down + remove_check_constraint :namespace_settings, CONSTRAINT_NAME + end +end diff --git a/db/post_migrate/20230127151606_add_fk_index_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb b/db/post_migrate/20230127151606_add_fk_index_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..a13ba0c21fb --- /dev/null +++ b/db/post_migrate/20230127151606_add_fk_index_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiBuildTraceMetadataOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_build_trace_metadata_on_partition_id_build_id + TABLE_NAME = :ci_build_trace_metadata + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME, unique: true) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230127151607_add_fk_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb b/db/post_migrate/20230127151607_add_fk_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..389cfc6a4ec --- /dev/null +++ b/db/post_migrate/20230127151607_add_fk_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class AddFkToCiBuildTraceMetadataOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_build_trace_metadata + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_aebc78111f_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :cascade, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20230127152727_add_fk_index_to_ci_job_artifacts_on_partition_id_and_job_id.rb b/db/post_migrate/20230127152727_add_fk_index_to_ci_job_artifacts_on_partition_id_and_job_id.rb new file mode 100644 index 00000000000..66933fa600e --- /dev/null +++ b/db/post_migrate/20230127152727_add_fk_index_to_ci_job_artifacts_on_partition_id_and_job_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiJobArtifactsOnPartitionIdAndJobId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_job_artifacts_on_partition_id_job_id + TABLE_NAME = :ci_job_artifacts + COLUMNS = [:partition_id, :job_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230127152728_add_fk_to_ci_job_artifacts_on_partition_id_and_job_id.rb b/db/post_migrate/20230127152728_add_fk_to_ci_job_artifacts_on_partition_id_and_job_id.rb new file mode 100644 index 00000000000..7c7cf7861ea --- /dev/null +++ b/db/post_migrate/20230127152728_add_fk_to_ci_job_artifacts_on_partition_id_and_job_id.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class AddFkToCiJobArtifactsOnPartitionIdAndJobId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_job_artifacts + TARGET_TABLE_NAME = :ci_builds + COLUMN = :job_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_c5137cb2c1_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :cascade, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20230127153229_add_fk_index_to_ci_job_variables_on_partition_id_and_job_id.rb b/db/post_migrate/20230127153229_add_fk_index_to_ci_job_variables_on_partition_id_and_job_id.rb new file mode 100644 index 00000000000..b06da3fc933 --- /dev/null +++ b/db/post_migrate/20230127153229_add_fk_index_to_ci_job_variables_on_partition_id_and_job_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiJobVariablesOnPartitionIdAndJobId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_job_variables_on_partition_id_job_id + TABLE_NAME = :ci_job_variables + COLUMNS = [:partition_id, :job_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230127153230_add_fk_to_ci_job_variables_on_partition_id_and_job_id.rb b/db/post_migrate/20230127153230_add_fk_to_ci_job_variables_on_partition_id_and_job_id.rb new file mode 100644 index 00000000000..7a6950fa96c --- /dev/null +++ b/db/post_migrate/20230127153230_add_fk_to_ci_job_variables_on_partition_id_and_job_id.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class AddFkToCiJobVariablesOnPartitionIdAndJobId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_job_variables + TARGET_TABLE_NAME = :ci_builds + COLUMN = :job_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_fbf3b34792_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :cascade, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20230130070623_add_index_on_packages_package_file_file_name.rb b/db/post_migrate/20230130070623_add_index_on_packages_package_file_file_name.rb new file mode 100644 index 00000000000..d7b495df272 --- /dev/null +++ b/db/post_migrate/20230130070623_add_index_on_packages_package_file_file_name.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddIndexOnPackagesPackageFileFileName < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'index_packages_package_files_on_file_name' + + def up + prepare_async_index :packages_package_files, :file_name, name: INDEX_NAME, using: :gin, + opclass: { description: :gin_trgm_ops } + end + + def down + unprepare_async_index :packages_package_files, :file_name, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20230130073109_nullify_creator_id_of_orphaned_projects.rb b/db/post_migrate/20230130073109_nullify_creator_id_of_orphaned_projects.rb new file mode 100644 index 00000000000..c13c6552c8e --- /dev/null +++ b/db/post_migrate/20230130073109_nullify_creator_id_of_orphaned_projects.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class NullifyCreatorIdOfOrphanedProjects < Gitlab::Database::Migration[2.1] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 500 + MAX_BATCH_SIZE = 5000 + MIGRATION = 'NullifyCreatorIdColumnOfOrphanedProjects' + INTERVAL = 2.minutes + + def up + queue_batched_background_migration( + MIGRATION, + :projects, + :id, + job_interval: INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :projects, :id, []) + end +end diff --git a/db/post_migrate/20230130075434_schedule_tmp_index_to_ci_build_report_results.rb b/db/post_migrate/20230130075434_schedule_tmp_index_to_ci_build_report_results.rb new file mode 100644 index 00000000000..778510e9fcb --- /dev/null +++ b/db/post_migrate/20230130075434_schedule_tmp_index_to_ci_build_report_results.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class ScheduleTmpIndexToCiBuildReportResults < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :tmp_index_ci_build_report_results_on_partition_id_and_build_id + TABLE_NAME = :ci_build_report_results + + def up + return unless Gitlab.com? + + prepare_async_index(TABLE_NAME, [:partition_id, :build_id], where: 'partition_id = 101', name: INDEX_NAME) + end + + def down + return unless Gitlab.com? + + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230130084718_drop_invalid_async_index_from_postgres_async_index.rb b/db/post_migrate/20230130084718_drop_invalid_async_index_from_postgres_async_index.rb new file mode 100644 index 00000000000..ebe28eb4088 --- /dev/null +++ b/db/post_migrate/20230130084718_drop_invalid_async_index_from_postgres_async_index.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class DropInvalidAsyncIndexFromPostgresAsyncIndex < Gitlab::Database::Migration[2.1] + # rollback 20230117092947_add_tmp_index_to_ci_build_report_results.rb + disable_ddl_transaction! + + INDEX_NAME = 'tmp_index_ci_build_report_results_on_partition_id_and_id' + TABLE_NAME = 'ci_build_report_results' + + def up + return unless Gitlab.com? + + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end + + def down + return unless Gitlab.com? + + prepare_async_index(TABLE_NAME, [:partition_id, :id], where: 'partition_id = 101', name: INDEX_NAME) + end +end diff --git a/db/post_migrate/20230130102855_add_fk_index_to_ci_build_report_results_on_partition_id_and_build_id.rb b/db/post_migrate/20230130102855_add_fk_index_to_ci_build_report_results_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..4fe71ba46d9 --- /dev/null +++ b/db/post_migrate/20230130102855_add_fk_index_to_ci_build_report_results_on_partition_id_and_build_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiBuildReportResultsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_build_report_results_on_partition_id_build_id + TABLE_NAME = :ci_build_report_results + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230130102856_add_fk_to_ci_build_report_results_on_partition_id_and_build_id.rb b/db/post_migrate/20230130102856_add_fk_to_ci_build_report_results_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..ef301af2c9f --- /dev/null +++ b/db/post_migrate/20230130102856_add_fk_to_ci_build_report_results_on_partition_id_and_build_id.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class AddFkToCiBuildReportResultsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_build_report_results + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_16cb1ff064_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :cascade, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20230130103957_add_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb b/db/post_migrate/20230130103957_add_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..cea4070a8be --- /dev/null +++ b/db/post_migrate/20230130103957_add_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddFkIndexToCiBuildNeedsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_build_needs_on_partition_id_build_id + TABLE_NAME = :ci_build_needs + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230130103958_add_fk_to_ci_build_needs_on_partition_id_and_build_id.rb b/db/post_migrate/20230130103958_add_fk_to_ci_build_needs_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..46985f12ff9 --- /dev/null +++ b/db/post_migrate/20230130103958_add_fk_to_ci_build_needs_on_partition_id_and_build_id.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class AddFkToCiBuildNeedsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_build_needs + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_3cf221d4ed_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: false, + reverse_lock_order: true, + on_update: :cascade, + on_delete: :cascade, + name: FK_NAME + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20230130202201_backfill_sent_notifications_for_bigint_conversion.rb b/db/post_migrate/20230130202201_backfill_sent_notifications_for_bigint_conversion.rb new file mode 100644 index 00000000000..2c8efed8dc2 --- /dev/null +++ b/db/post_migrate/20230130202201_backfill_sent_notifications_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillSentNotificationsForBigintConversion < Gitlab::Database::Migration[2.1] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + TABLE = :sent_notifications + COLUMNS = %i[id] + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230131005411_backfill_notes_id_for_bigint_conversion.rb b/db/post_migrate/20230131005411_backfill_notes_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..b0ccc14e947 --- /dev/null +++ b/db/post_migrate/20230131005411_backfill_notes_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillNotesIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :notes + COLUMNS = %i[id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, sub_batch_size: 500) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230131194959_remove_invalid_deploy_access_level.rb b/db/post_migrate/20230131194959_remove_invalid_deploy_access_level.rb new file mode 100644 index 00000000000..57364e2200b --- /dev/null +++ b/db/post_migrate/20230131194959_remove_invalid_deploy_access_level.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class RemoveInvalidDeployAccessLevel < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + # clean up any rows with invalid access_level entries + def up + update_column_in_batches(:protected_environment_deploy_access_levels, :access_level, nil) do |table, query| + query.where( + table.grouping(table[:user_id].not_eq(nil).or(table[:group_id].not_eq(nil))) + .and(table[:access_level].not_eq(nil))) + end + end + + def down + # no-op + + # we are setting access_level to NULL if group_id or user_id are present + end +end diff --git a/db/post_migrate/20230131210921_prepare_index_for_vulnerability_reads_on_project_id_scanner_id_vulnerability_id.rb b/db/post_migrate/20230131210921_prepare_index_for_vulnerability_reads_on_project_id_scanner_id_vulnerability_id.rb new file mode 100644 index 00000000000..0ac4e805f8a --- /dev/null +++ b/db/post_migrate/20230131210921_prepare_index_for_vulnerability_reads_on_project_id_scanner_id_vulnerability_id.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class PrepareIndexForVulnerabilityReadsOnProjectIdScannerIdVulnerabilityId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = 'idx_vulnerability_reads_project_id_scanner_id_vulnerability_id' + + # Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/382625 + def up + prepare_async_index :vulnerability_reads, [:project_id, :scanner_id, :vulnerability_id], name: INDEX_NAME + end + + def down + unprepare_async_index :vulnerability_reads, [:project_id, :scanner_id, :vulnerability_id], name: INDEX_NAME + end +end diff --git a/db/post_migrate/20230201012846_backfill_todos_note_id_for_bigint_conversion.rb b/db/post_migrate/20230201012846_backfill_todos_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..a105bea13ab --- /dev/null +++ b/db/post_migrate/20230201012846_backfill_todos_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillTodosNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :todos + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, sub_batch_size: 500) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230201014238_backfill_system_note_metadata_note_id_for_bigint_conversion.rb b/db/post_migrate/20230201014238_backfill_system_note_metadata_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..df24b755b7f --- /dev/null +++ b/db/post_migrate/20230201014238_backfill_system_note_metadata_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillSystemNoteMetadataNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :system_note_metadata + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb b/db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb new file mode 100644 index 00000000000..7f90b3293d8 --- /dev/null +++ b/db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class DropWebHookCallsHighColumn < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + with_lock_retries do + if column_exists?(:plan_limits, :web_hook_calls_high) # rubocop:disable Style/IfUnlessModifier + remove_column :plan_limits, :web_hook_calls_high + end + end + end + + def down + with_lock_retries do + unless column_exists?(:plan_limits, :web_hook_calls_high) + # rubocop:disable Migration/SchemaAdditionMethodsNoPost + add_column :plan_limits, :web_hook_calls_high, :integer, default: 0 + # rubocop:enable Migration/SchemaAdditionMethodsNoPost + end + end + end +end diff --git a/db/post_migrate/20230201152525_schedule_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb b/db/post_migrate/20230201152525_schedule_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..674d92295c3 --- /dev/null +++ b/db/post_migrate/20230201152525_schedule_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ScheduleFkIndexToCiBuildNeedsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_build_needs_on_partition_id_build_id + TABLE_NAME = :ci_build_needs + COLUMNS = [:partition_id, :build_id] + + def up + prepare_async_index(TABLE_NAME, COLUMNS, name: INDEX_NAME) + end + + def down + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230201153450_add_index_on_lfs_objects_file.rb b/db/post_migrate/20230201153450_add_index_on_lfs_objects_file.rb new file mode 100644 index 00000000000..669b3faf3d6 --- /dev/null +++ b/db/post_migrate/20230201153450_add_index_on_lfs_objects_file.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddIndexOnLfsObjectsFile < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'index_lfs_objects_on_file' + + # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/390401 + def up + prepare_async_index :lfs_objects, :file, name: INDEX_NAME + end + + def down + unprepare_async_index :lfs_objects, :file, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20230201171450_finalize_backfill_environment_tier_migration.rb b/db/post_migrate/20230201171450_finalize_backfill_environment_tier_migration.rb new file mode 100644 index 00000000000..ae4062cb764 --- /dev/null +++ b/db/post_migrate/20230201171450_finalize_backfill_environment_tier_migration.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class FinalizeBackfillEnvironmentTierMigration < Gitlab::Database::Migration[2.1] + MIGRATION = 'BackfillEnvironmentTiers' + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + ensure_batched_background_migration_is_finished( + job_class_name: MIGRATION, + table_name: :environments, + column_name: :id, + job_arguments: [], + finalize: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20230202002637_backfill_epic_user_mentions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230202002637_backfill_epic_user_mentions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..1f7af1af78f --- /dev/null +++ b/db/post_migrate/20230202002637_backfill_epic_user_mentions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillEpicUserMentionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :epic_user_mentions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230202004247_add_index_on_merge_request_diffs_external_diff.rb b/db/post_migrate/20230202004247_add_index_on_merge_request_diffs_external_diff.rb new file mode 100644 index 00000000000..6f8cfced238 --- /dev/null +++ b/db/post_migrate/20230202004247_add_index_on_merge_request_diffs_external_diff.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddIndexOnMergeRequestDiffsExternalDiff < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'index_merge_request_diffs_on_external_diff' + + # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/390399 + def up + prepare_async_index :merge_request_diffs, :external_diff, name: INDEX_NAME + end + + def down + unprepare_async_index :merge_request_diffs, :external_diff, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20230202023224_backfill_suggestions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230202023224_backfill_suggestions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..c4bd2ccf0c7 --- /dev/null +++ b/db/post_migrate/20230202023224_backfill_suggestions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillSuggestionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :suggestions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230202032302_backfill_issue_user_mentions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230202032302_backfill_issue_user_mentions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..749a2f97d7c --- /dev/null +++ b/db/post_migrate/20230202032302_backfill_issue_user_mentions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillIssueUserMentionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :issue_user_mentions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, batch_size: 40_000, sub_batch_size: 500) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230202131928_encrypt_ci_trigger_token.rb b/db/post_migrate/20230202131928_encrypt_ci_trigger_token.rb new file mode 100644 index 00000000000..c1cb40d1da1 --- /dev/null +++ b/db/post_migrate/20230202131928_encrypt_ci_trigger_token.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class EncryptCiTriggerToken < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + MIGRATION = 'EncryptCiTriggerToken' + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 1_000 + MAX_BATCH_SIZE = 2_000 + SUB_BATCH_SIZE = 100 + + def up + queue_batched_background_migration( + MIGRATION, + :ci_triggers, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :ci_triggers, :id, []) + end +end diff --git a/db/post_migrate/20230203122602_schedule_vulnerabilities_feedback_migration3.rb b/db/post_migrate/20230203122602_schedule_vulnerabilities_feedback_migration3.rb new file mode 100644 index 00000000000..7fed726823b --- /dev/null +++ b/db/post_migrate/20230203122602_schedule_vulnerabilities_feedback_migration3.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ScheduleVulnerabilitiesFeedbackMigration3 < Gitlab::Database::Migration[2.1] + MIGRATION = 'MigrateVulnerabilitiesFeedbackToVulnerabilitiesStateTransition' + TABLE_NAME = :vulnerability_feedback + BATCH_COLUMN = :id + DELAY_INTERVAL = 5.minutes + BATCH_SIZE = 250 + MAX_BATCH_SIZE = 250 + SUB_BATCH_SIZE = 50 + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + # replaced by db/post_migrate/20230209171547_schedule_vulnerabilities_feedback_migration4.rb + # no-op + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20230203122609_change_pipeline_name_index.rb b/db/post_migrate/20230203122609_change_pipeline_name_index.rb new file mode 100644 index 00000000000..2f2fef82c9d --- /dev/null +++ b/db/post_migrate/20230203122609_change_pipeline_name_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class ChangePipelineNameIndex < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_pipeline_metadata_on_pipeline_id_name_lower_text_pattern' + NEW_INDEX_NAME = 'index_pipeline_metadata_on_pipeline_id_name_text_pattern' + + def up + add_concurrent_index :ci_pipeline_metadata, 'pipeline_id, name text_pattern_ops', name: NEW_INDEX_NAME + + remove_concurrent_index_by_name :ci_pipeline_metadata, OLD_INDEX_NAME + end + + def down + add_concurrent_index :ci_pipeline_metadata, 'pipeline_id, lower(name) text_pattern_ops', name: OLD_INDEX_NAME + + remove_concurrent_index_by_name :ci_pipeline_metadata, NEW_INDEX_NAME + end +end diff --git a/db/post_migrate/20230207003812_backfill_note_diff_files_diff_note_id_for_bigint_conversion.rb b/db/post_migrate/20230207003812_backfill_note_diff_files_diff_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..ce53a855b2a --- /dev/null +++ b/db/post_migrate/20230207003812_backfill_note_diff_files_diff_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillNoteDiffFilesDiffNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :note_diff_files + COLUMNS = %i[diff_note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, batch_size: 40_000) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230207005701_backfill_snippet_user_mentions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230207005701_backfill_snippet_user_mentions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..4d4c36bf8fc --- /dev/null +++ b/db/post_migrate/20230207005701_backfill_snippet_user_mentions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillSnippetUserMentionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :snippet_user_mentions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230207011414_backfill_design_user_mentions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230207011414_backfill_design_user_mentions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..6e971bad382 --- /dev/null +++ b/db/post_migrate/20230207011414_backfill_design_user_mentions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillDesignUserMentionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :design_user_mentions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230207012238_backfill_vulnerability_user_mentions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230207012238_backfill_vulnerability_user_mentions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..e6d674c09ce --- /dev/null +++ b/db/post_migrate/20230207012238_backfill_vulnerability_user_mentions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillVulnerabilityUserMentionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :vulnerability_user_mentions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230207015850_backfill_commit_user_mentions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230207015850_backfill_commit_user_mentions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..d690c00dc7c --- /dev/null +++ b/db/post_migrate/20230207015850_backfill_commit_user_mentions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillCommitUserMentionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :commit_user_mentions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230207025315_backfill_merge_request_user_mentions_note_id_for_bigint_conversion.rb b/db/post_migrate/20230207025315_backfill_merge_request_user_mentions_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..127c1c17bce --- /dev/null +++ b/db/post_migrate/20230207025315_backfill_merge_request_user_mentions_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillMergeRequestUserMentionsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :merge_request_user_mentions + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, batch_size: 30_000, sub_batch_size: 500) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230207030259_backfill_timelogs_note_id_for_bigint_conversion.rb b/db/post_migrate/20230207030259_backfill_timelogs_note_id_for_bigint_conversion.rb new file mode 100644 index 00000000000..e88b810d813 --- /dev/null +++ b/db/post_migrate/20230207030259_backfill_timelogs_note_id_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillTimelogsNoteIdForBigintConversion < Gitlab::Database::Migration[2.1] + TABLE = :timelogs + COLUMNS = %i[note_id] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230207143602_schedule_fk_index_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb b/db/post_migrate/20230207143602_schedule_fk_index_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb new file mode 100644 index 00000000000..ae51e312fc4 --- /dev/null +++ b/db/post_migrate/20230207143602_schedule_fk_index_to_ci_build_trace_metadata_on_partition_id_and_build_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ScheduleFkIndexToCiBuildTraceMetadataOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_build_trace_metadata_on_partition_id_build_id + TABLE_NAME = :ci_build_trace_metadata + COLUMNS = [:partition_id, :build_id] + + def up + prepare_async_index(TABLE_NAME, COLUMNS, name: INDEX_NAME, unique: true) + end + + def down + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230207143844_schedule_fk_index_to_ci_job_artifacts_on_partition_id_and_job_id.rb b/db/post_migrate/20230207143844_schedule_fk_index_to_ci_job_artifacts_on_partition_id_and_job_id.rb new file mode 100644 index 00000000000..c9eda410b34 --- /dev/null +++ b/db/post_migrate/20230207143844_schedule_fk_index_to_ci_job_artifacts_on_partition_id_and_job_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ScheduleFkIndexToCiJobArtifactsOnPartitionIdAndJobId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_job_artifacts_on_partition_id_job_id + TABLE_NAME = :ci_job_artifacts + COLUMNS = [:partition_id, :job_id] + + def up + prepare_async_index(TABLE_NAME, COLUMNS, name: INDEX_NAME) + end + + def down + unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb b/db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb new file mode 100644 index 00000000000..9901e6af4ae --- /dev/null +++ b/db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiPipelineVariable < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes.freeze + TABLE = :ci_pipeline_variables + BATCH_SIZE = 2_000 + SUB_BATCH_SIZE = 200 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :id, []) + end +end diff --git a/db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb b/db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb new file mode 100644 index 00000000000..d1b25639638 --- /dev/null +++ b/db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiJobArtifact < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes + TABLE = :ci_job_artifacts + BATCH_SIZE = 5_000 + SUB_BATCH_SIZE = 500 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :id, []) + end +end diff --git a/db/post_migrate/20230208110638_cleanup_ci_runner_machines_machine_xid_rename.rb b/db/post_migrate/20230208110638_cleanup_ci_runner_machines_machine_xid_rename.rb new file mode 100644 index 00000000000..b596d7773ae --- /dev/null +++ b/db/post_migrate/20230208110638_cleanup_ci_runner_machines_machine_xid_rename.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CleanupCiRunnerMachinesMachineXidRename < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + cleanup_concurrent_column_rename :ci_runner_machines, :machine_xid, :system_xid + end + + def down + undo_cleanup_concurrent_column_rename :ci_runner_machines, :machine_xid, :system_xid + end +end diff --git a/db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb b/db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb new file mode 100644 index 00000000000..c3ec614a37f --- /dev/null +++ b/db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiStage < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes.freeze + TABLE = :ci_stages + BATCH_SIZE = 3_000 + SUB_BATCH_SIZE = 300 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :id, []) + end +end diff --git a/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb b/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb new file mode 100644 index 00000000000..d21d986ee31 --- /dev/null +++ b/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiBuildReportResult < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes.freeze + TABLE = :ci_build_report_results + BATCH_SIZE = 2_000 + SUB_BATCH_SIZE = 200 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :build_id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :build_id, []) + end +end diff --git a/db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb b/db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb new file mode 100644 index 00000000000..25087dcbfa4 --- /dev/null +++ b/db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiBuildTraceMetadata < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes.freeze + TABLE = :ci_build_trace_metadata + BATCH_SIZE = 3_000 + SUB_BATCH_SIZE = 300 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :build_id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :build_id, []) + end +end diff --git a/db/post_migrate/20230209103650_add_unique_software_license_policies_index_on_project_and_scan_result_policy.rb b/db/post_migrate/20230209103650_add_unique_software_license_policies_index_on_project_and_scan_result_policy.rb new file mode 100644 index 00000000000..b3e6c42370a --- /dev/null +++ b/db/post_migrate/20230209103650_add_unique_software_license_policies_index_on_project_and_scan_result_policy.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddUniqueSoftwareLicensePoliciesIndexOnProjectAndScanResultPolicy < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'idx_software_license_policies_unique_on_project_and_scan_policy' + + disable_ddl_transaction! + + def up + add_concurrent_index :software_license_policies, + [:project_id, :software_license_id, :scan_result_policy_id], + unique: true, + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :software_license_policies, INDEX_NAME + end +end diff --git a/db/post_migrate/20230209103714_add_fk_to_approval_rules_on_scan_result_policy_id.rb b/db/post_migrate/20230209103714_add_fk_to_approval_rules_on_scan_result_policy_id.rb new file mode 100644 index 00000000000..cfc2c33b32a --- /dev/null +++ b/db/post_migrate/20230209103714_add_fk_to_approval_rules_on_scan_result_policy_id.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddFkToApprovalRulesOnScanResultPolicyId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :approval_project_rules, + :scan_result_policies, + column: :scan_result_policy_id, + on_delete: :cascade, + reverse_lock_order: true + add_concurrent_foreign_key :approval_merge_request_rules, + :scan_result_policies, + column: :scan_result_policy_id, + on_delete: :cascade, + reverse_lock_order: true + end + + def down + remove_foreign_key_if_exists :approval_project_rules, column: :scan_result_policy_id + remove_foreign_key_if_exists :approval_merge_request_rules, column: :scan_result_policy_id + end +end diff --git a/db/post_migrate/20230209123006_remove_unique_software_license_policies_index_on_project.rb b/db/post_migrate/20230209123006_remove_unique_software_license_policies_index_on_project.rb new file mode 100644 index 00000000000..5c69fc6d9fe --- /dev/null +++ b/db/post_migrate/20230209123006_remove_unique_software_license_policies_index_on_project.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveUniqueSoftwareLicensePoliciesIndexOnProject < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'index_software_license_policies_unique_per_project' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :software_license_policies, INDEX_NAME + end + + def down + add_concurrent_index :software_license_policies, [:project_id, :software_license_id], unique: true, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20230209131808_recount_epic_cache_counts_v3.rb b/db/post_migrate/20230209131808_recount_epic_cache_counts_v3.rb new file mode 100644 index 00000000000..6252a300453 --- /dev/null +++ b/db/post_migrate/20230209131808_recount_epic_cache_counts_v3.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class RecountEpicCacheCountsV3 < Gitlab::Database::Migration[2.1] + MIGRATION = 'ThirdRecountEpicCacheCounts' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 200 + MAX_BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 20 + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + queue_batched_background_migration( + MIGRATION, + :epics, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE, + gitlab_schema: :gitlab_main + ) + end + + def down + delete_batched_background_migration(MIGRATION, :epics, :id, []) + end +end diff --git a/db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb b/db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb new file mode 100644 index 00000000000..07fcbcc3ad7 --- /dev/null +++ b/db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiBuildMetadata < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes + TABLE = :p_ci_builds_metadata + BATCH_SIZE = 5_000 + SUB_BATCH_SIZE = 500 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :id, []) + end +end diff --git a/db/post_migrate/20230209171547_schedule_vulnerabilities_feedback_migration4.rb b/db/post_migrate/20230209171547_schedule_vulnerabilities_feedback_migration4.rb new file mode 100644 index 00000000000..fb2f8fd65cc --- /dev/null +++ b/db/post_migrate/20230209171547_schedule_vulnerabilities_feedback_migration4.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class ScheduleVulnerabilitiesFeedbackMigration4 < Gitlab::Database::Migration[2.1] + MIGRATION = 'MigrateVulnerabilitiesFeedbackToVulnerabilitiesStateTransition' + TABLE_NAME = :vulnerability_feedback + BATCH_COLUMN = :id + JOB_INTERVAL = 2.minutes + BATCH_SIZE = 250 + SUB_BATCH_SIZE = 5 + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + # Delete the previous jobs + delete_batched_background_migration( + MIGRATION, + TABLE_NAME, + BATCH_COLUMN, + [] + ) + + # Reschedule the migration + queue_batched_background_migration( + MIGRATION, + TABLE_NAME, + BATCH_COLUMN, + job_interval: JOB_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration( + MIGRATION, + TABLE_NAME, + BATCH_COLUMN, + [] + ) + end +end diff --git a/db/post_migrate/20230210113924_prepare_index_approval_rules_on_scan_result_policy_id.rb b/db/post_migrate/20230210113924_prepare_index_approval_rules_on_scan_result_policy_id.rb new file mode 100644 index 00000000000..5776d6f737e --- /dev/null +++ b/db/post_migrate/20230210113924_prepare_index_approval_rules_on_scan_result_policy_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class PrepareIndexApprovalRulesOnScanResultPolicyId < Gitlab::Database::Migration[2.1] + PROJECT_INDEX_NAME = 'idx_approval_project_rules_on_scan_result_policy_id' + MERGE_REQUEST_INDEX_NAME = 'idx_approval_merge_request_rules_on_scan_result_policy_id' + + # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/391312 + def up + prepare_async_index :approval_project_rules, :scan_result_policy_id, name: PROJECT_INDEX_NAME + prepare_async_index :approval_merge_request_rules, :scan_result_policy_id, name: MERGE_REQUEST_INDEX_NAME + end + + def down + unprepare_async_index :approval_project_rules, :scan_result_policy_id, name: PROJECT_INDEX_NAME + unprepare_async_index :approval_merge_request_rules, :scan_result_policy_id, name: MERGE_REQUEST_INDEX_NAME + end +end diff --git a/db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb b/db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb new file mode 100644 index 00000000000..0a201c51467 --- /dev/null +++ b/db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiJobVariables < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + BATCH_SIZE = 50 + + def up + return unless Gitlab.com? + + define_batchable_model(:ci_job_variables) + .where(partition_id: 101) + .each_batch(of: BATCH_SIZE) do |batch| + batch.update_all(partition_id: 100) + sleep 0.1 + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb b/db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb new file mode 100644 index 00000000000..c05b759c2d0 --- /dev/null +++ b/db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class FixPartitionIdsOnCiSourcesPipelines < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + BATCH_SIZE = 50 + + def up + return unless Gitlab.com? + + model = define_batchable_model(:ci_sources_pipelines) + + batch_update_records(model, :partition_id, from: 101, to: 100, source_partition_id: 100) + batch_update_records(model, :source_partition_id, from: 101, to: 100) + end + + def down + # no-op + end + + private + + def batch_update_records(model, column, from:, to:, **updates) + updates.reverse_merge!(column => to) + + model + .where(model.arel_table[column].eq(from)) + .each_batch(of: BATCH_SIZE) { |batch| update_records(batch, updates) } + end + + def update_records(relation, updates) + relation.update_all(updates) + sleep 0.1 + end +end diff --git a/db/post_migrate/20230214174335_prepare_async_index_web_hook_logs.rb b/db/post_migrate/20230214174335_prepare_async_index_web_hook_logs.rb new file mode 100644 index 00000000000..536f0750b91 --- /dev/null +++ b/db/post_migrate/20230214174335_prepare_async_index_web_hook_logs.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class PrepareAsyncIndexWebHookLogs < Gitlab::Database::Migration[2.1] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_web_hook_logs_on_web_hook_id_and_created_at' + + def up + # Since web_hook_logs is a partitioned table, we need to prepare the index + # for each partition individually. We can't use the `prepare_async_index` + # method directly because it will try to prepare the index for the whole + # table, which will fail. + + # In a future migration, we will create the index on the parent table itself. + each_partition(:web_hook_logs) do |partition, partition_index_name| + prepare_async_index(partition.identifier, [:web_hook_id, :created_at], + name: partition_index_name) + end + end + + def down + each_partition(:web_hook_logs) do |partition, partition_index_name| + unprepare_async_index_by_name(partition.identifier, partition_index_name) + end + end + + private + + def each_partition(table_name) + partitioned_table = find_partitioned_table(table_name) + partitioned_table.postgres_partitions.order(:name).each do |partition| + partition_index_name = generated_index_name(partition.identifier, INDEX_NAME) + + yield partition, partition_index_name + end + end +end diff --git a/db/post_migrate/20230216035802_prepare_async_foreign_key_validation_for_ci_build_needs.rb b/db/post_migrate/20230216035802_prepare_async_foreign_key_validation_for_ci_build_needs.rb new file mode 100644 index 00000000000..1c3215a6691 --- /dev/null +++ b/db/post_migrate/20230216035802_prepare_async_foreign_key_validation_for_ci_build_needs.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class PrepareAsyncForeignKeyValidationForCiBuildNeeds < Gitlab::Database::Migration[2.1] + TABLE_NAME = :ci_build_needs + COLUMN_NAMES = [:partition_id, :build_id] + FOREIGN_KEY_NAME = :fk_rails_3cf221d4ed_p + + def up + prepare_async_foreign_key_validation(TABLE_NAME, COLUMN_NAMES, name: FOREIGN_KEY_NAME) + end + + def down + unprepare_async_foreign_key_validation(TABLE_NAME, COLUMN_NAMES, name: FOREIGN_KEY_NAME) + end +end diff --git a/db/post_migrate/20230216052103_prepare_async_foreign_key_validation_for_ci_build_report_results.rb b/db/post_migrate/20230216052103_prepare_async_foreign_key_validation_for_ci_build_report_results.rb new file mode 100644 index 00000000000..e9add3fd2ae --- /dev/null +++ b/db/post_migrate/20230216052103_prepare_async_foreign_key_validation_for_ci_build_report_results.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class PrepareAsyncForeignKeyValidationForCiBuildReportResults < Gitlab::Database::Migration[2.1] + TABLE_NAME = :ci_build_report_results + COLUMN_NAMES = [:partition_id, :build_id] + FOREIGN_KEY_NAME = :fk_rails_16cb1ff064_p + + def up + prepare_async_foreign_key_validation(TABLE_NAME, COLUMN_NAMES, name: FOREIGN_KEY_NAME) + end + + def down + unprepare_async_foreign_key_validation(TABLE_NAME, COLUMN_NAMES, name: FOREIGN_KEY_NAME) + end +end diff --git a/db/post_migrate/20230216054348_prepare_async_foreign_key_validation_for_ci_job_artifacts.rb b/db/post_migrate/20230216054348_prepare_async_foreign_key_validation_for_ci_job_artifacts.rb new file mode 100644 index 00000000000..6d545361e10 --- /dev/null +++ b/db/post_migrate/20230216054348_prepare_async_foreign_key_validation_for_ci_job_artifacts.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class PrepareAsyncForeignKeyValidationForCiJobArtifacts < Gitlab::Database::Migration[2.1] + TABLE_NAME = :ci_job_artifacts + COLUMN_NAMES = [:partition_id, :job_id] + FOREIGN_KEY_NAME = :fk_rails_c5137cb2c1_p + + def up + prepare_async_foreign_key_validation(TABLE_NAME, COLUMN_NAMES, name: FOREIGN_KEY_NAME) + end + + def down + unprepare_async_foreign_key_validation(TABLE_NAME, COLUMN_NAMES, name: FOREIGN_KEY_NAME) + end +end |