refactor(database): isolate configuration transactions

This commit is contained in:
InfinityPacer
2026-08-23 02:29:22 +08:00
parent e99289a07b
commit 3d7fb44dc7
23 changed files with 1071 additions and 153 deletions
+6 -1
View File
@@ -171,7 +171,7 @@ def ensure_optional_stub(name: str, **attrs) -> None:
def prepare_backend() -> None:
"""隔离 CONFIG_DIR、补 sites 垫片建表(后端须已在 ``sys.path`` 上)
"""隔离 CONFIG_DIR、补 sites 垫片建表并加载配置快照
主程序中后端即当前包;插件仓由其 ``tests/_bootstrap.py`` shim 在 import 本模块前
先把后端目录注入 ``sys.path``。顺序固定:先隔离 CONFIG_DIR,再补 ``app.application.site.sites`` 垫片,
@@ -182,6 +182,11 @@ def prepare_backend() -> None:
ensure_sites_stub()
from app.startup.database_initializer import init_db
init_db()
from app.db.oper.systemconfig import SystemConfigOper
from app.db.oper.userconfig import UserConfigOper
SystemConfigOper().load_snapshot()
UserConfigOper().load_snapshot()
# 缓存装饰器在测试模块导入时即创建后端,先装配隔离配置对应的适配器。
from app.startup.cache_initializer import configure_cache_dependencies
configure_cache_dependencies()