Skip to content

Commit

Permalink
Merge pull request rails#53261 from zachasme/deferrable-special-chars…
Browse files Browse the repository at this point in the history
…-dumping

Allow deferrable foreign key on column with non-ascii characters
  • Loading branch information
byroot committed Nov 16, 2024
1 parent 701d3e0 commit 9128e6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Fix parsing of SQLite foreign key names when they contain non-ASCII characters

*Zacharias Knudsen*

* Fix parsing of MySQL 8.0.16+ CHECK constraints when they contain new lines.

*Steve Hill*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def add_reference(table_name, ref_name, **options) # :nodoc:
end
alias :add_belongs_to :add_reference

FK_REGEX = /.*FOREIGN KEY\s+\("(\w+)"\)\s+REFERENCES\s+"(\w+)"\s+\("(\w+)"\)/
FK_REGEX = /.*FOREIGN KEY\s+\("([^"]+)"\)\s+REFERENCES\s+"(\w+)"\s+\("(\w+)"\)/
DEFERRABLE_REGEX = /DEFERRABLE INITIALLY (\w+)/
def foreign_keys(table_name)
# SQLite returns 1 row for each column of composite foreign keys.
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/migration/foreign_key_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,14 @@ def test_schema_dumping_with_defferable_initially_immediate

assert_match %r{\s+add_foreign_key "astronauts", "rockets", deferrable: :immediate$}, output
end

def test_schema_dumping_with_special_chars_deferrable
@connection.add_reference :astronauts, :røcket, foreign_key: { to_table: :rockets, deferrable: :deferred }

output = dump_table_schema "astronauts"

assert_match %r{\s+add_foreign_key "astronauts", "rockets", column: "røcket_id", deferrable: :deferred$}, output
end
end

def test_does_not_create_foreign_keys_when_bypassed_by_config
Expand Down

0 comments on commit 9128e6e

Please sign in to comment.