25 lines
704 B
Python
25 lines
704 B
Python
"""Initialize database tables.
|
|
|
|
This script creates all database tables defined in the models.
|
|
Run this before starting the application for the first time.
|
|
"""
|
|
|
|
import asyncio
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from app.core.config import get_settings
|
|
from app.models.base import BaseModel
|
|
|
|
settings = get_settings()
|
|
|
|
async def init_db():
|
|
"""Create all database tables."""
|
|
engine = create_async_engine(settings.DATABASE_URL, echo=True)
|
|
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(BaseModel.metadata.create_all)
|
|
|
|
await engine.dispose()
|
|
print("Database tables created successfully!")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(init_db()) |