"""创建推广员、推广码、线索与订单归因表。"""

from alembic import op

from zbt.infrastructure.mysql.core_models import CoreBase

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

TABLE_NAMES = (
    "salespersons",
    "promotion_codes",
    "lead_attributions",
    "order_attributions",
)


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)
