-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve foreign key introspection on SQLite #5409
Conversation
Should #4258 be cherry-picked into this? |
It looks like it depends on |
Maybe that's indirect somehow because @driesvints hi! 👋 Can you please review this, and maybe try it on the Laravel test suite? So that we can know if something is going to break and give you some time to prevent it? |
I did the same and also didn't find anything. Having somebody from Laravel take a look would be nice. |
Hi all. I tried these changes out on Laravel 9.x's test suite and everything still passed so I think we're good. Of course there could always be edge cases in apps. |
Great! Thanks for taking the time to check! |
@morozov @derrabus I think this breaks the ORM test suite: https://github.com/doctrine/orm/runs/6563292058?check_suite_focus=true 😞 |
It looks like the ORM always creates foreign keys via the ALTER statements as opposed to creating the table and the foreign keys at once. As a temporary fix, we could replace |
I believe I see what's going on here. When it comes to creating a schema where some tables contain foreign keys, neither ORM nor DBAL know in which order they need to be created in order to have the foreign key dependencies satisfied at every step of the migration, so the current implementation does this:
In order to unscrew this all we need to:
Alternatively, we could move the logic of creating schemas to the schema manager where it belongs (how would we name the method?). Then we could ditch all this visitor thing in one shot. |
Thanks for the in-depth analysis @morozov! Deprecating the collector in favor of a new schema manager method sounds more sensible
|
With this patch, DBAL can support all foreign key operations except for altering foreign keys on an existing table. IMO, it's still sufficient to declare that the platform supports foreign keys.
This might be considered a minor breaking change (see xkcd #1172) in the cases where code that alters a foreign key based on whether the current platform supports foreign keys. I'd argue that it's a made up/synthetic scenario that primarily applies to testing the DBAL or other libraries that provide an abstraction on top of the DBAL (e.g. the ORM).
In real practical cases, the application would use a subset of the features supported by all target platforms. So it would either not attempt to alter foreign keys because SQLite doesn't support that or it wouldn't support SQLite. In such cases, this change is backward-compatible.
UPD: it still looks like it will cause the same failure in the Laravel test suite that #3762 caused since the test suite relies on
AbstractPlatform::supportsForeignKeyConstraints()
(see laravel/framework#34093 (comment)).