"""add schedule_timezone to schedule_tasks Revision ID: c9d0e1f2a3b4 Revises: b8c9d0e1f2a3 Create Date: 2026-06-12 00:00:00.000000 """ from alembic import op import sqlalchemy as sa revision = "c9d0e1f2a3b4" down_revision = "b8c9d0e1f2a3" branch_labels = None depends_on = None def upgrade(): bind = op.get_bind() insp = sa.inspect(bind) if "schedule_tasks" not in set(insp.get_table_names()): return columns = {col["name"] for col in insp.get_columns("schedule_tasks")} if "schedule_timezone" not in columns: with op.batch_alter_table("schedule_tasks", schema=None) as batch_op: batch_op.add_column( sa.Column( "schedule_timezone", sa.String(length=64), nullable=True, ) ) op.execute("UPDATE schedule_tasks SET schedule_timezone = 'Asia/Shanghai' WHERE schedule_timezone IS NULL") with op.batch_alter_table("schedule_tasks", schema=None) as batch_op: batch_op.alter_column( "schedule_timezone", existing_type=sa.String(length=64), server_default=sa.text("'Asia/Shanghai'"), nullable=False, ) def downgrade(): bind = op.get_bind() insp = sa.inspect(bind) if "schedule_tasks" not in set(insp.get_table_names()): return columns = {col["name"] for col in insp.get_columns("schedule_tasks")} if "schedule_timezone" in columns: with op.batch_alter_table("schedule_tasks", schema=None) as batch_op: batch_op.drop_column("schedule_timezone")