45 lines
1.1 KiB
Python
Executable File
45 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
数据库连接检查脚本
|
|
用于验证数据库配置和连接状态
|
|
"""
|
|
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
|
|
# 添加项目根目录到Python路径
|
|
sys.path.append(os.path.dirname(__file__))
|
|
|
|
from app.core.database import check_db_connection, close_db
|
|
from app.core.config import settings
|
|
|
|
|
|
async def main():
|
|
"""主函数:检查数据库连接"""
|
|
try:
|
|
print(f"正在检查数据库连接...")
|
|
print(f"数据库URL: {settings.DATABASE_URL}")
|
|
|
|
# 检查数据库连接
|
|
is_connected = await check_db_connection()
|
|
|
|
if is_connected:
|
|
print("✅ 数据库连接正常!")
|
|
else:
|
|
print("❌ 数据库连接失败!")
|
|
print("请检查:")
|
|
print("1. PostgreSQL服务是否运行")
|
|
print("2. 数据库配置是否正确")
|
|
print("3. 网络连接是否正常")
|
|
sys.exit(1)
|
|
|
|
except Exception as e:
|
|
print(f"❌ 数据库连接检查失败: {e}")
|
|
sys.exit(1)
|
|
finally:
|
|
await close_db()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |