Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb')
-rw-r--r--db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb b/db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb
index a960258ff3d..a422811415b 100644
--- a/db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb
+++ b/db/post_migrate/20231025025733_swap_columns_for_ci_pipelines_pipeline_id_bigint_for_self_host.rb
@@ -10,11 +10,13 @@ class SwapColumnsForCiPipelinesPipelineIdBigintForSelfHost < Gitlab::Database::M
TRIGGER_FUNCTION_NAME = :trigger_1bd97da9c1a4
COLUMN_NAME = :auto_canceled_by_id
BIGINT_COLUMN_NAME = :auto_canceled_by_id_convert_to_bigint
- FK_NAME = :fk_262d4c2d19
- BIGINT_FK_NAME = :fk_67e4288f3a
INDEX_NAME = :index_ci_pipelines_on_auto_canceled_by_id
BIGINT_INDEX_NAME = :index_ci_pipelines_on_auto_canceled_by_id_bigint
+ class PgForeignKeys < MigrationRecord
+ self.table_name = :postgres_foreign_keys
+ end
+
def up
return if column_type_of?(:bigint)
@@ -45,10 +47,21 @@ class SwapColumnsForCiPipelinesPipelineIdBigintForSelfHost < Gitlab::Database::M
reset_trigger_function(TRIGGER_FUNCTION_NAME)
# Swap fkey constraint
- swap_foreign_keys(TABLE_NAME, FK_NAME, BIGINT_FK_NAME)
+ swap_foreign_keys(
+ TABLE_NAME,
+ foreign_key_name_for(TABLE_NAME, COLUMN_NAME),
+ foreign_key_name_for(TABLE_NAME, BIGINT_COLUMN_NAME)
+ )
# Swap index
swap_indexes(TABLE_NAME, INDEX_NAME, BIGINT_INDEX_NAME)
end
end
+
+ def foreign_key_name_for(source, column)
+ PgForeignKeys
+ .where(constrained_table_name: source)
+ .where(constrained_columns: [column])
+ .first&.name || raise("Required foreign key for #{source} #{column} is missing.")
+ end
end