feat: models

This commit is contained in:
Senko-san
2026-06-07 14:50:35 +03:00
parent 87b48e941e
commit dfd512a13f
11 changed files with 732 additions and 1 deletions
+39
View File
@@ -0,0 +1,39 @@
"""ORM model for likes — an append-only event log.
A like/dislike is **never** updated in place. Current state for a ``(user,
track)`` pair is the latest event by ``created_at``. This shape is required for
future sync and as a clean ML signal (plan §4.1). Hence: no ``updated_at``,
no unique constraint on ``(user, track)``.
"""
import datetime as dt
import uuid
from sqlalchemy import DateTime, ForeignKey, Index, String, func
from sqlalchemy.orm import Mapped, mapped_column
from app.infrastructure.db.base import Base
from app.infrastructure.db.models.mixins import UUIDPrimaryKeyMixin
class LikeModel(UUIDPrimaryKeyMixin, Base):
__tablename__ = "likes"
__table_args__ = (
# Latest-event lookups query by (user, track) ordered by time.
Index("ix_likes_user_id_track_id", "user_id", "track_id"),
)
user_id: Mapped[uuid.UUID] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
)
track_id: Mapped[uuid.UUID] = mapped_column(
ForeignKey("tracks.id", ondelete="CASCADE"),
nullable=False,
)
value: Mapped[str] = mapped_column(String(16), nullable=False)
created_at: Mapped[dt.datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
nullable=False,
)