Files
aufmass-web/_aufmass_web/scripts/migrate_formel.py
T

17 lines
640 B
Python

"""Add formel_typ, formel columns to positionen."""
import sqlite3, os
db_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'data', 'aufmass.db'))
if not os.path.exists(db_path):
print("No DB found, skipping."); exit(0)
conn = sqlite3.connect(db_path); c = conn.cursor()
c.execute("PRAGMA table_info(positionen)")
cols = [r[1] for r in c.fetchall()]
for col, typ in [('formel_typ','VARCHAR(10)'), ('formel','VARCHAR(300)')]:
if col not in cols:
c.execute(f"ALTER TABLE positionen ADD COLUMN {col} {typ}")
print(f"Added {col} to positionen")
conn.commit(); conn.close()
print("Migration done.")