S127 AstrBot启动迁移与仪表盘数据库配置
这个提交存在于:
父节点
6a88ced1d5
当前提交
1f5110a6ba
共有 3 个文件被更改,包括 24 次插入 和 2 次删除
|
|
@ -6,7 +6,7 @@ from backend.routes.common import handle_request
|
|||
from backend.services.dashboard_service import DashboardService
|
||||
from core.identity import RequestContext
|
||||
from core.security import require_authenticated
|
||||
from database.db_helper import Database
|
||||
from database.db_helper import Database, load_database_settings
|
||||
|
||||
|
||||
def get_dashboard_summary(
|
||||
|
|
@ -14,7 +14,7 @@ def get_dashboard_summary(
|
|||
service: DashboardService | None = None,
|
||||
database: Database | None = None,
|
||||
) -> dict:
|
||||
dashboard_service = service or DashboardService(database or Database())
|
||||
dashboard_service = service or DashboardService(database or Database(load_database_settings()))
|
||||
|
||||
def action() -> dict:
|
||||
require_authenticated(ctx)
|
||||
|
|
|
|||
10
main.py
10
main.py
|
|
@ -30,6 +30,7 @@ from adapters.webui_adapter import get_web_mount_manifest
|
|||
from backend.route_registry import ROUTES
|
||||
from backend.services.ui_service import API_BASE
|
||||
from core.identity import RequestContext
|
||||
from database.db_helper import Database, DatabaseSettings, load_database_settings
|
||||
|
||||
|
||||
PLUGIN_NAME = "astrbot_plugin_imagestudio"
|
||||
|
|
@ -75,6 +76,12 @@ def get_runtime_health() -> dict[str, Any]:
|
|||
return runtime_health()
|
||||
|
||||
|
||||
def initialize_runtime_database(settings: DatabaseSettings | None = None) -> dict[str, Any]:
|
||||
database = Database(settings or load_database_settings())
|
||||
database.initialize()
|
||||
return {"initialized": True, "backend": database.backend}
|
||||
|
||||
|
||||
def dispatch_web_request(
|
||||
ctx: RequestContext,
|
||||
method: str,
|
||||
|
|
@ -158,10 +165,13 @@ class Main(AstrBotStar):
|
|||
super().__init__()
|
||||
self.context = context
|
||||
self.registration_result: dict[str, Any] | None = None
|
||||
self.database_result: dict[str, Any] | None = None
|
||||
|
||||
async def initialize(self) -> None:
|
||||
if self.context is not None:
|
||||
self.registration_result = register_plugin(self.context)
|
||||
if self.registration_result.get("bridge_api", {}).get("registered"):
|
||||
self.database_result = initialize_runtime_database()
|
||||
return None
|
||||
|
||||
async def terminate(self) -> None:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from backend.route_registry import ROUTES
|
||||
from core.identity import RequestContext
|
||||
from database.db_helper import DatabaseSettings, SqliteSettings
|
||||
from main import (
|
||||
Main,
|
||||
PLUGIN_NAME,
|
||||
|
|
@ -13,6 +15,7 @@ from main import (
|
|||
dispatch_web_request,
|
||||
get_plugin_manifest,
|
||||
get_runtime_health,
|
||||
initialize_runtime_database,
|
||||
register_bridge_api,
|
||||
register_plugin,
|
||||
)
|
||||
|
|
@ -102,6 +105,15 @@ class PluginEntrypointTests(unittest.TestCase):
|
|||
self.assertEqual(response["status"], "ok")
|
||||
self.assertEqual(response["data"]["plugin_name"], PLUGIN_NAME)
|
||||
|
||||
def test_initialize_runtime_database_runs_migrations(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
db_path = Path(tmp) / "imagestudio.db"
|
||||
result = initialize_runtime_database(DatabaseSettings(sqlite=SqliteSettings(path=str(db_path))))
|
||||
|
||||
self.assertTrue(result["initialized"])
|
||||
self.assertEqual(result["backend"], "sqlite")
|
||||
self.assertTrue(db_path.exists())
|
||||
|
||||
def test_astrbot_main_class_exposes_manifest(self):
|
||||
plugin = Main(context=object())
|
||||
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用