imdrasil / jennifer_sqlite3_adapter

SQLite3 adapter for Jennifer ORM
MIT License
13 stars 7 forks source link

Enabling foreign key support incorrect #46

Open matthewmcgarvey opened 1 year ago

matthewmcgarvey commented 1 year ago

https://github.com/imdrasil/jennifer_sqlite3_adapter/blob/767093168fd98881f065226ace2ebb3cff2087ec/src/jennifer_sqlite3_adapter.cr#L51-L57

This code is enabling foreign key support. The problem is that this enabling needs to be done on every connection, not just once. Instead of calling with_connection, you should use the setup_connection callback provided on DB::Database.

To verify that the bug exists, you'd have to do multiple sql statements that rely on foreign key constraints to work with different database connections.

SQLite docs on enabling foreign key support (The 3rd paragraph in that section states that it needs to happen on every connection): https://www.sqlite.org/foreignkeys.html#fk_enable

imdrasil commented 1 year ago

Great spot. Thank you for this. Will take a look at this