Alibrown commited on
Commit
aecadf5
·
verified ·
1 Parent(s): 4e64bc1

Update app/db_sync.py

Browse files
Files changed (1) hide show
  1. app/db_sync.py +10 -10
app/db_sync.py CHANGED
@@ -47,22 +47,22 @@ _initialized: bool = False
47
  # =============================================================================
48
 
49
  async def initialize() -> None:
50
- """
51
- Initializes db_sync — reads SQLITE_PATH from .pyfun [DB_SYNC].
52
- Creates app/* tables if they don't exist.
53
- Called once by app/app.py during startup sequence.
54
- No fundaments passed in — fully sandboxed.
55
-
56
- Shares the SQLite file with user_handler.py (Guardian) but only
57
- manages its own tables. Guardian tables are never touched here.
58
- """
59
  global _db_path, _initialized
60
 
61
  if _initialized:
62
  return
63
 
64
  db_cfg = config.get_db_sync()
65
- _db_path = db_cfg.get("SQLITE_PATH", "app/.hub_state.db")
 
 
 
 
 
 
 
 
 
66
 
67
  await _init_tables()
68
 
 
47
  # =============================================================================
48
 
49
  async def initialize() -> None:
 
 
 
 
 
 
 
 
 
50
  global _db_path, _initialized
51
 
52
  if _initialized:
53
  return
54
 
55
  db_cfg = config.get_db_sync()
56
+ raw_path = db_cfg.get("SQLITE_PATH", "app/.hub_state.db")
57
+
58
+ # HF Spaces: SPACE_ID is set → filesystem is read-only except /tmp/
59
+ import os
60
+ if os.getenv("SPACE_ID"):
61
+ filename = os.path.basename(raw_path)
62
+ _db_path = f"/tmp/{filename}"
63
+ logger.info(f"HF Space detected — SQLite relocated to {_db_path}")
64
+ else:
65
+ _db_path = raw_path
66
 
67
  await _init_tables()
68