Initial commit: AuroraMusic monorepo
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, func
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from .base import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
email: Mapped[str] = mapped_column(String(255), unique=True, index=True, nullable=False)
|
||||
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
display_name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
songs: Mapped[list["Song"]] = relationship(back_populates="owner", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class Song(Base):
|
||||
__tablename__ = "songs"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"))
|
||||
|
||||
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
prompt: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
lyrics: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
mode: Mapped[str] = mapped_column(String(20), default="instrumental") # instrumental | vocals
|
||||
|
||||
status: Mapped[str] = mapped_column(String(20), default="pending") # pending|processing|completed|failed
|
||||
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
audio_path: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
duration_seconds: Mapped[float | None] = mapped_column(nullable=True)
|
||||
cover_seed: Mapped[int] = mapped_column(Integer, default=0)
|
||||
|
||||
is_public: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
like_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
owner: Mapped["User"] = relationship(back_populates="songs")
|
||||
likes: Mapped[list["Like"]] = relationship(back_populates="song", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class Like(Base):
|
||||
__tablename__ = "likes"
|
||||
__table_args__ = (UniqueConstraint("user_id", "song_id", name="uq_like_user_song"),)
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"))
|
||||
song_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("songs.id", ondelete="CASCADE"))
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
song: Mapped["Song"] = relationship(back_populates="likes")
|
||||
Reference in New Issue
Block a user