"""Add automation_configs, automation_runs, automation_logs tables Revision ID: 002_automation Revises: 001_initial Create Date: 2026-03-01 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = "002_automation" down_revision: Union[str, None] = "001_initial" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # automation_configs op.create_table( "automation_configs", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), sa.Column("name", sa.String(length=100), nullable=False), sa.Column("character_name", sa.String(length=100), nullable=False), sa.Column( "strategy_type", sa.String(length=50), nullable=False, comment="Strategy type: combat, gathering, crafting, trading, task, leveling", ), sa.Column("config", sa.JSON(), nullable=False), sa.Column("enabled", sa.Boolean(), nullable=False, server_default=sa.text("true")), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False, ), sa.Column( "updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False, ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_automation_configs_character_name"), "automation_configs", ["character_name"], unique=False, ) # automation_runs op.create_table( "automation_runs", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), sa.Column( "config_id", sa.Integer(), sa.ForeignKey("automation_configs.id", ondelete="CASCADE"), nullable=False, ), sa.Column( "status", sa.String(length=20), nullable=False, server_default=sa.text("'running'"), comment="Status: running, paused, stopped, completed, error", ), sa.Column( "started_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False, ), sa.Column("stopped_at", sa.DateTime(timezone=True), nullable=True), sa.Column("actions_count", sa.Integer(), nullable=False, server_default=sa.text("0")), sa.Column("error_message", sa.Text(), nullable=True), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_automation_runs_config_id"), "automation_runs", ["config_id"], unique=False, ) # automation_logs op.create_table( "automation_logs", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), sa.Column( "run_id", sa.Integer(), sa.ForeignKey("automation_runs.id", ondelete="CASCADE"), nullable=False, ), sa.Column("action_type", sa.String(length=50), nullable=False), sa.Column("details", sa.JSON(), nullable=False), sa.Column("success", sa.Boolean(), nullable=False, server_default=sa.text("true")), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False, ), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_automation_logs_run_id"), "automation_logs", ["run_id"], unique=False, ) def downgrade() -> None: op.drop_index(op.f("ix_automation_logs_run_id"), table_name="automation_logs") op.drop_table("automation_logs") op.drop_index(op.f("ix_automation_runs_config_id"), table_name="automation_runs") op.drop_table("automation_runs") op.drop_index(op.f("ix_automation_configs_character_name"), table_name="automation_configs") op.drop_table("automation_configs")