"""Link rss_items to their discussion-summary note.

Revision ID: 0039
Revises: 0038
Create Date: 2026-04-14
"""

from __future__ import annotations

import sqlalchemy as sa
from alembic import op

revision = "0039"
down_revision = "0038"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column(
        "rss_items",
        sa.Column("discussion_note_id", sa.BigInteger(), nullable=True),
    )
    op.create_foreign_key(
        "fk_rss_items_discussion_note_id",
        "rss_items",
        "notes",
        ["discussion_note_id"],
        ["id"],
        ondelete="SET NULL",
    )


def downgrade() -> None:
    op.drop_constraint(
        "fk_rss_items_discussion_note_id", "rss_items", type_="foreignkey"
    )
    op.drop_column("rss_items", "discussion_note_id")
