fix(db): recover progress_text columns skipped by migration-version collision

Merging origin/main collided on schema version 15: the deployment DB
recorded v15 as `reviewer_failure_count` (downstream-only), while upstream
defines v15 as `turn_progress_text`. The runner tracks applied migrations
by version number, so it skips upstream's `turn_progress_text` on the live
DB and never creates paired_turns.progress_text / progress_updated_at —
columns the merged runtime reads and writes (db/paired-turns.ts,
web-dashboard-data.ts), which would crash the live paired-room flow.

Add idempotent migration 019 to re-create those columns under a free
version number. No-op on fresh installs where migration 015 already ran.

Caught by a pre-flight boot of the merged code against a copy of the live DB.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-06-08 21:35:32 +09:00
parent 1dd948a7ac
commit dca56d9493
3 changed files with 38 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ function getExpectedSchemaMigrations(): Array<{
{ version: 16, name: 'room_skill_overrides' },
{ version: 17, name: 'scheduled_task_room_role' },
{ version: 18, name: 'paired_turn_output_attachments' },
{ version: 19, name: 'turn_progress_text_recovery' },
];
}

View File

@@ -0,0 +1,35 @@
import type { Database } from 'bun:sqlite';
import { tableHasColumn } from './helpers.js';
import type { SchemaMigrationDefinition } from './types.js';
/**
* Recovery for a migration-version collision introduced by merging
* origin/main into the long-lived deployment branch.
*
* The deployment DB recorded schema version 15 as `reviewer_failure_count`
* (a downstream-only migration), while upstream defines version 15 as
* `turn_progress_text` (migration 015). Because the migration runner tracks
* applied migrations by version number alone, the upstream `turn_progress_text`
* migration is skipped on the live DB and `paired_turns.progress_text` /
* `progress_updated_at` are never created — even though merged runtime code
* (src/db/paired-turns.ts, src/web-dashboard-data.ts) reads and writes them.
*
* This migration re-applies those columns idempotently under a fresh version
* number so the live deployment gets them. It is a no-op on databases where
* migration 015 already ran (fresh installs), thanks to the column guards.
*/
export const TURN_PROGRESS_TEXT_RECOVERY_MIGRATION: SchemaMigrationDefinition = {
version: 19,
name: 'turn_progress_text_recovery',
apply(database: Database) {
if (!tableHasColumn(database, 'paired_turns', 'progress_text')) {
database.exec(`ALTER TABLE paired_turns ADD COLUMN progress_text TEXT`);
}
if (!tableHasColumn(database, 'paired_turns', 'progress_updated_at')) {
database.exec(
`ALTER TABLE paired_turns ADD COLUMN progress_updated_at TEXT`,
);
}
},
};

View File

@@ -18,6 +18,7 @@ import { TURN_PROGRESS_TEXT_MIGRATION } from './015_turn-progress-text.js';
import { ROOM_SKILL_OVERRIDES_MIGRATION } from './016_room-skill-overrides.js';
import { SCHEDULED_TASK_ROOM_ROLE_MIGRATION } from './017_scheduled-task-room-role.js';
import { PAIRED_TURN_OUTPUT_ATTACHMENTS_MIGRATION } from './018_paired-turn-output-attachments.js';
import { TURN_PROGRESS_TEXT_RECOVERY_MIGRATION } from './019_turn-progress-text-recovery.js';
import type {
SchemaMigrationArgs,
SchemaMigrationDefinition,
@@ -44,6 +45,7 @@ const ORDERED_SCHEMA_MIGRATIONS: readonly SchemaMigrationDefinition[] = [
ROOM_SKILL_OVERRIDES_MIGRATION,
SCHEDULED_TASK_ROOM_ROLE_MIGRATION,
PAIRED_TURN_OUTPUT_ATTACHMENTS_MIGRATION,
TURN_PROGRESS_TEXT_RECOVERY_MIGRATION,
];
function ensureSchemaMigrationsTable(database: Database): void {