From c3b638cb163ebd6058ad8ac6450cfe285d4160ff Mon Sep 17 00:00:00 2001 From: "DESKTOP-RTLN3BA\\$punk" Date: Mon, 2 Feb 2026 17:02:21 -0800 Subject: [PATCH] feat(migrations): possible podcast fix on prod --- .../88_make_podcast_transcript_nullable.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 surfsense_backend/alembic/versions/88_make_podcast_transcript_nullable.py diff --git a/surfsense_backend/alembic/versions/88_make_podcast_transcript_nullable.py b/surfsense_backend/alembic/versions/88_make_podcast_transcript_nullable.py new file mode 100644 index 000000000..c369d939e --- /dev/null +++ b/surfsense_backend/alembic/versions/88_make_podcast_transcript_nullable.py @@ -0,0 +1,58 @@ +"""Make podcast_transcript nullable + +Revision ID: 88 +Revises: 87 +Create Date: 2026-02-02 + +The podcast workflow now creates a podcast record with PENDING status first, +then fills in the transcript after generation completes. This requires +podcast_transcript to be nullable. +""" + +from collections.abc import Sequence + +from alembic import op + +revision: str = "88" +down_revision: str | None = "87" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + # Make podcast_transcript nullable and remove the server default + op.execute( + """ + ALTER TABLE podcasts + ALTER COLUMN podcast_transcript DROP NOT NULL; + """ + ) + op.execute( + """ + ALTER TABLE podcasts + ALTER COLUMN podcast_transcript DROP DEFAULT; + """ + ) + + +def downgrade() -> None: + # Set empty JSON for any NULL values before adding NOT NULL constraint + op.execute( + """ + UPDATE podcasts + SET podcast_transcript = '{}'::jsonb + WHERE podcast_transcript IS NULL; + """ + ) + op.execute( + """ + ALTER TABLE podcasts + ALTER COLUMN podcast_transcript SET DEFAULT '{}'; + """ + ) + op.execute( + """ + ALTER TABLE podcasts + ALTER COLUMN podcast_transcript SET NOT NULL; + """ + )