""" Jednorázový skript — vytvoří/aktualizuje tabulky v MySQL. Spusť jednou: python create_iwrs_tables.py """ import os import mysql.connector import db_config BASE_DIR = os.path.dirname(os.path.abspath(__file__)) SQL_FILE = os.path.join(BASE_DIR, "create_iwrs_tables.sql") conn = mysql.connector.connect( host=db_config.DB_HOST, port=db_config.DB_PORT, user=db_config.DB_USER, password=db_config.DB_PASSWORD, database=db_config.DB_NAME, ) cursor = conn.cursor() sql = open(SQL_FILE, encoding="utf-8").read() # Odstraň komentáře a rozdělíme na příkazy stmts = [s.strip() for s in sql.split(";")] for stmt in stmts: # Odstraň řádkové komentáře lines = [l for l in stmt.splitlines() if not l.strip().startswith("--")] stmt = "\n".join(lines).strip() if not stmt or stmt.upper().startswith("USE"): continue try: cursor.execute(stmt) print(f"OK: {stmt[:80]}") except Exception as e: print(f"SKIP: {e}") conn.commit() cursor.close() conn.close() print("\nHotovo.")