"""Phase 10.3 — Availability, Shifts & Working Zones schema (additive)."""
from alembic import op
from app.core.database import Base
import app.models  # noqa: F401

revision = "0004_phase_103_availability"
down_revision = "0003_phase_102_fleet"
branch_labels = None
depends_on = None

_NEW_TABLES = (
    "driver_availabilities",
    "shifts",
    "shift_assignments",
    "working_zones",
)


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)
