"""A user's Google Takeout export: what they watched on YouTube, and their Watch later list Revision ID: 0113_takeout_items Revises: 0112_one_watch_later Create Date: 2026-10-23 One row per video and kind. A video the catalog does not know yet waits with no outcome, so the id is not a foreign key; the partial index is what a newly known video looks its waiting rows up by. """ import sqlalchemy as sa from alembic import op revision: str = "0113_takeout_items" down_revision: str | None = "0112_one_watch_later" branch_labels: str | None = None depends_on: str | None = None def upgrade() -> None: op.create_table( "takeout_items", sa.Column("id", sa.Integer(), primary_key=True), sa.Column( "user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, ), sa.Column("kind", sa.String(12), nullable=False), sa.Column("video_id", sa.String(16), nullable=False), sa.Column("channel_id", sa.String(32), nullable=True), sa.Column("at", sa.DateTime(timezone=True), nullable=False), sa.Column("outcome", sa.String(12), nullable=True), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False ), sa.UniqueConstraint("user_id", "kind", "video_id", name="uq_takeout_item"), sa.CheckConstraint("kind IN ('watched', 'watch_later')", name="ck_takeout_item_kind"), ) op.create_index( "ix_takeout_items_waiting", "takeout_items", ["video_id"], postgresql_where=sa.text("outcome IS NULL"), ) def downgrade() -> None: op.drop_index("ix_takeout_items_waiting", table_name="takeout_items") op.drop_table("takeout_items")