"""Task: Add source_edit_plan_id to edit_plans and generation_tasks

Revision ID: 022
Revises: 021
Create Date: 2026-07-04

新增 source_edit_plan_id 字段到 edit_plans 和 generation_tasks 表，
用于关联生成记录到其来源的剪辑计划。
"""

import sqlalchemy as sa

from alembic import op

revision = "022"
down_revision = "021"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column(
        "edit_plans",
        sa.Column("source_edit_plan_id", sa.String(32), nullable=True),
    )
    op.create_index(
        op.f("ix_edit_plans_source_edit_plan_id"),
        "edit_plans",
        ["source_edit_plan_id"],
        unique=False,
    )

    op.add_column(
        "generation_tasks",
        sa.Column("source_edit_plan_id", sa.String(32), nullable=True),
    )
    op.create_index(
        op.f("ix_generation_tasks_source_edit_plan_id"),
        "generation_tasks",
        ["source_edit_plan_id"],
        unique=False,
    )


def downgrade() -> None:
    op.drop_index(
        op.f("ix_generation_tasks_source_edit_plan_id"),
        table_name="generation_tasks",
    )
    op.drop_column("generation_tasks", "source_edit_plan_id")

    op.drop_index(
        op.f("ix_edit_plans_source_edit_plan_id"),
        table_name="edit_plans",
    )
    op.drop_column("edit_plans", "source_edit_plan_id")
