"""Phase 10.7+10.8 — Tracking, POD & Settlement schema (additive)."""
from alembic import op
from app.core.database import Base
import app.models  # noqa: F401

revision = "0008_phase_107_108_tracking_settlement"
down_revision = "0007_phase_106_routing"
branch_labels = None
depends_on = None

_NEW_TABLES = (
    "tracking_sessions",
    "tracking_points",
    "proof_of_delivery",
    "customer_tracking_tokens",
    "settlement_intents",
    "settlement_lines",
)


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


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