Files
sdb2-backend/app/models/sound.py
JSC 6068599a47
All checks were successful
Backend CI / lint (push) Successful in 9m49s
Backend CI / test (push) Successful in 6m15s
Refactor test cases for improved readability and consistency
- Adjusted function signatures in various test files to enhance clarity by aligning parameters.
- Updated patching syntax for better readability across test cases.
- Improved formatting and spacing in test assertions and mock setups.
- Ensured consistent use of async/await patterns in async test functions.
- Enhanced comments for better understanding of test intentions.
2025-08-01 20:53:30 +02:00

39 lines
1.5 KiB
Python

from typing import TYPE_CHECKING
from sqlmodel import Field, Relationship, UniqueConstraint
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
class Sound(BaseModel, table=True):
"""Database model for a sound."""
type: str = Field(nullable=False)
name: str = Field(nullable=False)
filename: str = Field(nullable=False)
duration: int = Field(default=0, ge=0, nullable=False)
size: int = Field(default=0, ge=0, nullable=False)
hash: str = Field(nullable=False)
normalized_filename: str | None = Field(default=None)
normalized_duration: int | None = Field(default=None, ge=0)
normalized_size: int | None = Field(default=None, ge=0)
normalized_hash: str | None = Field(default=None)
thumbnail: str | None = Field(default=None)
play_count: int = Field(default=0, ge=0, nullable=False)
is_normalized: bool = Field(default=False, nullable=False)
is_music: bool = Field(default=False, nullable=False)
is_deletable: bool = Field(default=True, nullable=False)
# constraints
__table_args__ = (UniqueConstraint("hash", name="uq_sound_hash"),)
# relationships
playlist_sounds: list["PlaylistSound"] = Relationship(back_populates="sound")
extractions: list["Extraction"] = Relationship(back_populates="sound")
play_history: list["SoundPlayed"] = Relationship(back_populates="sound")