"""Phase 9.7 — Competition & Event Management schema."""
from alembic import op
import sqlalchemy as sa
from app.core.database import Base
import app.models  # noqa: F401

revision = "0008_phase_97_competitions"
down_revision = "0007_phase_96_training"
branch_labels = None
depends_on = None


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


def downgrade():
    bind = op.get_bind()
    for table in (
        "competition_certificates",
        "competition_judges",
        "competition_medals",
        "competition_rankings",
        "competition_results",
        "competition_matches",
        "competition_registrations",
        "competition_groups",
        "competition_teams",
        "competitions",
    ):
        if sa.inspect(bind).has_table(table):
            op.drop_table(table)
