From dba05f57494ce8377204756b933460cc7d87145a Mon Sep 17 00:00:00 2001 From: DJ Majumdar Date: Mon, 23 Mar 2026 23:20:39 -0700 Subject: [PATCH] refactor: consolidate paused_groups migration into standard include_str! pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename 010_paused_groups.sql to 005 and replace inline SQL with include_str!, matching migrations 001–004. Drop the now-unnecessary ALTER TABLE and backfill statements since the DB is re-created. --- ...aused_groups.sql => 005_paused_groups.sql} | 0 src/store/mod.rs | 31 ++----------------- 2 files changed, 3 insertions(+), 28 deletions(-) rename migrations/{010_paused_groups.sql => 005_paused_groups.sql} (100%) diff --git a/migrations/010_paused_groups.sql b/migrations/005_paused_groups.sql similarity index 100% rename from migrations/010_paused_groups.sql rename to migrations/005_paused_groups.sql diff --git a/src/store/mod.rs b/src/store/mod.rs index d16738b..31b4bdb 100644 --- a/src/store/mod.rs +++ b/src/store/mod.rs @@ -281,34 +281,9 @@ impl TaskStore { sqlx::raw_sql(include_str!("../../migrations/004_task_tags.sql")) .execute(&self.pool) .await?; - - // 010: paused_groups table + pause_reasons column on tasks. - // The CREATE TABLE is idempotent, but ALTER TABLE ADD COLUMN will - // fail if the column already exists (fresh databases include it in - // 001_tasks.sql). Run each statement individually and tolerate the - // "duplicate column" error from the ALTER. - sqlx::raw_sql( - "CREATE TABLE IF NOT EXISTS paused_groups ( - group_key TEXT NOT NULL PRIMARY KEY, - paused_at INTEGER NOT NULL, - resume_at INTEGER - );", - ) - .execute(&self.pool) - .await?; - - // ALTER TABLE ADD COLUMN is not idempotent — tolerate failure. - let _ = - sqlx::raw_sql("ALTER TABLE tasks ADD COLUMN pause_reasons INTEGER NOT NULL DEFAULT 0;") - .execute(&self.pool) - .await; - - // Backfill: existing paused tasks get PREEMPTION bit. - sqlx::raw_sql( - "UPDATE tasks SET pause_reasons = 1 WHERE status = 'paused' AND pause_reasons = 0;", - ) - .execute(&self.pool) - .await?; + sqlx::raw_sql(include_str!("../../migrations/005_paused_groups.sql")) + .execute(&self.pool) + .await?; Ok(()) }