Files
docker-configs/discord_bot/init_db.py
Will Song 568dcc45e4 Fix router failover and add Discord bot
- Remove duplicate claude_api provider to fix automatic failover
- Enhance error detection with HTTP status codes and more indicators
- Add comprehensive README documentation with manual switching
- Implement Discord bot with Claude Code CLI integration
- Support /terminal and /claude commands with AI-powered responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 21:35:52 -05:00

59 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
"""
数据库初始化脚本
运行此脚本来创建必要的数据库表和初始数据
"""
import os
import sys
from pathlib import Path
# 添加项目路径
sys.path.append(str(Path(__file__).parent))
from utils.database import DatabaseManager
import logging
# 配置日志
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def main():
"""初始化数据库"""
try:
# 确保databases目录存在
db_dir = Path(__file__).parent / "databases"
db_dir.mkdir(exist_ok=True)
# 初始化数据库
db_path = str(db_dir / "discord_bot.db")
logger.info(f"初始化数据库: {db_path}")
db_manager = DatabaseManager(db_path)
# 验证数据库是否正确创建
tables = db_manager.execute_query("""
SELECT name FROM sqlite_master
WHERE type='table' AND name NOT LIKE 'sqlite_%'
""")
logger.info("已创建的表:")
for table in tables:
logger.info(f" - {table['name']}")
# 检查术语字典是否有数据
term_count = db_manager.execute_query("SELECT COUNT(*) as count FROM term_dic")[0]['count']
logger.info(f"术语字典包含 {term_count} 条记录")
logger.info("数据库初始化完成!")
except Exception as e:
logger.error(f"数据库初始化失败: {e}")
sys.exit(1)
if __name__ == "__main__":
main()