"""创建智能投保交易主链表。"""

from alembic import op

from zbt.infrastructure.mysql.core_models import CoreBase

revision = "core_0002"
down_revision = "core_0001"
branch_labels = None
depends_on = None

TABLE_NAMES = (
    "quotes",
    "enrollment_drafts",
    "user_confirmations",
    "enrollment_orders",
    "payment_transactions",
    "policies",
    "outbox_events",
    "async_tasks",
)


def upgrade() -> None:
    bind = op.get_bind()
    tables = [CoreBase.metadata.tables[name] for name in TABLE_NAMES]
    for table in CoreBase.metadata.sorted_tables:
        if table in tables:
            table.create(bind=bind)


def downgrade() -> None:
    bind = op.get_bind()
    tables = [CoreBase.metadata.tables[name] for name in TABLE_NAMES]
    for table in reversed(CoreBase.metadata.sorted_tables):
        if table in tables:
            table.drop(bind=bind)
