big changes in profiles and users

This commit is contained in:
Mateusz Gruszczyński
2026-05-26 09:00:29 +02:00
parent 629b06a9df
commit 92d870878f
9 changed files with 471 additions and 162 deletions

View File

@@ -73,9 +73,19 @@ def normalize_settings(data: dict | None) -> dict:
def get_settings(profile_id: int) -> dict:
with connect() as conn:
row = conn.execute("SELECT value FROM app_settings WHERE key=?", (_key(profile_id),)).fetchone()
row = conn.execute("SELECT settings_json FROM poller_settings WHERE profile_id=?", (int(profile_id),)).fetchone()
if not row:
# Note: Existing installs stored profile poller settings in app_settings; migrate lazily on first read.
legacy = conn.execute("SELECT value FROM app_settings WHERE key=?", (_key(profile_id),)).fetchone()
if legacy:
try:
settings = normalize_settings(json.loads(legacy.get("value") or "{}"))
except Exception:
settings = normalize_settings({})
conn.execute("INSERT OR REPLACE INTO poller_settings(profile_id,settings_json,updated_at) VALUES(?,?,?)", (int(profile_id), json.dumps(settings), utcnow()))
return settings
try:
data = json.loads(row.get("value") or "{}") if row else {}
data = json.loads(row.get("settings_json") or "{}") if row else {}
except Exception:
data = {}
return normalize_settings(data)
@@ -84,7 +94,7 @@ def get_settings(profile_id: int) -> dict:
def save_settings(profile_id: int, data: dict) -> dict:
settings = normalize_settings(data)
with connect() as conn:
conn.execute("INSERT OR REPLACE INTO app_settings(key,value) VALUES(?,?)", (_key(profile_id), json.dumps(settings)))
conn.execute("INSERT OR REPLACE INTO poller_settings(profile_id,settings_json,updated_at) VALUES(?,?,?)", (int(profile_id), json.dumps(settings), utcnow()))
return settings