Fix CI timezone and fresh settings initialization
CI / Frontend build (push) Successful in 12s
CI / Backend tests (push) Failing after 15s
CI / Script syntax (push) Successful in 3s

This commit is contained in:
Codex
2026-07-15 01:13:29 +02:00
parent f5997b47d9
commit 88e6d042cd
4 changed files with 90 additions and 17 deletions
+50 -15
View File
@@ -1,7 +1,9 @@
from __future__ import annotations
import sqlite3
from .db import db, utc_now
from .migrations import DEFAULT_SETTINGS
from .migrations import DEFAULT_SETTINGS, run_migrations
INT_KEYS = {"default_retention_value", "max_concurrent_backups"}
@@ -27,9 +29,20 @@ def serialize_value(key: str, value) -> str:
return str(value)
def _is_missing_settings_table(exc: sqlite3.OperationalError) -> bool:
return "no such table: settings" in str(exc).lower()
def get_settings() -> dict:
with db() as conn:
rows = conn.execute("SELECT key, value FROM settings").fetchall()
try:
with db() as conn:
rows = conn.execute("SELECT key, value FROM settings").fetchall()
except sqlite3.OperationalError as exc:
if not _is_missing_settings_table(exc):
raise
run_migrations()
with db() as conn:
rows = conn.execute("SELECT key, value FROM settings").fetchall()
raw = {row["key"]: row["value"] for row in rows}
for key, value in DEFAULT_SETTINGS.items():
raw.setdefault(key, value)
@@ -42,22 +55,44 @@ def set_settings(values: dict) -> dict:
unknown = set(values) - valid_keys
if unknown:
raise ValueError(f"Unknown settings: {', '.join(sorted(unknown))}")
with db() as conn:
for key, value in values.items():
conn.execute(
"""
INSERT INTO settings(key, value, updated_at)
VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at
""",
(key, serialize_value(key, value), now),
)
try:
with db() as conn:
for key, value in values.items():
conn.execute(
"""
INSERT INTO settings(key, value, updated_at)
VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at
""",
(key, serialize_value(key, value), now),
)
except sqlite3.OperationalError as exc:
if not _is_missing_settings_table(exc):
raise
run_migrations()
with db() as conn:
for key, value in values.items():
conn.execute(
"""
INSERT INTO settings(key, value, updated_at)
VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at
""",
(key, serialize_value(key, value), now),
)
return get_settings()
def get_setting(key: str, default: str = "") -> str:
with db() as conn:
row = conn.execute("SELECT value FROM settings WHERE key = ?", (key,)).fetchone()
try:
with db() as conn:
row = conn.execute("SELECT value FROM settings WHERE key = ?", (key,)).fetchone()
except sqlite3.OperationalError as exc:
if not _is_missing_settings_table(exc):
raise
run_migrations()
with db() as conn:
row = conn.execute("SELECT value FROM settings WHERE key = ?", (key,)).fetchone()
if row:
return row["value"]
return default