Skip to content

Commit c7f7b0a

Browse files
authored
Merge pull request rails#50198 from fatkodima/fix-duplicate-deferrable-directive
Fix duplicate `DEFERRABLE` directive added for foreign keys in PostgreSQL and SQLite
2 parents fc07905 + 955798b commit c7f7b0a

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

activerecord/lib/active_record/connection_adapters/postgresql/schema_creation.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def visit_AlterTable(o)
1818

1919
def visit_AddForeignKey(o)
2020
super.dup.tap do |sql|
21-
sql << " DEFERRABLE INITIALLY #{o.options[:deferrable].to_s.upcase}" if o.deferrable
2221
sql << " NOT VALID" unless o.validate?
2322
end
2423
end

activerecord/lib/active_record/connection_adapters/sqlite3/schema_creation.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ module ConnectionAdapters
55
module SQLite3
66
class SchemaCreation < SchemaCreation # :nodoc:
77
private
8-
def visit_AddForeignKey(o)
9-
super.dup.tap do |sql|
10-
sql << " DEFERRABLE INITIALLY #{o.options[:deferrable].to_s.upcase}" if o.deferrable
11-
end
12-
end
13-
148
def visit_ForeignKeyDefinition(o)
159
super.dup.tap do |sql|
1610
sql << " DEFERRABLE INITIALLY #{o.deferrable.to_s.upcase}" if o.deferrable

activerecord/test/cases/migration/foreign_key_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ def test_add_invalid_foreign_key
519519

520520
if ActiveRecord::Base.lease_connection.supports_deferrable_constraints?
521521
def test_deferrable_foreign_key
522-
@connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", deferrable: :immediate
522+
assert_queries_match(/\("id"\)\s+DEFERRABLE INITIALLY IMMEDIATE\W*\z/i) do
523+
@connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", deferrable: :immediate
524+
end
523525

524526
foreign_keys = @connection.foreign_keys("astronauts")
525527
assert_equal 1, foreign_keys.size

0 commit comments

Comments
 (0)