feat: 更新机器人配置并添加数据库迁移脚本

- 将bot_config_template.toml中的版本升级至7.9.0
- 增强数据库配置选项以支持PostgreSQL
- 引入一个新脚本,用于在SQLite、MySQL和PostgreSQL之间迁移数据
- 实现一个方言适配器,用于处理特定于数据库的行为和配置
This commit is contained in:
Windpicker-owo
2025-11-27 18:45:01 +08:00
parent 369639a8f1
commit 43483b934e
30 changed files with 1658 additions and 2226 deletions

View File

@@ -238,6 +238,14 @@ class BatchDatabaseWriter:
stmt = stmt.on_duplicate_key_update(
**{key: value for key, value in update_data.items() if key != "stream_id"}
)
elif global_config.database.database_type == "postgresql":
from sqlalchemy.dialects.postgresql import insert as pg_insert
stmt = pg_insert(ChatStreams).values(stream_id=stream_id, **update_data)
stmt = stmt.on_conflict_do_update(
index_elements=[ChatStreams.stream_id],
set_=update_data
)
else:
# 默认使用SQLite语法
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
@@ -264,6 +272,14 @@ class BatchDatabaseWriter:
stmt = stmt.on_duplicate_key_update(
**{key: value for key, value in update_data.items() if key != "stream_id"}
)
elif global_config.database.database_type == "postgresql":
from sqlalchemy.dialects.postgresql import insert as pg_insert
stmt = pg_insert(ChatStreams).values(stream_id=stream_id, **update_data)
stmt = stmt.on_conflict_do_update(
index_elements=[ChatStreams.stream_id],
set_=update_data
)
else:
from sqlalchemy.dialects.sqlite import insert as sqlite_insert