From 6d6018aa32e397ce18d26f0251e762fd1bea3c1b Mon Sep 17 00:00:00 2001 From: Robert Perce Date: Wed, 4 Feb 2026 13:32:03 -0600 Subject: [PATCH] fix: store refresh-at as string type, not date type, for sqlx autotyping --- Taskfile | 3 ++- migrations/each_user/0012_contact_fresh_type.sql | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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;