schema: add auto_class + sorted to review_plans, drop confidence

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-18 10:10:40 +02:00
parent 68771bb980
commit ef417bea09
2 changed files with 27 additions and 1 deletions
+24
View File
@@ -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 {
+3 -1
View File
@@ -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<string, string> = {
sonarr_api_key: "",
sonarr_enabled: "0",
audio_languages: "[]",
auto_processing: "0",
scan_running: "0",
job_sleep_seconds: "0",