From ef417bea09de1ec9d32dbefcbca4689f787a0ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20F=C3=B6rtsch?= Date: Sat, 18 Apr 2026 10:10:40 +0200 Subject: [PATCH] schema: add auto_class + sorted to review_plans, drop confidence Co-Authored-By: Claude Sonnet 4.6 --- server/db/index.ts | 24 ++++++++++++++++++++++++ server/db/schema.ts | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/server/db/index.ts b/server/db/index.ts index 8568183..b7bc234 100644 --- a/server/db/index.ts +++ b/server/db/index.ts @@ -55,6 +55,7 @@ export function getDb(): Database { _db = new Database(dbPath, { create: true }); _db.exec(SCHEMA); migrate(_db); + backfill(_db); seedDefaults(_db); return _db; } @@ -80,6 +81,29 @@ function migrate(db: Database): void { alter("ALTER TABLE review_plans RENAME COLUMN webhook_verified TO verified"); alter("ALTER TABLE review_plans DROP COLUMN verified"); alter("ALTER TABLE media_items ADD COLUMN ingest_source TEXT NOT NULL DEFAULT 'scan'"); + alter("ALTER TABLE review_plans ADD COLUMN auto_class TEXT"); + alter("ALTER TABLE review_plans ADD COLUMN sorted INTEGER NOT NULL DEFAULT 0"); + alter("ALTER TABLE review_plans DROP COLUMN confidence"); + // Indexes for new columns — must run after the columns exist on existing DBs + alter("CREATE INDEX IF NOT EXISTS idx_review_plans_sorted ON review_plans(sorted)"); + alter("CREATE INDEX IF NOT EXISTS idx_review_plans_auto_class ON review_plans(auto_class)"); +} + +/** + * One-shot backfill for the inbox/auto_class rollout (2026-04-18): + * + * - Existing plans were already past the Inbox stage in the old world. Set + * sorted = 1 on every pre-existing row so they keep showing up where the + * user last saw them; dumping them into the new Inbox column on upgrade + * would look like data loss. + * - auto_class starts NULL on upgraded rows. The analyzer's next run over + * each item (reanalyze, rescan, or the explicit /sort-inbox pass) will + * populate it. Until then, the Review column renders a neutral badge. + * + * Idempotent: the WHERE clause makes repeated calls no-ops. + */ +function backfill(db: Database): void { + db.prepare("UPDATE review_plans SET sorted = 1 WHERE sorted = 0 AND auto_class IS NULL").run(); } function seedDefaults(db: Database): void { diff --git a/server/db/schema.ts b/server/db/schema.ts index 801203e..5c130af 100644 --- a/server/db/schema.ts +++ b/server/db/schema.ts @@ -65,7 +65,8 @@ CREATE TABLE IF NOT EXISTS review_plans ( item_id INTEGER NOT NULL UNIQUE REFERENCES media_items(id) ON DELETE CASCADE, status TEXT NOT NULL DEFAULT 'pending', is_noop INTEGER NOT NULL DEFAULT 0, - confidence TEXT NOT NULL DEFAULT 'low', + auto_class TEXT, + sorted INTEGER NOT NULL DEFAULT 0, apple_compat TEXT, job_type TEXT NOT NULL DEFAULT 'copy', subs_extracted INTEGER NOT NULL DEFAULT 0, @@ -135,6 +136,7 @@ export const DEFAULT_CONFIG: Record = { sonarr_api_key: "", sonarr_enabled: "0", audio_languages: "[]", + auto_processing: "0", scan_running: "0", job_sleep_seconds: "0",