fix(#2279): idempotent column-guard migrations, drop invalid ADD COLUMN IF NOT EXISTS
This commit is contained in:
parent
c47faf0af9
commit
dfbf198ef3
5 changed files with 188 additions and 121 deletions
|
|
@ -20,6 +20,8 @@ use hive_sh4re::wire_time::now_unix;
|
|||
use rusqlite::{Connection, OptionalExtension, params};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::db::Migration;
|
||||
|
||||
/// Typed error returned by [`ScheduledPrompts::pause`] and
|
||||
/// [`ScheduledPrompts::resume`] when the target row does not exist or
|
||||
/// is already cancelled. Handlers downcast on this type to emit 404
|
||||
|
|
@ -186,17 +188,18 @@ impl ScheduledPrompts {
|
|||
.context("enable foreign keys")?;
|
||||
conn.execute_batch(SCHEMA)
|
||||
.context("apply scheduled_prompts schema")?;
|
||||
// Versioned migration: add paused_at_unix. Legacy databases are
|
||||
// detected via the presence of this column (it was the only
|
||||
// migration before versioning was introduced).
|
||||
// Versioned migration: add paused_at_unix. The per-migration
|
||||
// `adds_column` guard skips the ALTER on a legacy DB that already
|
||||
// has the column (it was the only migration before versioning).
|
||||
crate::db::apply_versioned_migrations(
|
||||
&conn,
|
||||
"scheduled_prompts",
|
||||
("scheduled_prompts", "paused_at_unix"),
|
||||
&[
|
||||
// v1: add paused_at_unix for per-schedule pause support.
|
||||
"ALTER TABLE scheduled_prompts \
|
||||
ADD COLUMN IF NOT EXISTS paused_at_unix INTEGER",
|
||||
Migration {
|
||||
sql: "ALTER TABLE scheduled_prompts ADD COLUMN paused_at_unix INTEGER",
|
||||
adds_column: Some(("scheduled_prompts", "paused_at_unix")),
|
||||
},
|
||||
],
|
||||
)?;
|
||||
// Migration: recreate the due-rows index to also exclude paused
|
||||
|
|
|
|||
Loading…
Reference in a new issue