diff --git a/surfsense_backend/alembic/versions/80_add_thread_id_to_podcasts.py b/surfsense_backend/alembic/versions/80_add_thread_id_to_podcasts.py new file mode 100644 index 000000000..ea66a09a1 --- /dev/null +++ b/surfsense_backend/alembic/versions/80_add_thread_id_to_podcasts.py @@ -0,0 +1,40 @@ +"""Add thread_id to podcasts + +Revision ID: 80 +Revises: 79 +Create Date: 2026-01-23 + +""" + +from collections.abc import Sequence + +from alembic import op + +revision: str = "80" +down_revision: str | None = "79" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + """Add thread_id column to podcasts.""" + op.execute( + """ + ALTER TABLE podcasts + ADD COLUMN IF NOT EXISTS thread_id INTEGER + REFERENCES new_chat_threads(id) ON DELETE SET NULL; + """ + ) + + op.execute( + """ + CREATE INDEX IF NOT EXISTS ix_podcasts_thread_id + ON podcasts(thread_id); + """ + ) + + +def downgrade() -> None: + """Remove thread_id column from podcasts.""" + op.execute("DROP INDEX IF EXISTS ix_podcasts_thread_id") + op.execute("ALTER TABLE podcasts DROP COLUMN IF EXISTS thread_id") diff --git a/surfsense_backend/app/db.py b/surfsense_backend/app/db.py index d13e0cbdd..7018e613c 100644 --- a/surfsense_backend/app/db.py +++ b/surfsense_backend/app/db.py @@ -693,6 +693,14 @@ class Podcast(BaseModel, TimestampMixin): ) search_space = relationship("SearchSpace", back_populates="podcasts") + thread_id = Column( + Integer, + ForeignKey("new_chat_threads.id", ondelete="SET NULL"), + nullable=True, + index=True, + ) + thread = relationship("NewChatThread") + class SearchSpace(BaseModel, TimestampMixin): __tablename__ = "searchspaces"