From c8471b787e6ab63c3396f0438f3f83974f7be321 Mon Sep 17 00:00:00 2001 From: Giancarmine Salucci Date: Thu, 6 Aug 2026 16:17:18 +0000 Subject: [PATCH] feat: Add transcript_source column and type to foundation schema - Add transcript_source: 'captions' | 'whisper' | null to Job interface in types.ts - Add idempotent migration for transcript_source column in jobs table - Update rowToJob to map transcript_source from database - Update updateJob and resetJob statements to handle transcript_source - Fix transcriptSource in updateJob function call - Add transcriptSource: null to all test makeJob helpers This foundation schema enables transcript source tracking for D2/D5/D6 stories. Schema migration applies idempotently via addColumnIfMissing utility. Co-Authored-By: Claude Haiku 4.5 --- src/lib/server/db.ts | 7 ++++++- src/lib/types.ts | 1 + src/tests/job-error-line.test.ts | 1 + src/tests/job-list-error-display.test.ts | 1 + src/tests/job-progress.test.ts | 1 + src/tests/retry-endpoint.test.ts | 1 + 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/server/db.ts b/src/lib/server/db.ts index f9e450b..baef2b6 100644 --- a/src/lib/server/db.ts +++ b/src/lib/server/db.ts @@ -53,6 +53,7 @@ db.exec(` try { addColumnIfMissing('jobs', 'retry_count', 'INTEGER DEFAULT 0'); addColumnIfMissing('jobs', 'next_retry_at', 'TEXT'); + addColumnIfMissing('jobs', 'transcript_source', 'TEXT'); } catch (e) { console.warn('[db] failed to add retry columns:', e); } @@ -74,6 +75,7 @@ const stmts = { error = @error, retry_count = @retryCount, next_retry_at = @nextRetryAt, + transcript_source = @transcriptSource, updated_at = datetime('now') WHERE id = @id `), @@ -87,6 +89,7 @@ const stmts = { mean_volume = NULL, whisper_job_id = NULL, output_dir = NULL, segments_json = NULL, retry_count = 0, next_retry_at = NULL, + transcript_source = NULL, updated_at = datetime('now') WHERE id = @id `), @@ -116,6 +119,7 @@ function rowToJob(row: Record): Job { segmentsJson: row.segments_json as string | null, error: row.error as string | null, retryCount: row.retry_count as number | null, + transcriptSource: row.transcript_source as 'captions' | 'whisper' | null, nextRetryAt: row.next_retry_at as string | null, createdAt: row.created_at as string, updatedAt: row.updated_at as string @@ -152,7 +156,8 @@ export function updateJob(job: Partial & { id: string }): void { segmentsJson: merged.segmentsJson, error: merged.error, retryCount: merged.retryCount ?? null, - nextRetryAt: merged.nextRetryAt ?? null + nextRetryAt: merged.nextRetryAt ?? null, + transcriptSource: merged.transcriptSource ?? null }); } diff --git a/src/lib/types.ts b/src/lib/types.ts index 455522e..877368e 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -52,6 +52,7 @@ export interface Job { error: string | null; retryCount: number | null; nextRetryAt: string | null; + transcriptSource: 'captions' | 'whisper' | null; createdAt: string; updatedAt: string; } diff --git a/src/tests/job-error-line.test.ts b/src/tests/job-error-line.test.ts index 42accd6..4f62f33 100644 --- a/src/tests/job-error-line.test.ts +++ b/src/tests/job-error-line.test.ts @@ -19,6 +19,7 @@ function makeJob(overrides: Partial = {}): Job { error: 'transcription timeout', retryCount: 0, nextRetryAt: null, + transcriptSource: null, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), ...overrides diff --git a/src/tests/job-list-error-display.test.ts b/src/tests/job-list-error-display.test.ts index c779dfd..e73c3bf 100644 --- a/src/tests/job-list-error-display.test.ts +++ b/src/tests/job-list-error-display.test.ts @@ -21,6 +21,7 @@ function makeJob(overrides: Partial = {}): Job { meanVolume: null, retryCount: null, nextRetryAt: null, + transcriptSource: null, ...overrides, }; } diff --git a/src/tests/job-progress.test.ts b/src/tests/job-progress.test.ts index b9f6ad3..7a1d064 100644 --- a/src/tests/job-progress.test.ts +++ b/src/tests/job-progress.test.ts @@ -17,6 +17,7 @@ function makeJob(overrides: Partial = {}): Job { error: null, retryCount: null, nextRetryAt: null, + transcriptSource: null, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), ...overrides diff --git a/src/tests/retry-endpoint.test.ts b/src/tests/retry-endpoint.test.ts index 07b553b..5f28fa6 100644 --- a/src/tests/retry-endpoint.test.ts +++ b/src/tests/retry-endpoint.test.ts @@ -35,6 +35,7 @@ function makeJob(overrides: Partial = {}): Job { error: 'Something failed', retryCount: 0, nextRetryAt: null, + transcriptSource: null, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), ...overrides