From 0799cca3e678c53b3629573bcf164f7b851bd9b4 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 17 Oct 2026 22:46:01 -0400 Subject: [PATCH] fix(schema): ship the two Batch-A upgrade ALTERs that 1.15.0 missed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit audio_metadata (media_items) and audio_offset_seconds (reading_progress) were declared only inside their CREATE TABLE blocks — fresh installs got them, upgraded installs never did, because columns reach existing databases only via the idempotent ALTER block that schema.sql re-runs on every boot. On prod (v1.15.0) this 42703'd every media-existence check and the archive pass (1817/1817 scan errors), and every progress save, since the shared progress upsert names audio_offset_seconds. Both ALTERs match the declared shapes exactly (nullable JSONB; INTEGER CHECK (audio_offset_seconds >= 0)); idempotent, applied on every boot. Verified against a scratch database built to the v1.14.0 shape: overlay the patched schema -> both columns created; re-run (every boot) skips cleanly; probes resolve reading_progress.audio_offset_seconds integer and media_items.audio_metadata jsonb. Parse test and a real container boot (38 tables, 6 functions verified) green. --- database/schema/schema.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/database/schema/schema.sql b/database/schema/schema.sql index e9ab2aec..9385dd8c 100644 --- a/database/schema/schema.sql +++ b/database/schema/schema.sql @@ -263,6 +263,10 @@ ALTER TABLE media_items ADD COLUMN IF NOT EXISTS contributors_search TEXT[]; ALTER TABLE media_items ADD COLUMN IF NOT EXISTS narrators TEXT[] NOT NULL DEFAULT '{}'; ALTER TABLE media_items ADD COLUMN IF NOT EXISTS narrators_search TEXT[] NOT NULL DEFAULT '{}'; ALTER TABLE media_items ADD COLUMN IF NOT EXISTS abridged BOOLEAN NOT NULL DEFAULT FALSE; +-- audio_metadata is declared in the CREATE TABLE above, which only fresh +-- installs ever see — this ALTER is the upgrade path for pre-A2 installs +-- (its absence 42703'd every scan and archive pass on upgraded deployments). +ALTER TABLE media_items ADD COLUMN IF NOT EXISTS audio_metadata JSONB; -- Per-field user-override tracking (idempotent backfill for existing -- installs; the column is also declared in the media_items table @@ -371,6 +375,11 @@ CREATE TABLE IF NOT EXISTS reading_progress ( conflict_resolved BOOLEAN DEFAULT TRUE ); +-- audio_offset_seconds upgrade path: declared in the CREATE TABLE above +-- (Batch A) with no ALTER, so pre-A installs lacked the column and every +-- progress save — the shared upsert names it — failed with SQLSTATE 42703. +ALTER TABLE reading_progress ADD COLUMN IF NOT EXISTS audio_offset_seconds INTEGER CHECK (audio_offset_seconds >= 0); + -- Create media_ratings table CREATE TABLE IF NOT EXISTS media_ratings ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(),