api/app/db/init_db.py
2025-04-09 23:00:06 +08:00

21 lines
629 B
Python

import asyncio
from app.db.database import Base, engine
from app.models.users import User
from app.models.person_images import PersonImage
from app.models.clothing import ClothingCategory, Clothing
from app.models.tryon import TryonHistory
# 创建所有表格
async def init_db():
async with engine.begin() as conn:
# 在SQLAlchemy 2.0中可以直接使用异步创建表
await conn.run_sync(Base.metadata.create_all)
# 同步入口点
def init_db_sync():
asyncio.run(init_db())
if __name__ == "__main__":
print("创建数据库表...")
init_db_sync()
print("数据库表创建完成。")