Spaces:
Build error
Build error
File size: 2,942 Bytes
09fa60b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | """Database models."""
from datetime import datetime, timezone
from typing import Optional
from uuid import UUID, uuid4
from sqlalchemy import JSON, Text, Integer, Float, String, DateTime, Boolean
from sqlalchemy.dialects.postgresql import UUID as PGUUID
from sqlalchemy.orm import Mapped, mapped_column
from app.db.database import Base
def utcnow() -> datetime:
"""Get current UTC datetime."""
return datetime.now(timezone.utc)
class Generation(Base):
"""Music generation record."""
__tablename__ = "generations"
id: Mapped[UUID] = mapped_column(
PGUUID(as_uuid=True),
primary_key=True,
default=uuid4,
)
prompt: Mapped[str] = mapped_column(Text, nullable=False)
lyrics: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
style: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
duration: Mapped[int] = mapped_column(Integer, default=30)
# Generation status
status: Mapped[str] = mapped_column(
String(20),
default="pending",
nullable=False,
) # pending, processing, completed, failed
# File paths
audio_path: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
instrumental_path: Mapped[Optional[str]] = mapped_column(
String(500), nullable=True
)
vocal_path: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
# Metadata
generation_metadata: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
# Timestamps
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=utcnow,
nullable=False,
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=utcnow,
onupdate=utcnow,
nullable=False,
)
completed_at: Mapped[Optional[datetime]] = mapped_column(
DateTime(timezone=True),
nullable=True,
)
# Error handling
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
# Processing metrics
processing_time_seconds: Mapped[Optional[float]] = mapped_column(
Float, nullable=True
)
class User(Base):
"""User model (for future authentication)."""
__tablename__ = "users"
id: Mapped[UUID] = mapped_column(
PGUUID(as_uuid=True),
primary_key=True,
default=uuid4,
)
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
username: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=utcnow,
)
|