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
+33 -1
View File
@@ -1,14 +1,32 @@
from pathlib import Path
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
from .db import db, utc_now
def _normalize_timezone(value: str) -> str:
timezone_name = value.strip()
if not timezone_name:
return "UTC"
if timezone_name.startswith("/"):
marker = "/zoneinfo/"
if marker in timezone_name:
timezone_name = timezone_name.split(marker, 1)[1]
else:
timezone_name = timezone_name.lstrip("/")
try:
ZoneInfo(timezone_name)
except (ValueError, ZoneInfoNotFoundError):
return "UTC"
return timezone_name
def _system_timezone() -> str:
timezone_file = Path("/etc/timezone")
if timezone_file.exists():
value = timezone_file.read_text().strip()
if value:
return value
return _normalize_timezone(value)
return "UTC"
@@ -147,3 +165,17 @@ def run_migrations() -> None:
"INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
(3, now),
)
if 4 not in applied:
now = utc_now()
row = conn.execute("SELECT value FROM settings WHERE key = 'timezone'").fetchone()
if row:
normalized_timezone = _normalize_timezone(row["value"])
if normalized_timezone != row["value"]:
conn.execute(
"UPDATE settings SET value = ?, updated_at = ? WHERE key = 'timezone'",
(normalized_timezone, now),
)
conn.execute(
"INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
(4, now),
)