import sqlite3, os

db_path = os.path.join(os.path.dirname(__file__), 'maestro.db')
conn = sqlite3.connect(db_path)
c = conn.cursor()

migrations = [
    ('clients', 'consignes_chargement', 'TEXT'),
    ('projets', 'consignes_chargement', 'TEXT'),
    ('pieces', 'consignes_chargement', 'TEXT'),
]

for table, col, typ in migrations:
    cols = [row[1] for row in c.execute(f"PRAGMA table_info({table})").fetchall()]
    if col not in cols:
        c.execute(f"ALTER TABLE {table} ADD COLUMN {col} {typ}")
        print(f"OK {table}.{col} ajouté")
    else:
        print(f"-- {table}.{col} déjà présent")

conn.commit()
conn.close()
print("Migration terminée")
