Enable foreign keys in SQLite
TomaszGasior opened this issue · 8 comments
I've just saw this:
demo/src/Controller/Admin/BlogController.php
Lines 171 to 174 in b0526f4
In my open source app I reconfigure SQLite to enable foreign keys using Doctrine functionality. Maybe symfony/demo app could do something similar?
That's based on https://github.com/doctrine/dbal/blob/3.6.x/src/Driver/AbstractSQLiteDriver/Middleware/EnableForeignKeys.php but doesn't crash the app if another DBMS is used.
Tomasz, the solution that you proposed is great ... but given that this is a demo application just to showcase Symfony, each and learn Symfony and benchmark Symfony, I think it's better to not complicate the application to implement this feature.
Using SQLite is convenient for the idea of this project (create a 100% stand-alone app that doesn't require to install, run or configure anything). However, most real apps will use PostgreSQL, MySQL, etc. so we shouldn't try to fix SQLite shortcomings. Thanks for your understanding.
However, most real apps will use PostgreSQL, MySQL,
And that's the exact reason why it may make sense to enable foreign keys in SQLite: because all of real-world apps will have foreign keys enabled by default in MySQL or PostgreSQL.
Maybe it's a better idea to contribute this feature to DoctrineBundle instead.
It's already included in Doctrine DBAL but the way how it's currently implemented makes it impossible to easily swap database driver. This is explained here in the issue description ↑↑↑ (I updated broken URL, however)
It's already included in Doctrine DBAL
DBAL is not DoctrineBundle.
Yes, and there is nothing wrong with that. EnableForeignKeys middleware is already included in Doctrine DBAL which is installed when you have Doctrine bundle installed.
If you don't want to have that class in your app, you can just add Doctrine\DBAL\Driver\AbstractSQLiteDriver\Middleware\EnableForeignKeys to your services.yaml and tag with proper tag doctrine.middleware.
As I described, if you do that in your app, the app will not work with driver other than SQLite one because implementation built into Doctrine DBAL is not conditional: that's the reason why it may make sense to have this little file in your app, to have better control.
I don't think you get my point. Nevermind.