diff --git a/lib/gitlab/database/async_constraints/migration_helpers.rb b/lib/gitlab/database/async_constraints/migration_helpers.rb index 0e53b12586aac37b84c14854043b312a66ae29f5..4615ea6ee5bc8970551a460e118c786a4ec22a47 100644 --- a/lib/gitlab/database/async_constraints/migration_helpers.rb +++ b/lib/gitlab/database/async_constraints/migration_helpers.rb @@ -41,22 +41,6 @@ def unprepare_async_foreign_key_validation(table_name, column_name = nil, name: end end - def prepare_partitioned_async_foreign_key_validation(table_name, column_name = nil, name: nil) - ensure_async_constraint_validation_is_enabled do - Gitlab::Database::PostgresPartitionedTable.each_partition(table_name) do |partition| - prepare_async_foreign_key_validation(partition.identifier, column_name, name: name) - end - end - end - - def unprepare_partitioned_async_foreign_key_validation(table_name, column_name = nil, name: nil) - ensure_async_constraint_validation_is_enabled do - Gitlab::Database::PostgresPartitionedTable.each_partition(table_name) do |partition| - unprepare_async_foreign_key_validation(partition.identifier, column_name, name: name) - end - end - end - # Prepares a check constraint for asynchronous validation. # # Stores the constraint information in the postgres_async_foreign_key_validations diff --git a/lib/gitlab/database/partitioning_migration_helpers/foreign_key_helpers.rb b/lib/gitlab/database/partitioning_migration_helpers/foreign_key_helpers.rb index 67d16b48d2f715f58352e48447faea0f8ecd5e61..0cbb40f5f0d89c363ebd18827623c9b041245e46 100644 --- a/lib/gitlab/database/partitioning_migration_helpers/foreign_key_helpers.rb +++ b/lib/gitlab/database/partitioning_migration_helpers/foreign_key_helpers.rb @@ -135,6 +135,30 @@ def swap_partitioned_foreign_keys(table_name, old_foreign_key, new_foreign_key) swap_foreign_keys(partitioned_table.name, old_foreign_key, new_foreign_key) end + # Prepares a partitioned foreign key for asynchronous validation. + # + # This method prepares each partition of the table for async validation + # using the same default naming convention as add_concurrent_partitioned_foreign_key. + def prepare_partitioned_async_foreign_key_validation(table_name, column_name = nil, name: nil) + fk_name = name || concurrent_partitioned_foreign_key_name(table_name, column_name) + + Gitlab::Database::PostgresPartitionedTable.each_partition(table_name) do |partition| + prepare_async_foreign_key_validation(partition.identifier, column_name, name: fk_name) + end + end + + # Removes a partitioned foreign key from asynchronous validation. + # + # This method removes each partition of the table from async validation + # using the same default naming convention as add_concurrent_partitioned_foreign_key. + def unprepare_partitioned_async_foreign_key_validation(table_name, column_name = nil, name: nil) + fk_name = name || concurrent_partitioned_foreign_key_name(table_name, column_name) + + Gitlab::Database::PostgresPartitionedTable.each_partition(table_name) do |partition| + unprepare_async_foreign_key_validation(partition.identifier, column_name, name: fk_name) + end + end + private # Returns the name for a concurrent partitioned foreign key.