mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🎨 调整旧版数据库加载逻辑 (#212)
This commit is contained in:
@@ -25,8 +25,6 @@ def get_config_path() -> tuple[str, str]:
|
||||
else:
|
||||
working_dir = os.getcwd()
|
||||
data_dir = path.join(working_dir, "data")
|
||||
if not path.isdir(data_dir):
|
||||
os.makedirs(data_dir)
|
||||
old_path = path.join(data_dir, "hk_reporter.json")
|
||||
new_path = path.join(data_dir, "bison.json")
|
||||
deprecated_maker_path = path.join(data_dir, "bison.json.deprecated")
|
||||
@@ -36,6 +34,7 @@ def get_config_path() -> tuple[str, str]:
|
||||
|
||||
|
||||
def drop():
|
||||
config = Config()
|
||||
if plugin_config.bison_config_path:
|
||||
data_dir = plugin_config.bison_config_path
|
||||
else:
|
||||
@@ -252,7 +251,7 @@ def start_up():
|
||||
return
|
||||
if not (search_res := config.kv_config.search(Query().name == "version")):
|
||||
config.kv_config.insert({"name": "version", "value": config.migrate_version})
|
||||
elif search_res[0].get("value") < config.migrate_version:
|
||||
elif search_res[0].get("value") < config.migrate_version: # type: ignore
|
||||
query = Query()
|
||||
version_query = query.name == "version"
|
||||
cur_version = search_res[0].get("value")
|
||||
@@ -268,6 +267,3 @@ def start_up():
|
||||
config.kv_config.update({"value": config.migrate_version}, version_query)
|
||||
# do migration
|
||||
config.update_send_cache()
|
||||
|
||||
|
||||
config = Config()
|
||||
|
||||
@@ -2,11 +2,12 @@ from nonebot.log import logger
|
||||
from nonebot_plugin_datastore.db import get_engine
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
|
||||
from .config_legacy import ConfigContent, config, drop
|
||||
from .config_legacy import Config, ConfigContent, drop
|
||||
from .db_model import Subscribe, Target, User
|
||||
|
||||
|
||||
async def data_migrate():
|
||||
config = Config()
|
||||
if config.available:
|
||||
logger.warning("You are still using legacy db, migrating to sqlite")
|
||||
all_subs: list[ConfigContent] = list(
|
||||
|
||||
Reference in New Issue
Block a user