"""Phase 14.5 — Transaction Ledger schema (additive)."""
from alembic import op
from app.core.database import Base
import app.models  # noqa: F401

revision = "0006_phase_145_ledger"
down_revision = "0005_phase_144_callbacks"
branch_labels = None
depends_on = None

_LEDGER_TABLES = (
    "payment_transactions",
    "payment_transaction_fee_lines",
    "payment_ledger_entries",
)


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


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