Skip to content

Commit b0f74bf

Browse files
authored
Merge pull request rails#53261 from zachasme/deferrable-special-chars-dumping
Allow deferrable foreign key on column with non-ascii characters
2 parents 883ed53 + fe9321c commit b0f74bf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def add_reference(table_name, ref_name, **options) # :nodoc:
407407
end
408408
alias :add_belongs_to :add_reference
409409

410-
FK_REGEX = /.*FOREIGN KEY\s+\("(\w+)"\)\s+REFERENCES\s+"(\w+)"\s+\("(\w+)"\)/
410+
FK_REGEX = /.*FOREIGN KEY\s+\("([^"]+)"\)\s+REFERENCES\s+"(\w+)"\s+\("(\w+)"\)/
411411
DEFERRABLE_REGEX = /DEFERRABLE INITIALLY (\w+)/
412412
def foreign_keys(table_name)
413413
# SQLite returns 1 row for each column of composite foreign keys.

activerecord/test/cases/migration/foreign_key_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,14 @@ def test_schema_dumping_with_defferable_initially_immediate
601601

602602
assert_match %r{\s+add_foreign_key "astronauts", "rockets", deferrable: :immediate$}, output
603603
end
604+
605+
def test_schema_dumping_with_special_chars_deferrable
606+
@connection.add_reference :astronauts, :røcket, foreign_key: { to_table: :rockets, deferrable: :deferred }
607+
608+
output = dump_table_schema "astronauts"
609+
610+
assert_match %r{\s+add_foreign_key "astronauts", "rockets", column: "røcket_id", deferrable: :deferred$}, output
611+
end
604612
end
605613

606614
def test_does_not_create_foreign_keys_when_bypassed_by_config

0 commit comments

Comments
 (0)