From d42c78f58ce6d8b3d76e316dd868a213b3230f7e Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Tue, 27 Oct 2026 13:21:29 -0400 Subject: [PATCH] fix(schema): widen media_items.genre to TEXT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The genre column was VARCHAR(100), and the audio tag fallback stores the file's raw genre atom verbatim. Libation writes Audible's category ladder as one comma-joined string ("Politicians, Presidents & Heads of State, United States, Russia, Communism & Socialism, International Relations" — 111 chars), so any such book failed its import or metadata update with SQLSTATE 22001 (value too long), taking the whole row down with it. VARCHAR -> TEXT is a metadata-only change in Postgres and safe to re-run; the in-place ALTER follows the media_highlights position-widening precedent so existing databases converge on restart (schema.sql runs on every boot). --- database/schema/schema.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/database/schema/schema.sql b/database/schema/schema.sql index 38d4c6d3..9370a117 100644 --- a/database/schema/schema.sql +++ b/database/schema/schema.sql @@ -174,7 +174,7 @@ CREATE TABLE IF NOT EXISTS media_items ( language VARCHAR(10) DEFAULT 'en', -- Language code (ISO 639-1) edition VARCHAR(100), -- Edition information page_count INTEGER, -- Total page count - genre VARCHAR(100), -- Genre classification + genre TEXT, -- Genre classification (smart-genre shelf OR raw tag free text — Audible category strings exceed 100 chars) copyright_year INTEGER, -- Copyright/publication year goodreads_id VARCHAR(50), -- Goodreads identifier openlibrary_id VARCHAR(50), -- Open Library identifier @@ -279,6 +279,14 @@ CREATE INDEX IF NOT EXISTS idx_media_items_contributors_gin ON media_items USING ALTER TABLE media_items ADD COLUMN IF NOT EXISTS tags_search TEXT[]; ALTER TABLE media_items ADD COLUMN IF NOT EXISTS contributors_search TEXT[]; +-- Widen genre for existing databases: the audio tag fallback stores the +-- raw file genre atom (Audible category strings exceed 100 chars — +-- e.g. "Politicians, Presidents & Heads of State, United States, ..."), +-- and VARCHAR(100) rejected the whole import/update at the database +-- layer (SQLSTATE 22001). VARCHAR -> TEXT is a metadata-only change, +-- safe to re-run (media_highlights position widening precedent). +ALTER TABLE media_items ALTER COLUMN genre TYPE TEXT; + -- Audiobook editorial facts (A2a): narrators are user-editable first-class -- (search/filter/badge surface); abridged rides along; audio_metadata keeps -- the scan-derived tech record (duration/codec/chapters).