Files
aios/scripts/self_optimize_v5.py

19 lines
1.3 KiB
Python

#!/usr/bin/env python3
from pathlib import Path
import os, sqlite3, time, argparse
parser=argparse.ArgumentParser(); parser.add_argument('--safe-only', action='store_true'); args=parser.parse_args()
root=Path(os.getenv('AIOS_WEBOPS_ROOT', Path(__file__).resolve().parents[1]/'active-runtime'))
db_path=Path(os.getenv('AIOS_WEBOPS_DB', root/'data'/'webops.sqlite3'))
if not db_path.exists():
db_path=root/'data'/'webops_v5.sqlite3'
db_path.parent.mkdir(parents=True, exist_ok=True)
con=sqlite3.connect(db_path)
now=time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
# Safe-only: only restore role migration order and illegal roles. Runtime/code changes still require owner approval.
con.execute("UPDATE routing_policy SET failover_priority=1,active_node='server-hw',backup_node='server-local',updated_at=? WHERE role='owner'",(now,))
con.execute("UPDATE routing_policy SET failover_priority=2,active_node='server-hw',backup_node='server-local',updated_at=? WHERE role='admin'",(now,))
con.execute("UPDATE routing_policy SET failover_priority=3,active_node='server-hw',backup_node='server-local',updated_at=? WHERE role='user'",(now,))
con.execute("UPDATE users SET role='user',updated_at=? WHERE role NOT IN ('owner','admin','user')",(now,))
con.commit(); con.close()
print('SELF_OPTIMIZE_V5_SAFE_FIX_OK')