mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🎨 调整旧版数据库加载逻辑 (#212)
This commit is contained in:
@@ -17,11 +17,10 @@ def config_legacy(app: App, use_legacy_config):
|
||||
from nonebot_bison.config import config_legacy as config
|
||||
|
||||
config.start_up()
|
||||
|
||||
yield config.Config()
|
||||
|
||||
config.Config().db.close()
|
||||
legacy_config = Path(config.get_config_path()[0])
|
||||
legacy_config.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_create_and_get(config_legacy: "Config", app: App):
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
async def test_migration(use_legacy_config):
|
||||
from nonebot_plugin_datastore.db import init_db
|
||||
|
||||
from nonebot_bison.config.config_legacy import config as config_legacy
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
from nonebot_bison.config.db_config import config
|
||||
|
||||
config_legacy = Config()
|
||||
config_legacy.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
@@ -57,9 +58,10 @@ async def test_migration(use_legacy_config):
|
||||
async def test_migrate_dup(use_legacy_config):
|
||||
from nonebot_plugin_datastore.db import init_db
|
||||
|
||||
from nonebot_bison.config.config_legacy import config as config_legacy
|
||||
from nonebot_bison.config.config_legacy import Config
|
||||
from nonebot_bison.config.db_config import config
|
||||
|
||||
config_legacy = Config()
|
||||
config_legacy.add_subscribe(
|
||||
user=123,
|
||||
user_type="group",
|
||||
|
||||
+14
-3
@@ -84,9 +84,20 @@ async def init_scheduler(app: App):
|
||||
async def use_legacy_config(app: App):
|
||||
import aiofiles
|
||||
|
||||
from nonebot_bison.config.config_legacy import config, get_config_path
|
||||
from nonebot_bison.config.config_legacy import Config, get_config_path
|
||||
from nonebot_bison.utils import Singleton
|
||||
|
||||
async with aiofiles.open(get_config_path()[0], "w") as f:
|
||||
# 默认不创建配置所在的文件夹
|
||||
# 如果需要测试需要手动创建相关文件夹
|
||||
path = Path(get_config_path()[0])
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
async with aiofiles.open(path, "w") as f:
|
||||
await f.write("{}")
|
||||
|
||||
config._do_init()
|
||||
Config()._do_init()
|
||||
|
||||
yield
|
||||
|
||||
# 清除单例的缓存
|
||||
Singleton._instances.clear()
|
||||
|
||||
Reference in New Issue
Block a user