Initial commit: WealthWise financial analytics platform
This commit is contained in:
25
backend/scripts/init_db.py
Normal file
25
backend/scripts/init_db.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""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())
|
||||
Reference in New Issue
Block a user