"""One-shot helper: apply db/npl_schema.sql against polleo_demand."""
from pathlib import Path
from sqlalchemy import create_engine, text

URL = "postgresql://polleo:polleo_dev@localhost:5432/polleo_demand"
SQL_PATH = Path(__file__).parent / "npl_schema.sql"

eng = create_engine(URL)
sql = SQL_PATH.read_text(encoding="utf-8")
with eng.connect() as c:
    c.exec_driver_sql(sql)
    c.commit()
    rows = c.execute(text(
        "SELECT table_name FROM information_schema.tables "
        "WHERE table_schema='public' AND table_name LIKE 'npl_%' "
        "ORDER BY table_name"
    )).fetchall()
    print("NPL tables created:", [r[0] for r in rows])
    enums = c.execute(text(
        "SELECT typname FROM pg_type WHERE typname LIKE 'npl_%' ORDER BY typname"
    )).fetchall()
    print("NPL enums:", [r[0] for r in enums])
