"""Phase 14.3 — Payment Requests schema (additive)."""
from alembic import op
from app.core.database import Base
import app.models  # noqa: F401

revision = "0004_phase_143_requests"
down_revision = "0003_phase_142_merchant"
branch_labels = None
depends_on = None

_REQUEST_TABLES = (
    "payment_requests",
    "payment_request_status_history",
    "payment_request_lines",
)


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


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