"""coupon_session 加 trace_url 列(pricebot done 帧公网调试链接)

建表迁移 coupon_session_table 落地后才追加本列,故单独成一个迁移:已建表的环境(本地/已 upgrade 过)
靠它补列,全新环境则「建表(无 trace_url)→ 本迁移加列」,两条路一致、不重复加列。

Revision ID: coupon_session_trace_url
Revises: coupon_session_table
Create Date: 2026-06-30 00:00:00.000000

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "coupon_session_trace_url"
down_revision: str | Sequence[str] | None = "coupon_session_table"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    with op.batch_alter_table("coupon_session", schema=None) as batch_op:
        batch_op.add_column(sa.Column("trace_url", sa.String(length=512), nullable=True))


def downgrade() -> None:
    with op.batch_alter_table("coupon_session", schema=None) as batch_op:
        batch_op.drop_column("trace_url")
