#!/usr/bin/env python3 import sys, sqlite3, pathlib, shutil, os runtime=pathlib.Path(sys.argv[1] if len(sys.argv)>1 else os.environ.get('AIOS_RUNTIME_ROOT','.')).resolve(); webops=runtime/'webops' (webops/'data').mkdir(parents=True,exist_ok=True); (webops/'migrations').mkdir(parents=True,exist_ok=True) pkg=pathlib.Path(__file__).resolve().parents[1] for src in sorted((pkg/'migrations').glob('*.sql')): dst=webops/'migrations'/src.name if not dst.exists(): shutil.copy2(src,dst) con=sqlite3.connect(webops/'data'/'webops.sqlite3') for sqlf in sorted((webops/'migrations').glob('*.sql')): con.executescript(sqlf.read_text(encoding='utf-8')); con.commit() con.close(); print('MIGRATIONS_APPLIED', webops/'data'/'webops.sqlite3')