feat: Add Extraction model and seed main playlist functionality
This commit is contained in:
@@ -8,12 +8,12 @@ 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
|
||||
extraction,
|
||||
plan,
|
||||
playlist,
|
||||
playlist_sound,
|
||||
sound,
|
||||
sound_played,
|
||||
stream,
|
||||
user,
|
||||
user_oauth,
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
from app.core.logging import get_logger
|
||||
from app.models.plan import Plan
|
||||
from app.models.playlist import Playlist
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -52,12 +53,37 @@ async def seed_plans(session: AsyncSession) -> None:
|
||||
logger.info("Successfully seeded %d plans", len(initial_plans))
|
||||
|
||||
|
||||
async def seed_main_playlist(session: AsyncSession) -> None:
|
||||
"""Seed the main playlist with initial data."""
|
||||
logger.info("Seeding main playlist data")
|
||||
|
||||
# Check if the main playlist already exists
|
||||
existing_playlist = await session.exec(select(Playlist).where(Playlist.is_main))
|
||||
if existing_playlist.first():
|
||||
logger.info("Main playlist already exists, skipping seeding")
|
||||
return
|
||||
|
||||
# Create the main playlist
|
||||
main_playlist = Playlist(
|
||||
name="All",
|
||||
description="The default main playlist with all the tracks",
|
||||
is_main=True,
|
||||
is_deletable=False,
|
||||
is_current=True,
|
||||
)
|
||||
session.add(main_playlist)
|
||||
|
||||
await session.commit()
|
||||
logger.info("Successfully seeded main playlist")
|
||||
|
||||
|
||||
async def seed_all_data(session: AsyncSession) -> None:
|
||||
"""Seed all initial data."""
|
||||
logger.info("Starting data seeding")
|
||||
|
||||
try:
|
||||
await seed_plans(session)
|
||||
await seed_main_playlist(session)
|
||||
logger.info("Data seeding completed successfully")
|
||||
except Exception:
|
||||
logger.exception("Failed to seed data")
|
||||
|
||||
@@ -9,7 +9,7 @@ if TYPE_CHECKING:
|
||||
from app.models.user import User
|
||||
|
||||
|
||||
class Stream(BaseModel, table=True):
|
||||
class Extraction(BaseModel, table=True):
|
||||
"""Database model for a stream."""
|
||||
|
||||
service: str = Field(nullable=False)
|
||||
@@ -30,10 +30,10 @@ class Stream(BaseModel, table=True):
|
||||
UniqueConstraint(
|
||||
"service",
|
||||
"service_id",
|
||||
name="uq_stream_service_service_id",
|
||||
name="uq_extraction_service_service_id",
|
||||
),
|
||||
)
|
||||
|
||||
# relationships
|
||||
sound: "Sound" = Relationship(back_populates="streams")
|
||||
user: "User" = Relationship(back_populates="streams")
|
||||
sound: "Sound" = Relationship(back_populates="extractions")
|
||||
user: "User" = Relationship(back_populates="extractions")
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Relationship
|
||||
from app.models.base import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.models.extraction import Extraction
|
||||
from app.models.playlist_sound import PlaylistSound
|
||||
from app.models.sound_played import SoundPlayed
|
||||
from app.models.stream import Stream
|
||||
|
||||
|
||||
class Sound(BaseModel, table=True):
|
||||
@@ -31,5 +31,5 @@ class Sound(BaseModel, table=True):
|
||||
|
||||
# relationships
|
||||
playlist_sounds: list["PlaylistSound"] = Relationship(back_populates="sound")
|
||||
streams: list["Stream"] = Relationship(back_populates="sound")
|
||||
extractions: list["Extraction"] = Relationship(back_populates="sound")
|
||||
play_history: list["SoundPlayed"] = Relationship(back_populates="sound")
|
||||
|
||||
@@ -6,10 +6,10 @@ from sqlmodel import Field, Relationship
|
||||
from app.models.base import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.models.extraction import Extraction
|
||||
from app.models.plan import Plan
|
||||
from app.models.playlist import Playlist
|
||||
from app.models.sound_played import SoundPlayed
|
||||
from app.models.stream import Stream
|
||||
from app.models.user_oauth import UserOauth
|
||||
|
||||
|
||||
@@ -34,4 +34,4 @@ class User(BaseModel, table=True):
|
||||
plan: "Plan" = Relationship(back_populates="users")
|
||||
playlists: list["Playlist"] = Relationship(back_populates="user")
|
||||
sounds_played: list["SoundPlayed"] = Relationship(back_populates="user")
|
||||
streams: list["Stream"] = Relationship(back_populates="user")
|
||||
extractions: list["Extraction"] = Relationship(back_populates="user")
|
||||
|
||||
Reference in New Issue
Block a user