From 5e696888d630f16ec79f44d4c8976bbc5f6e71da Mon Sep 17 00:00:00 2001 From: Alessandro Costa Date: Mon, 6 Apr 2026 07:20:48 -0300 Subject: [PATCH] fix: add migration for generated_by_model and relevance_count columns The compiled binary (v10.6.3) creates these columns at runtime via MigrationRunner, but no corresponding migration exists in the TypeScript source. Anyone building from source gets observations without these columns, breaking the feedback pipeline and model tracking. This migration conditionally adds both columns using PRAGMA table_info checks, making it safe for databases that already have them. Refs: #1626 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/services/sqlite/migrations.ts | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/services/sqlite/migrations.ts b/src/services/sqlite/migrations.ts index 5be21f6a..76d51a9b 100644 --- a/src/services/sqlite/migrations.ts +++ b/src/services/sqlite/migrations.ts @@ -541,6 +541,37 @@ export const migration008: Migration = { } }; +/** + * Migration 009: Add missing columns to observations table + * + * The generated_by_model column tracks which model generated each observation + * (required for model selection optimization via Thompson Sampling). + * The relevance_count column tracks how many times an observation was reused + * (incremented by the feedback recording pipeline). + * + * Both columns may already exist in databases created by the compiled binary + * (v10.6.3) but are missing from the migration source. This migration + * conditionally adds them. + */ +export const migration009: Migration = { + version: 26, + up: (db: Database) => { + const columns = db.prepare('PRAGMA table_info(observations)').all() as any[]; + const hasGeneratedByModel = columns.some((c: any) => c.name === 'generated_by_model'); + const hasRelevanceCount = columns.some((c: any) => c.name === 'relevance_count'); + + if (!hasGeneratedByModel) { + db.run('ALTER TABLE observations ADD COLUMN generated_by_model TEXT'); + } + if (!hasRelevanceCount) { + db.run('ALTER TABLE observations ADD COLUMN relevance_count INTEGER DEFAULT 0'); + } + }, + down: (_db: Database) => { + // SQLite does not support DROP COLUMN in older versions; no-op + } +}; + /** * All migrations in order */ @@ -552,5 +583,6 @@ export const migrations: Migration[] = [ migration005, migration006, migration007, - migration008 + migration008, + migration009 ]; \ No newline at end of file