"""Phase 14.2 — Merchant Accounts schema (additive)."""
from alembic import op
from app.core.database import Base
import app.models  # noqa: F401

revision = "0003_phase_142_merchant"
down_revision = "0002_phase_141_psp"
branch_labels = None
depends_on = None

_MERCHANT_TABLES = (
    "merchant_accounts",
    "merchant_account_profiles",
    "merchant_settlement_profiles",
    "merchant_compliance_refs",
    "merchant_account_status_history",
)


def upgrade():
    bind = op.get_bind()
    Base.metadata.create_all(bind=bind)


def downgrade():
    bind = op.get_bind()
    for name in reversed(_MERCHANT_TABLES):
        table = Base.metadata.tables.get(name)
        if table is not None:
            table.drop(bind=bind, checkfirst=True)
