From 305822aa4fc3530cafb7dde1ee016b60aec3d4b0 Mon Sep 17 00:00:00 2001 From: oliver Date: Tue, 22 Sep 2026 17:06:09 +0800 Subject: [PATCH] Add alembic revision for biz_state_task.collect_queued_at. Fixes /v1/biz-state/tasks 500 when ORM expects the column but DB was still on prior head. Co-authored-by: Cursor --- alembic/versions/20260922_biz_state_queued.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 alembic/versions/20260922_biz_state_queued.py diff --git a/alembic/versions/20260922_biz_state_queued.py b/alembic/versions/20260922_biz_state_queued.py new file mode 100644 index 0000000..5e03915 --- /dev/null +++ b/alembic/versions/20260922_biz_state_queued.py @@ -0,0 +1,51 @@ +"""Add biz_state_task.collect_queued_at for collect queue claim. + +Revision ID: 20260922_biz_state_queued +Revises: 20260921_exec_policy +Create Date: 2026-09-22 +""" + +from __future__ import annotations + +from typing import Sequence, Union + +from alembic import op + +revision: str = "20260922_biz_state_queued" +down_revision: Union[str, Sequence[str], None] = "20260921_exec_policy" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + bind = op.get_bind() + dialect = str(getattr(bind.dialect, "name", "") or "").lower() + if dialect.startswith("postgres"): + op.execute( + "ALTER TABLE biz_state_task ADD COLUMN IF NOT EXISTS collect_queued_at TIMESTAMP" + ) + else: + # SQLite / others: best-effort + try: + op.add_column( + "biz_state_task", + __import__("sqlalchemy", fromlist=["Column"]).Column( + "collect_queued_at", + __import__("sqlalchemy", fromlist=["DateTime"]).DateTime(), + nullable=True, + ), + ) + except Exception: + pass + + +def downgrade() -> None: + bind = op.get_bind() + dialect = str(getattr(bind.dialect, "name", "") or "").lower() + if dialect.startswith("postgres"): + op.execute("ALTER TABLE biz_state_task DROP COLUMN IF EXISTS collect_queued_at") + else: + try: + op.drop_column("biz_state_task", "collect_queued_at") + except Exception: + pass