fix(stream): update service and sound_id fields to be nullable; adjust create_stream method parameters for optional values
This commit is contained in:
@@ -19,10 +19,10 @@ class Stream(db.Model):
|
||||
__tablename__ = "stream"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
service: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
service_id: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
service: Mapped[str] = mapped_column(String(50), nullable=True)
|
||||
service_id: Mapped[str] = mapped_column(String(255), nullable=True)
|
||||
sound_id: Mapped[int] = mapped_column(
|
||||
Integer, ForeignKey("sound.id"), nullable=False
|
||||
Integer, ForeignKey("sound.id"), nullable=True
|
||||
)
|
||||
url: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
title: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
|
||||
@@ -30,7 +30,9 @@ class Stream(db.Model):
|
||||
artist: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
album: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
genre: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(50), nullable=False, default="active")
|
||||
status: Mapped[str] = mapped_column(
|
||||
String(50), nullable=False, default="pending"
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
default=lambda: datetime.now(tz=ZoneInfo("UTC")),
|
||||
@@ -64,17 +66,21 @@ class Stream(db.Model):
|
||||
"album": self.album,
|
||||
"genre": self.genre,
|
||||
"status": self.status,
|
||||
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
|
||||
"created_at": (
|
||||
self.created_at.isoformat() if self.created_at else None
|
||||
),
|
||||
"updated_at": (
|
||||
self.updated_at.isoformat() if self.updated_at else None
|
||||
),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create_stream(
|
||||
cls,
|
||||
service: str,
|
||||
service_id: str,
|
||||
sound_id: int,
|
||||
url: str,
|
||||
service: Optional[str] = None,
|
||||
service_id: Optional[str] = None,
|
||||
sound_id: Optional[int] = None,
|
||||
title: Optional[str] = None,
|
||||
track: Optional[str] = None,
|
||||
artist: Optional[str] = None,
|
||||
@@ -108,7 +114,9 @@ class Stream(db.Model):
|
||||
cls, service: str, service_id: str
|
||||
) -> Optional["Stream"]:
|
||||
"""Find stream by service and service_id."""
|
||||
return cls.query.filter_by(service=service, service_id=service_id).first()
|
||||
return cls.query.filter_by(
|
||||
service=service, service_id=service_id
|
||||
).first()
|
||||
|
||||
@classmethod
|
||||
def find_by_sound(cls, sound_id: int) -> list["Stream"]:
|
||||
|
||||
Reference in New Issue
Block a user