feat(tasks): persist list_id/effort/notes + update_task_cmd — close Task 2 metadata gap
This commit is contained in:
@@ -112,6 +112,9 @@ const MIGRATIONS: &[(i64, &str, &str)] = &[
|
||||
ALTER TABLE tasks ADD COLUMN parent_task_id TEXT REFERENCES tasks(id) ON DELETE CASCADE;
|
||||
CREATE INDEX IF NOT EXISTS idx_tasks_parent ON tasks(parent_task_id)
|
||||
"#),
|
||||
(4, "tasks_meta: notes column for persisted free-text", r#"
|
||||
ALTER TABLE tasks ADD COLUMN notes TEXT NOT NULL DEFAULT ''
|
||||
"#),
|
||||
];
|
||||
|
||||
/// Split SQL into individual statements, respecting BEGIN...END trigger blocks.
|
||||
@@ -197,6 +200,7 @@ pub async fn run_migrations(pool: &SqlitePool) -> Result<()> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sqlx::sqlite::SqlitePoolOptions;
|
||||
use sqlx::Row;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_migrations_run_on_empty_db() {
|
||||
@@ -211,7 +215,7 @@ mod tests {
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 3);
|
||||
assert_eq!(count, 4);
|
||||
|
||||
sqlx::query("INSERT INTO settings (key, value) VALUES ('test', 'value')")
|
||||
.execute(&pool)
|
||||
@@ -233,7 +237,35 @@ mod tests {
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 3);
|
||||
assert_eq!(count, 4);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn migration_tasks_meta_adds_columns() {
|
||||
// Task 2.6 — verify list_id / effort / notes are all present on the
|
||||
// tasks table after migrations run. list_id and effort have been
|
||||
// present since v1 (nullable); notes is added by v4.
|
||||
let pool = SqlitePoolOptions::new()
|
||||
.max_connections(1)
|
||||
.connect("sqlite::memory:")
|
||||
.await
|
||||
.expect("pool");
|
||||
run_migrations(&pool).await.expect("migrate");
|
||||
|
||||
let info = sqlx::query("PRAGMA table_info(tasks)")
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let names: Vec<String> = info
|
||||
.iter()
|
||||
.map(|r| r.get::<String, _>("name"))
|
||||
.collect();
|
||||
for col in ["list_id", "effort", "notes"] {
|
||||
assert!(
|
||||
names.contains(&col.to_string()),
|
||||
"tasks must have {col}; got {names:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user