mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
🐛 回退数据库问题
This commit is contained in:
parent
b68ba1ff80
commit
4638c5d021
@ -6,84 +6,84 @@ from nonebot.log import logger
|
|||||||
from LittlePaimon.config import GENSHIN_DB_PATH, SUB_DB_PATH, GENSHIN_VOICE_DB_PATH, MANAGER_DB_PATH, LEARNING_CHAT_DB_PATH
|
from LittlePaimon.config import GENSHIN_DB_PATH, SUB_DB_PATH, GENSHIN_VOICE_DB_PATH, MANAGER_DB_PATH, LEARNING_CHAT_DB_PATH
|
||||||
|
|
||||||
|
|
||||||
# DATABASE = {
|
DATABASE = {
|
||||||
# "connections": {
|
"connections": {
|
||||||
# "genshin": {
|
"genshin": {
|
||||||
# "engine": "tortoise.backends.sqlite",
|
"engine": "tortoise.backends.sqlite",
|
||||||
# "credentials": {"file_path": GENSHIN_DB_PATH},
|
"credentials": {"file_path": GENSHIN_DB_PATH},
|
||||||
# },
|
},
|
||||||
# "subscription": {
|
"subscription": {
|
||||||
# "engine": "tortoise.backends.sqlite",
|
"engine": "tortoise.backends.sqlite",
|
||||||
# "credentials": {"file_path": SUB_DB_PATH},
|
"credentials": {"file_path": SUB_DB_PATH},
|
||||||
# },
|
},
|
||||||
# 'genshin_voice': {
|
'genshin_voice': {
|
||||||
# "engine": "tortoise.backends.sqlite",
|
"engine": "tortoise.backends.sqlite",
|
||||||
# "credentials": {"file_path": GENSHIN_VOICE_DB_PATH},
|
"credentials": {"file_path": GENSHIN_VOICE_DB_PATH},
|
||||||
# },
|
},
|
||||||
# 'manager': {
|
'manager': {
|
||||||
# "engine": "tortoise.backends.sqlite",
|
"engine": "tortoise.backends.sqlite",
|
||||||
# "credentials": {"file_path": MANAGER_DB_PATH},
|
"credentials": {"file_path": MANAGER_DB_PATH},
|
||||||
# },
|
},
|
||||||
# 'learning_chat': {
|
'learning_chat': {
|
||||||
# "engine": "tortoise.backends.sqlite",
|
"engine": "tortoise.backends.sqlite",
|
||||||
# "credentials": {"file_path": LEARNING_CHAT_DB_PATH},
|
"credentials": {"file_path": LEARNING_CHAT_DB_PATH},
|
||||||
# },
|
},
|
||||||
|
},
|
||||||
|
"apps": {
|
||||||
|
"genshin": {
|
||||||
|
"models": ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'],
|
||||||
|
"default_connection": "genshin",
|
||||||
|
},
|
||||||
|
"subscription": {
|
||||||
|
"models": ['LittlePaimon.database.models.subscription'],
|
||||||
|
"default_connection": "subscription",
|
||||||
|
},
|
||||||
|
"genshin_voice": {
|
||||||
|
"models": ['LittlePaimon.database.models.genshin_voice'],
|
||||||
|
"default_connection": "genshin_voice",
|
||||||
|
},
|
||||||
|
"manager": {
|
||||||
|
"models": ['LittlePaimon.database.models.manager'],
|
||||||
|
"default_connection": "manager",
|
||||||
|
},
|
||||||
|
"learning_chat": {
|
||||||
|
"models": ['LittlePaimon.database.models.learning_chat'],
|
||||||
|
"default_connection": "learning_chat",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
# DATABASE = [
|
||||||
|
# {
|
||||||
|
# 'db_url': f'sqlite://{GENSHIN_DB_PATH}',
|
||||||
|
# 'models': ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'],
|
||||||
# },
|
# },
|
||||||
# "apps": {
|
# {
|
||||||
# "genshin": {
|
# 'db_url': f'sqlite://{SUB_DB_PATH}',
|
||||||
# "models": ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'],
|
# 'models': ['LittlePaimon.database.models.subscription'],
|
||||||
# "default_connection": "genshin",
|
|
||||||
# },
|
|
||||||
# "subscription": {
|
|
||||||
# "models": ['LittlePaimon.database.models.subscription'],
|
|
||||||
# "default_connection": "subscription",
|
|
||||||
# },
|
|
||||||
# "genshin_voice": {
|
|
||||||
# "models": ['LittlePaimon.database.models.genshin_voice'],
|
|
||||||
# "default_connection": "genshin_voice",
|
|
||||||
# },
|
|
||||||
# "manager": {
|
|
||||||
# "models": ['LittlePaimon.database.models.manager'],
|
|
||||||
# "default_connection": "manager",
|
|
||||||
# },
|
|
||||||
# "learning_chat": {
|
|
||||||
# "models": ['LittlePaimon.database.models.learning_chat'],
|
|
||||||
# "default_connection": "learning_chat",
|
|
||||||
# }
|
|
||||||
# },
|
# },
|
||||||
# }
|
# {
|
||||||
DATABASE = [
|
# 'db_url': f'sqlite://{GENSHIN_VOICE_DB_PATH}',
|
||||||
{
|
# 'models': ['LittlePaimon.database.models.genshin_voice'],
|
||||||
'db_url': f'sqlite://{GENSHIN_DB_PATH}',
|
# },
|
||||||
'models': ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'],
|
# {
|
||||||
},
|
# 'db_url': f'sqlite://{MANAGER_DB_PATH}',
|
||||||
{
|
# 'models': ['LittlePaimon.database.models.manager'],
|
||||||
'db_url': f'sqlite://{SUB_DB_PATH}',
|
# },
|
||||||
'models': ['LittlePaimon.database.models.subscription'],
|
# {
|
||||||
},
|
# 'db_url': f'sqlite://{LEARNING_CHAT_DB_PATH}',
|
||||||
{
|
# 'models': ['LittlePaimon.database.models.learning_chat'],
|
||||||
'db_url': f'sqlite://{GENSHIN_VOICE_DB_PATH}',
|
# },
|
||||||
'models': ['LittlePaimon.database.models.genshin_voice'],
|
# ]
|
||||||
},
|
|
||||||
{
|
|
||||||
'db_url': f'sqlite://{MANAGER_DB_PATH}',
|
|
||||||
'models': ['LittlePaimon.database.models.manager'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'db_url': f'sqlite://{LEARNING_CHAT_DB_PATH}',
|
|
||||||
'models': ['LittlePaimon.database.models.learning_chat'],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def register_database(db_path: Optional[Union[str, Path]], models: List[Union[str, Path]]):
|
# def register_database(db_path: Optional[Union[str, Path]], models: List[Union[str, Path]]):
|
||||||
"""
|
# """
|
||||||
注册数据库
|
# 注册数据库
|
||||||
"""
|
# """
|
||||||
DATABASE.append({
|
# DATABASE.append({
|
||||||
'db_url': f'sqlite://{db_path}',
|
# 'db_url': f'sqlite://{db_path}',
|
||||||
'models': models,
|
# 'models': models,
|
||||||
})
|
# })
|
||||||
|
|
||||||
|
|
||||||
async def connect():
|
async def connect():
|
||||||
@ -91,12 +91,13 @@ async def connect():
|
|||||||
建立数据库连接
|
建立数据库连接
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
for db in DATABASE:
|
# for db in DATABASE:
|
||||||
await Tortoise.init(
|
# await Tortoise.init(
|
||||||
db_url=db['db_url'],
|
# db_url=db['db_url'],
|
||||||
modules={'models': db['models']},
|
# modules={'models': db['models']},
|
||||||
)
|
# )
|
||||||
await Tortoise.generate_schemas()
|
await Tortoise.init(DATABASE)
|
||||||
|
await Tortoise.generate_schemas()
|
||||||
logger.opt(colors=True).success("<u><y>[数据库]</y></u><g>连接成功</g>")
|
logger.opt(colors=True).success("<u><y>[数据库]</y></u><g>连接成功</g>")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.opt(colors=True).warning(f"<u><y>[数据库]</y></u><r>连接失败:{e}</r>")
|
logger.opt(colors=True).warning(f"<u><y>[数据库]</y></u><r>连接失败:{e}</r>")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user