migration: preserve startup accounts and system slice
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from .http import SystemHttpMixin
|
||||
|
||||
__all__ = ["SystemHttpMixin"]
|
||||
@@ -0,0 +1,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import date
|
||||
from http import HTTPStatus
|
||||
|
||||
|
||||
class SystemHttpMixin:
|
||||
def save_system_settings(self) -> None:
|
||||
try:
|
||||
result = self.application_service.save_system_settings(self.read_json_body())
|
||||
self.send_json({"ok": True, **result})
|
||||
except (ValueError, json.JSONDecodeError) as exc:
|
||||
self.send_json({"error": str(exc)}, HTTPStatus.BAD_REQUEST)
|
||||
|
||||
def test_system_llm_settings(self) -> None:
|
||||
try:
|
||||
body = self.read_json_body()
|
||||
result = self.application_service.test_system_llm_profile(
|
||||
str(body.get("model_id") or ""), body.get("profile") or {}
|
||||
)
|
||||
self.send_json({"ok": True, "result": result})
|
||||
except (ValueError, json.JSONDecodeError) as exc:
|
||||
self.send_json({"error": str(exc)}, HTTPStatus.BAD_REQUEST)
|
||||
|
||||
def start_background_refresh(self) -> None:
|
||||
try:
|
||||
body = self.read_json_body(allow_empty=True)
|
||||
started = self.application_service.request_background_sync(
|
||||
str(body.get("trade_date") or date.today().isoformat())
|
||||
)
|
||||
self.send_json(
|
||||
{
|
||||
"ok": True,
|
||||
"started": started,
|
||||
"message": "后台刷新已开始" if started else "已有后台刷新任务正在运行",
|
||||
},
|
||||
HTTPStatus.ACCEPTED,
|
||||
)
|
||||
except (ValueError, json.JSONDecodeError) as exc:
|
||||
self.send_json({"error": str(exc)}, HTTPStatus.BAD_REQUEST)
|
||||
@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
class SystemSettingsRepositoryMixin:
|
||||
"""Original encrypted system-setting persistence methods."""
|
||||
|
||||
def get_system_setting(self, key: str) -> str:
|
||||
with self.connect() as connection:
|
||||
row = connection.execute(
|
||||
"SELECT encrypted_payload FROM system_settings WHERE setting_key = ?",
|
||||
(key,),
|
||||
).fetchone()
|
||||
return str(row["encrypted_payload"]) if row else ""
|
||||
|
||||
def save_system_setting(self, key: str, encrypted_payload: str) -> None:
|
||||
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
with self.connect() as connection:
|
||||
connection.execute(
|
||||
"""
|
||||
INSERT INTO system_settings (setting_key, encrypted_payload, updated_at)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT(setting_key) DO UPDATE SET
|
||||
encrypted_payload = excluded.encrypted_payload,
|
||||
updated_at = excluded.updated_at
|
||||
""",
|
||||
(key, encrypted_payload, now),
|
||||
)
|
||||
Reference in New Issue
Block a user