From cea8e2d35d85feaa9efd370f4376b8d0219ce249 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 29 Dec 2025 21:07:01 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master [skip secret push protection] --- ...9_add_bigint_fk_for_deployment_clusters.rb | 51 +-------- ...async_bigint_fk_for_deployment_clusters.rb | 33 +----- ...5_finalize_deployment_bigint_conversion.rb | 19 ++++ ...8_create_bigint_indexes_for_deployments.rb | 102 ++++++++++++++++++ ..._bigint_fk_for_deployment_clusters_real.rb | 54 ++++++++++ ..._bigint_fk_for_deployment_clusters_real.rb | 36 +++++++ db/schema_migrations/20251222184305 | 1 + db/schema_migrations/20251222184308 | 1 + db/schema_migrations/20251224145808 | 1 + db/schema_migrations/20251224150011 | 1 + 10 files changed, 223 insertions(+), 76 deletions(-) create mode 100644 db/post_migrate/20251222184305_finalize_deployment_bigint_conversion.rb create mode 100644 db/post_migrate/20251222184308_create_bigint_indexes_for_deployments.rb create mode 100644 db/post_migrate/20251224145808_add_bigint_fk_for_deployment_clusters_real.rb create mode 100644 db/post_migrate/20251224150011_prepare_async_bigint_fk_for_deployment_clusters_real.rb create mode 100644 db/schema_migrations/20251222184305 create mode 100644 db/schema_migrations/20251222184308 create mode 100644 db/schema_migrations/20251224145808 create mode 100644 db/schema_migrations/20251224150011 diff --git a/db/post_migrate/20251222180619_add_bigint_fk_for_deployment_clusters.rb b/db/post_migrate/20251222180619_add_bigint_fk_for_deployment_clusters.rb index 38b80ad078a..e09249af8ea 100644 --- a/db/post_migrate/20251222180619_add_bigint_fk_for_deployment_clusters.rb +++ b/db/post_migrate/20251222180619_add_bigint_fk_for_deployment_clusters.rb @@ -1,54 +1,11 @@ # frozen_string_literal: true class AddBigintFkForDeploymentClusters < Gitlab::Database::Migration[2.3] - disable_ddl_transaction! milestone '18.8' - TABLE_NAME = 'deployment_clusters' - COLUMNS = %i[deployment_id cluster_id].freeze - FOREIGN_KEYS = [ - { - source_table: :deployment_clusters, - column: :deployment_id_convert_to_bigint, - target_table: :deployments, - target_column: :id_convert_to_bigint, - on_delete: :cascade, - tmp_name: :fk_rails_6359a164df_tmp - } - ].freeze - - def up - conversion_needed = COLUMNS.all? do |column| - column_exists?(TABLE_NAME, convert_to_bigint_column(column)) - end - - unless conversion_needed - say "No conversion columns found - no need to create bigint FKs" - return - end - - FOREIGN_KEYS.each do |fk| - add_concurrent_foreign_key( - fk[:source_table], - fk[:target_table], - column: fk[:column], - target_column: fk[:target_column], - name: fk[:tmp_name], - on_delete: fk[:on_delete], - validate: false, - reverse_lock_order: true - ) - end - end - - def down - FOREIGN_KEYS.each do |fk| - remove_foreign_key_if_exists( - fk[:source_table], - fk[:target_table], - name: fk[:tmp_name], - reverse_lock_order: true - ) - end + def change + # no-op duplicated in + # db/post_migrate/20251224145808_add_bigint_fk_for_deployment_clusters_real.rb + # due to https://gitlab.com/gitlab-org/gitlab/-/issues/584816#note_2973390014 end end diff --git a/db/post_migrate/20251222180622_prepare_async_bigint_fk_for_deployment_clusters.rb b/db/post_migrate/20251222180622_prepare_async_bigint_fk_for_deployment_clusters.rb index 21dc270a3e0..d896ffde1db 100644 --- a/db/post_migrate/20251222180622_prepare_async_bigint_fk_for_deployment_clusters.rb +++ b/db/post_migrate/20251222180622_prepare_async_bigint_fk_for_deployment_clusters.rb @@ -3,34 +3,9 @@ class PrepareAsyncBigintFkForDeploymentClusters < Gitlab::Database::Migration[2.3] milestone '18.8' - TABLE_NAME = 'deployment_clusters' - COLUMNS = %i[deployment_id].freeze - - def up - conversion_needed = COLUMNS.all? do |column| - column_exists?(TABLE_NAME, convert_to_bigint_column(column)) - end - - unless conversion_needed - say "No conversion columns found - no need to validate bigint FKs" - return - end - - prepare_async_foreign_key_validation(:deployment_clusters, :deployment_id_convert_to_bigint, - name: :fk_rails_6359a164df_tmp) - end - - def down - conversion_needed = COLUMNS.all? do |column| - column_exists?(TABLE_NAME, convert_to_bigint_column(column)) - end - - unless conversion_needed - say "No conversion columns found - no need to validate bigint FKs" - return - end - - unprepare_async_foreign_key_validation(:deployment_clusters, :deployment_id_convert_to_bigint, - name: :fk_rails_6359a164df_tmp) + def change + # no-op duplicated in + # db/post_migrate/20251224150011_prepare_async_bigint_fk_for_deployment_clusters_real.rb + # due to https://gitlab.com/gitlab-org/gitlab/-/issues/584816#note_2973390014 end end diff --git a/db/post_migrate/20251222184305_finalize_deployment_bigint_conversion.rb b/db/post_migrate/20251222184305_finalize_deployment_bigint_conversion.rb new file mode 100644 index 00000000000..39db7dc9f10 --- /dev/null +++ b/db/post_migrate/20251222184305_finalize_deployment_bigint_conversion.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class FinalizeDeploymentBigintConversion < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + milestone '18.8' + + COLUMNS = %i[id environment_id project_id user_id].freeze + + def up + ensure_backfill_conversion_of_integer_to_bigint_is_finished( + 'deployments', + COLUMNS + ) + end + + def down; end +end diff --git a/db/post_migrate/20251222184308_create_bigint_indexes_for_deployments.rb b/db/post_migrate/20251222184308_create_bigint_indexes_for_deployments.rb new file mode 100644 index 00000000000..3017118b95e --- /dev/null +++ b/db/post_migrate/20251222184308_create_bigint_indexes_for_deployments.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +class CreateBigintIndexesForDeployments < Gitlab::Database::Migration[2.3] + include Gitlab::Database::MigrationHelpers::ConvertToBigint + + disable_ddl_transaction! + milestone '18.8' + + TABLE_NAME = 'deployments' + BIGINT_COLUMNS = [ + :id_convert_to_bigint, + :environment_id_convert_to_bigint + ].freeze + + INDEXES = [ + { + name: 'deployment_id_pkey', + columns: [:id_convert_to_bigint], + options: { unique: true } + }, + { + name: 'index_deployments_for_visible_scope', + columns: [:environment_id_convert_to_bigint, :finished_at], + options: { order: { finished_at: :desc }, where: "status IN (1, 2, 3, 4, 6)" } + }, + { + name: 'index_deployments_on_environment_id_and_id', + columns: [:environment_id_convert_to_bigint, :id_convert_to_bigint] + }, + { + name: 'index_deployments_on_environment_id_and_ref', + columns: [:environment_id_convert_to_bigint, :ref] + }, + { + name: 'index_deployments_on_environment_id_status_and_finished_at', + columns: [:environment_id_convert_to_bigint, :status, :finished_at] + }, + { + name: 'index_deployments_on_environment_id_status_and_id', + columns: [:environment_id_convert_to_bigint, :status, :id_convert_to_bigint] + }, + { + name: 'index_deployments_on_environment_status_sha', + columns: [:environment_id_convert_to_bigint, :status, :sha] + }, + { + name: 'index_deployments_on_id_and_status_and_created_at', + columns: [:id_convert_to_bigint, :status, :created_at], + exclude_com: true + }, + { + name: 'index_deployments_on_project_and_environment_and_updated_at_id', + columns: [:project_id, :environment_id_convert_to_bigint, :updated_at, :id_convert_to_bigint] + }, + { + name: 'index_deployments_on_project_id_and_id', + columns: [:project_id, :id_convert_to_bigint], + options: { order: { id_convert_to_bigint: :desc } } + }, + { + name: 'index_deployments_on_project_id_and_updated_at_and_id', + columns: [:project_id, :updated_at, :id_convert_to_bigint], + options: { order: { updated_at: :desc, id_convert_to_bigint: :desc } } + } + ].freeze + + def up + return if skip_migration? + + INDEXES.each do |index| + next if Gitlab.com_except_jh? && index[:exclude_com] + + options = index[:options] || {} + add_concurrent_index TABLE_NAME, index[:columns], name: bigint_index_name(index[:name]), **options # rubocop:disable Migration/PreventIndexCreation -- Indexes added async already + end + end + + def down + return if skip_migration? + + INDEXES.each do |index| + next if Gitlab.com_except_jh? && index[:exclude_com] + + remove_concurrent_index_by_name TABLE_NAME, bigint_index_name(index[:name]) + end + end + + private + + def skip_migration? + unless conversion_columns_exist? + say "No conversion columns found - migration skipped" + return true + end + + false + end + + def conversion_columns_exist? + BIGINT_COLUMNS.all? { |column| column_exists?(TABLE_NAME, column) } + end +end diff --git a/db/post_migrate/20251224145808_add_bigint_fk_for_deployment_clusters_real.rb b/db/post_migrate/20251224145808_add_bigint_fk_for_deployment_clusters_real.rb new file mode 100644 index 00000000000..b0b70c6897d --- /dev/null +++ b/db/post_migrate/20251224145808_add_bigint_fk_for_deployment_clusters_real.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +class AddBigintFkForDeploymentClustersReal < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.8' + + TABLE_NAME = 'deployment_clusters' + COLUMNS = %i[deployment_id cluster_id].freeze + FOREIGN_KEYS = [ + { + source_table: :deployment_clusters, + column: :deployment_id_convert_to_bigint, + target_table: :deployments, + target_column: :id_convert_to_bigint, + on_delete: :cascade, + tmp_name: :fk_rails_6359a164df_tmp + } + ].freeze + + def up + conversion_needed = COLUMNS.all? do |column| + column_exists?(TABLE_NAME, convert_to_bigint_column(column)) + end + + unless conversion_needed + say "No conversion columns found - no need to create bigint FKs" + return + end + + FOREIGN_KEYS.each do |fk| + add_concurrent_foreign_key( + fk[:source_table], + fk[:target_table], + column: fk[:column], + target_column: fk[:target_column], + name: fk[:tmp_name], + on_delete: fk[:on_delete], + validate: false, + reverse_lock_order: true + ) + end + end + + def down + FOREIGN_KEYS.each do |fk| + remove_foreign_key_if_exists( + fk[:source_table], + fk[:target_table], + name: fk[:tmp_name], + reverse_lock_order: true + ) + end + end +end diff --git a/db/post_migrate/20251224150011_prepare_async_bigint_fk_for_deployment_clusters_real.rb b/db/post_migrate/20251224150011_prepare_async_bigint_fk_for_deployment_clusters_real.rb new file mode 100644 index 00000000000..b6b03dc6b79 --- /dev/null +++ b/db/post_migrate/20251224150011_prepare_async_bigint_fk_for_deployment_clusters_real.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class PrepareAsyncBigintFkForDeploymentClustersReal < Gitlab::Database::Migration[2.3] + milestone '18.8' + + TABLE_NAME = 'deployment_clusters' + COLUMNS = %i[deployment_id].freeze + + def up + conversion_needed = COLUMNS.all? do |column| + column_exists?(TABLE_NAME, convert_to_bigint_column(column)) + end + + unless conversion_needed + say "No conversion columns found - no need to validate bigint FKs" + return + end + + prepare_async_foreign_key_validation(:deployment_clusters, :deployment_id_convert_to_bigint, + name: :fk_rails_6359a164df_tmp) + end + + def down + conversion_needed = COLUMNS.all? do |column| + column_exists?(TABLE_NAME, convert_to_bigint_column(column)) + end + + unless conversion_needed + say "No conversion columns found - no need to validate bigint FKs" + return + end + + unprepare_async_foreign_key_validation(:deployment_clusters, :deployment_id_convert_to_bigint, + name: :fk_rails_6359a164df_tmp) + end +end diff --git a/db/schema_migrations/20251222184305 b/db/schema_migrations/20251222184305 new file mode 100644 index 00000000000..9970e4663bb --- /dev/null +++ b/db/schema_migrations/20251222184305 @@ -0,0 +1 @@ +2d191bb2a3066f7c620daf55a24474633f88d175d88f2b234e1db6ac5e96f0d9 \ No newline at end of file diff --git a/db/schema_migrations/20251222184308 b/db/schema_migrations/20251222184308 new file mode 100644 index 00000000000..739df2cafae --- /dev/null +++ b/db/schema_migrations/20251222184308 @@ -0,0 +1 @@ +14b8ebc762aea80a85ab86f7080c254349ae59da622be5f8af2c9f6a3c4a2038 \ No newline at end of file diff --git a/db/schema_migrations/20251224145808 b/db/schema_migrations/20251224145808 new file mode 100644 index 00000000000..0f8f6892f40 --- /dev/null +++ b/db/schema_migrations/20251224145808 @@ -0,0 +1 @@ +63ee9db81e3a361c92a0f2f95a7a6f8ee2db07c2c96777c46f1c615bae365750 \ No newline at end of file diff --git a/db/schema_migrations/20251224150011 b/db/schema_migrations/20251224150011 new file mode 100644 index 00000000000..352fc7b3c5d --- /dev/null +++ b/db/schema_migrations/20251224150011 @@ -0,0 +1 @@ +577cfcee15939f11a768335ba0c819a23d58d7635acde9d43cbd63c6903c3cfc \ No newline at end of file