Add database seeding functionality and enhance model relationships
- Implement initial data seeding for plans in the database. - Create a new `seed_all_data` function to manage seeding process. - Update `Sound` and `User` models to include relationships for `SoundPlayed` and `Stream`.
This commit is contained in:
@@ -6,6 +6,7 @@ from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.logging import get_logger
|
||||
from app.core.seeds import seed_all_data
|
||||
from app.models import ( # noqa: F401
|
||||
plan,
|
||||
playlist,
|
||||
@@ -45,6 +46,19 @@ async def init_db() -> None:
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(SQLModel.metadata.create_all)
|
||||
logger.info("Database tables created successfully")
|
||||
|
||||
# Seed initial data
|
||||
await seed_initial_data()
|
||||
|
||||
except Exception:
|
||||
logger.exception("Failed to initialize database")
|
||||
raise
|
||||
|
||||
|
||||
async def seed_initial_data() -> None:
|
||||
"""Seed initial data into the database."""
|
||||
logger = get_logger(__name__)
|
||||
logger.info("Starting initial data seeding")
|
||||
|
||||
async with AsyncSession(engine) as session:
|
||||
await seed_all_data(session)
|
||||
|
||||
Reference in New Issue
Block a user