import sys; sys.path.insert(0,"/app")
from app.database import SessionLocal
from sqlalchemy import text as sa_text
from scripts.fix_lab_formatting import repair_units, tabulate_panels
db = SessionLocal()
for qid, t in db.execute(sa_text("SELECT id, question_text FROM questions WHERE question_text IS NOT NULL ORDER BY id")).fetchall():
    f,_ = repair_units(t); out,k = tabulate_panels(f)
    if not k: continue
    print(f"### {qid}")
    for line in out.split("\n"):
        if line.startswith("|"): print("  ", line)
