Skip to content

Commit

Permalink
Simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Nov 7, 2024
1 parent 0988e39 commit 509eb9c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/strong_migrations/safe_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def safe_add_reference(table, reference, *args, **options)
def safe_add_foreign_key(from_table, to_table, *args, **options)
@migration.reversible do |dir|
dir.up do
if ar_version < 7.1 || !@migration.connection.foreign_key_exists?(from_table, to_table, **options.merge(validate: false))
if ar_version < 7.1 || !connection.foreign_key_exists?(from_table, to_table, **options.merge(validate: false))
@migration.add_foreign_key(from_table, to_table, *args, **options.merge(validate: false))
end
disable_transaction
Expand Down Expand Up @@ -93,11 +93,11 @@ def safe_change_column_null(add_args, validate_args, change_args, remove_args, d
end
disable_transaction

@migration.connection.begin_db_transaction
connection.begin_db_transaction
@migration.validate_check_constraint(*validate_args, **validate_options)
@migration.change_column_null(*change_args)
@migration.remove_check_constraint(*remove_args, **remove_options)
@migration.connection.commit_db_transaction
connection.commit_db_transaction
end
dir.down do
down_args = change_args.dup
Expand All @@ -111,13 +111,13 @@ def safe_change_column_null(add_args, validate_args, change_args, remove_args, d
# so just commit at start
def disable_transaction
if in_transaction? && !transaction_disabled
@migration.connection.commit_db_transaction
connection.commit_db_transaction
self.transaction_disabled = true
end
end

def in_transaction?
@migration.connection.open_transactions > 0
connection.open_transactions > 0
end
end
end

0 comments on commit 509eb9c

Please sign in to comment.