⚠️ Performing SQLite migrations that require foreign keys off (PRAGMA foreign_keys=OFF;
)
#464
matthewlarkin
started this conversation in
General
Replies: 1 comment 2 replies
-
Hey ! Indeed, this behavior is defined in sqlx. But, considering the alternative, I think it's a good one. So yes, this requires making a "ghost" transaction, but it's probably better than ending up in a state where a migration is partially failed. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I recently had trouble preventing SQLPage (or maybe just sqlx) from automatically removing records during SQLite migrations involving foreign keys and
on cascade delete
, despite settingPRAGMA foreign_keys=off;
at the top of the migration file.It would seem if we need to truly disable foreign keys during migration, we need to commit the initial (ghost) transaction that SQLPage sets up.
@lovasoa, would you say this is a safe move? I haven't run into issues yet, but I feel this approach is a little hacky, and I wonder if it would cause any issues with SQLPage's ability to stop a faulty migration, detect faulty file changes before committing, etc. I don't know what's going on under the hood here, so I'm not sure what's being affected by committing the transaction early like that.
At any rate, I'm just glad I was able to catch this one out ahead of accidental deletion, even if I "knew for sure the migration should work"! 😅😬
Beta Was this translation helpful? Give feedback.
All reactions