diff --git a/Taskfile b/Taskfile index 211d1e8..9eeaa50 100755 --- a/Taskfile +++ b/Taskfile @@ -12,7 +12,8 @@ refresh_sqlx_db() { rm -f some_user.db for migration in migrations/each_user/*.sql; do echo "Applying $migration..." - sqlite3 some_user.db < "$migration" + echo "BEGIN TRANSACTION;$(cat "$migration");COMMIT TRANSACTION;"\ + | sqlite3 some_user.db done } diff --git a/migrations/each_user/0012_contact_fresh_type.sql b/migrations/each_user/0012_contact_fresh_type.sql index a9685ef..7a5f8bb 100644 --- a/migrations/each_user/0012_contact_fresh_type.sql +++ b/migrations/each_user/0012_contact_fresh_type.sql @@ -1,5 +1,12 @@ +-- foreign_keys can only up/down outside of transactions +-- so we first pre-commit the one started by sqlx... +COMMIT TRANSACTION; +-- turn off foreign keys... PRAGMA foreign_keys=OFF; + +-- start our own transaction... +BEGIN TRANSACTION; create table if not exists new_contacts ( id integer primary key autoincrement, birthday text, @@ -16,4 +23,12 @@ insert into new_contacts ( drop table contacts; alter table new_contacts rename to contacts; PRAGMA foreign_key_check; + +-- commit our own transaction... +COMMIT TRANSACTION; + +-- put our own pragmas back... PRAGMA foreign_keys=ON; + +-- and start a dummy transaction so sqlx's COMMIT doesn't explode +BEGIN TRANSACTION;