"""tasks.run_owner 列(蓝绿双实例部署,RUN.md B 档).

Revision ID: 0020
Revises: 0019
Create Date: 2026-07-06

给 tasks 加 run_owner(TEXT NULL):当前 in-flight run 是哪个实例(ZCBOT_INSTANCE,
如 blue/green)起的。启动 stale-run reaper 据此只收自己实例的孤儿 run,不误杀蓝绿
并存期另一实例正在跑的 run。

单实例部署(ZCBOT_INSTANCE 未设)写 NULL,reaper 行为不变(全量收)。additive,
无数据迁移;存量 running 行 run_owner=NULL,会被任一实例的 reaper 兜底收掉(与
迁移前行为一致)。
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op


revision: str = "0020"
down_revision: Union[str, None] = "0019"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column("tasks", sa.Column("run_owner", sa.Text(), nullable=True))


def downgrade() -> None:
    op.drop_column("tasks", "run_owner")
