The SQLite3 adapter now implements the supports_deferrable_constraints? contract#49376
Conversation
|
Could the test failure be a flaky test? I can't reproduce locally and the error (
Could we retry the build? |
I've issued a rebuild. 🙏 Edit: The rebuild failed, but this test is also flaking on main. |
|
@zzak the fix for this flaky test is in main, can we rebuild this PR? |
|
@fractaledmind Could you rebase please? 🙇 |
d54697d to
c85acbc
Compare
cb18ebd to
a3e2c2b
Compare
a3e2c2b to
38dd5f4
Compare
|
Would you address the |
…ts?` contract
Implementing the full `supports_deferrable_constraints?` contract allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options in the `add_reference` and `add_foreign_key` methods.
```ruby
add_reference :person, :alias, foreign_key: { deferrable: :deferred }
add_reference :alias, :person, foreign_key: { deferrable: :deferred }
```
38dd5f4 to
ea17941
Compare
|
@yahonda: Done (for both of my PRs) |
| end | ||
|
|
||
| def add_foreign_key(from_table, to_table, **options) | ||
| if options[:deferrable] == true |
There was a problem hiding this comment.
Rails main branch version is already 7.2.0.alpha, I'd like to keep this deprecation message as the PostgreSQL adapter does.
Motivation / Background
SQLite is a feature-rich database engine, and production usage is only growing. We need Rails' support to offer developers the range and scope of its features.
The PostgreSQL adapter supports deferred foreign keys, and SQLite itself has support deferred foreign keys since at least 2011.
Detail
Implementing the full
supports_deferrable_constraints?contract allows foreign keys to be deferred by adding the:deferrablekey to theforeign_keyoptions in theadd_referenceandadd_foreign_keymethods.In this PR, I am adding full support for the SQLite3Adapter by implementing:
ActiveRecord::ConnectionAdapters::SQLite3::SchemaCreation#visit_AddForeignKeyActiveRecord::ConnectionAdapters::SQLite3::SchemaCreation#visit_ForeignKeyDefinitionActiveRecord::ConnectionAdapters::SQLite3Adapter#supports_deferrable_constraints?ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements#assert_valid_deferrableand altering:
ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements#add_foreign_keyActiveRecord::ConnectionAdapters::SQLite3Adapter#foreign_keysAdditional Info
In order to get the
ActiveRecord::ConnectionAdapters::SQLite3Adapter#foreign_keysmethod working properly, I had to add a query to get theCREATE TABLEsql and parse which foreign key constraints are deferrable and which of those are deferred. In order to support this use-case, I extracted atable_structure_sqlmethod which nowtable_structure_with_collationrelies on.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]