From 4a0ed993298ebe4bbd9a7b1eff087dc8207e4fc9 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 --- .../each_user/0012_contact_fresh_type.sql | 19 ++++++++++++++++ src/web/contact/mod.rs | 22 ++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 migrations/each_user/0012_contact_fresh_type.sql diff --git a/migrations/each_user/0012_contact_fresh_type.sql b/migrations/each_user/0012_contact_fresh_type.sql new file mode 100644 index 0000000..a9685ef --- /dev/null +++ b/migrations/each_user/0012_contact_fresh_type.sql @@ -0,0 +1,19 @@ + +PRAGMA foreign_keys=OFF; +create table if not exists new_contacts ( + id integer primary key autoincrement, + birthday text, + manually_freshened_at text, + text_body text, + lives_with text not null default '' +); + +insert into new_contacts ( + id, birthday, manually_freshened_at, text_body, lives_with) + select id, birthday, manually_freshened_at, text_body, lives_with + from contacts; + +drop table contacts; +alter table new_contacts rename to contacts; +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/src/web/contact/mod.rs b/src/web/contact/mod.rs index 34b0c13..8eea1b0 100644 --- a/src/web/contact/mod.rs +++ b/src/web/contact/mod.rs @@ -601,16 +601,18 @@ mod put { .execute(pool) .await?; - QueryBuilder::new("insert into groups (contact_id, name, slug) ") - .push_values(&new_groups, |mut b, name| { - b.push_bind(contact_id) - .push_bind(name) - .push_bind(slugify(name)); - }) - .build() - .persistent(false) - .execute(pool) - .await?; + if new_groups.len() > 0 { + QueryBuilder::new("insert into groups (contact_id, name, slug) ") + .push_values(&new_groups, |mut b, name| { + b.push_bind(contact_id) + .push_bind(name) + .push_bind(slugify(name)); + }) + .build() + .persistent(false) + .execute(pool) + .await?; + } { let mut switchboard = sw_lock.write().unwrap();