|
|
|
|
|
|
| import os, zipfile, sqlite3
|
| from .github_client import get_or_create_release, download_asset
|
|
|
|
|
| DATA_DIR = "data_enterprise"
|
|
|
| def restore_chroma_once():
|
|
|
| if os.path.exists("/tmp/.chroma_restored"):
|
| return
|
|
|
| print("[Restore] Starting Chroma DB restore from GitHub...")
|
|
|
| os.makedirs(DATA_DIR, exist_ok=True)
|
|
|
| release = get_or_create_release()
|
| zip_temp = "/tmp/chroma_restore.zip"
|
|
|
| if download_asset(release, "chroma_backup.zip", zip_temp):
|
| with zipfile.ZipFile(zip_temp, 'r') as z:
|
|
|
|
|
| z.extractall(DATA_DIR)
|
| print(f"[Restore] Chroma DB successfully extracted into {DATA_DIR}")
|
| else:
|
| print("[Restore] No Chroma backup found in GitHub Release.")
|
|
|
|
|
| open("/tmp/.chroma_restored", "w").close()
|
|
|
| def restore_sqlite_once():
|
|
|
| if os.path.exists("/tmp/.sqlite_restored"):
|
| return
|
|
|
| print("[Restore] Starting SQLite Cache restore from GitHub...")
|
| os.makedirs(DATA_DIR, exist_ok=True)
|
|
|
| release = get_or_create_release()
|
| zip_temp = "/tmp/sqlite_restore.zip"
|
|
|
| if download_asset(release, "sqlite_backup.zip", zip_temp):
|
| with zipfile.ZipFile(zip_temp, 'r') as z:
|
|
|
|
|
| z.extractall(DATA_DIR)
|
|
|
| db_path = os.path.join(DATA_DIR, "cache_store.db")
|
| if os.path.exists(db_path):
|
| try:
|
|
|
| conn = sqlite3.connect(db_path)
|
| conn.execute("DELETE FROM sqlite_sequence WHERE name='qa_cache';")
|
| conn.commit()
|
| conn.close()
|
| print(f"[Restore] SQLite DB restored and sequence cleaned.")
|
| except Exception as e:
|
| print(f"[Restore] SQLite sequence cleanup skipped: {e}")
|
| else:
|
| print("[Restore] No SQLite backup found in GitHub Release.")
|
|
|
|
|
| open("/tmp/.sqlite_restored", "w").close() |