summaryrefslogtreecommitdiff
path: root/db/post_migrate/20230130103958_add_fk_to_ci_build_needs_on_partition_id_and_build_id.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20230130103958_add_fk_to_ci_build_needs_on_partition_id_and_build_id.rb')
-rw-r--r--db/post_migrate/20230130103958_add_fk_to_ci_build_needs_on_partition_id_and_build_id.rb37
1 files changed, 37 insertions, 0 deletions
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