Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 8, 2023
1 parent 04c03a5 commit 4a525b9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/strong_migrations/safe_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ def safe_add_reference(table, reference, *args, **options)
end

def safe_add_foreign_key(from_table, to_table, *args, **options)
validate_options = options.slice(:column, :name)

@migration.reversible do |dir|
dir.up do
@migration.add_foreign_key(from_table, to_table, *args, **options.merge(validate: false))
disable_transaction
validate_options = options.slice(:column, :name)
if ActiveRecord::VERSION::MAJOR >= 6
@migration.validate_foreign_key(from_table, to_table, **validate_options)
else
@migration.validate_foreign_key(from_table, validate_options.any? ? validate_options : to_table)
end
end
dir.down do
remove_options = options.slice(:column, :name)
if ActiveRecord::VERSION::MAJOR >= 6
@migration.remove_foreign_key(from_table, to_table, **validate_options)
@migration.remove_foreign_key(from_table, to_table, **remove_options)
else
@migration.remove_foreign_key(from_table, validate_options.any? ? validate_options : to_table)
@migration.remove_foreign_key(from_table, remove_options.any? ? remove_options : to_table)
end
end
end
Expand Down

0 comments on commit 4a525b9

Please sign in to comment.