Bug
Clicking "Generate Insights" produces the error:
table project_insight_runs has no column named lifecycle
Root Cause
The lifecycle and cancelledAt columns were added to project_insight_runs in a commit that updated both SCHEMA_SQL (for fresh DBs) and retroactively inserted them into migration v33's CREATE TABLE. A safety-net addColumnIfMissing was placed inside the version < 59 migration block.
However, databases that were already at schema version 59+ when that commit landed never re-run v59. The SCHEMA_SQL uses CREATE TABLE IF NOT EXISTS, which is a no-op when the table already exists. Result: the columns are missing.
The codebase already has a pattern for exactly this scenario — ensureRoutinesSchemaCompatibility() runs unconditionally on every init(), outside the version-gated migration path.
Fix
Add ensureInsightRunsSchemaCompatibility() following the same pattern — idempotent addColumnIfMissing calls that run on every database initialization.
Reproduction
- Use a database that was created before the lifecycle columns were added
- Run migrations to current schema version
- Click "Generate Insights" in the dashboard
- Observe the SQLite error about missing
lifecycle column
Bug
Clicking "Generate Insights" produces the error:
Root Cause
The
lifecycleandcancelledAtcolumns were added toproject_insight_runsin a commit that updated bothSCHEMA_SQL(for fresh DBs) and retroactively inserted them into migration v33'sCREATE TABLE. A safety-netaddColumnIfMissingwas placed inside theversion < 59migration block.However, databases that were already at schema version 59+ when that commit landed never re-run v59. The
SCHEMA_SQLusesCREATE TABLE IF NOT EXISTS, which is a no-op when the table already exists. Result: the columns are missing.The codebase already has a pattern for exactly this scenario —
ensureRoutinesSchemaCompatibility()runs unconditionally on everyinit(), outside the version-gated migration path.Fix
Add
ensureInsightRunsSchemaCompatibility()following the same pattern — idempotentaddColumnIfMissingcalls that run on every database initialization.Reproduction
lifecyclecolumn