import asyncio import os import sys # 保证根目录在 sys.path sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from app.core.database import engine, Base import app.models.proxy_reputation # 导入模型,确保注册到 Base.metadata async def init_tables(): print("⏳ 正在连接数据库并创建代理信誉相关数据表...") try: async with engine.begin() as conn: # 仅创建未存在的表 await conn.run_sync(Base.metadata.create_all) print("✅ 数据库表 proxy_reputation 和 proxy_telemetry_log 校验/创建完成!") except Exception as e: print(f"❌ 建表失败: {e}") finally: await engine.dispose() if __name__ == "__main__": asyncio.run(init_tables())