Files
2026-04-23 00:39:58 -04:00

52 lines
2.0 KiB
Python

from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, UniqueConstraint, Index
from sqlalchemy.sql import func
from app.database import Base
class Playlist(Base):
__tablename__ = "playlists"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
spotify_id = Column(String, nullable=False, unique=True)
spotify_type = Column(String, nullable=False, default="playlist") # playlist | album | artist | track
description = Column(String, default="")
image_url = Column(String, default="")
emoji = Column(String, default="") # si está definido, reemplaza la imagen
created_at = Column(DateTime(timezone=True), server_default=func.now())
class VotingConfig(Base):
"""Single-row table — always query .first()."""
__tablename__ = "voting_config"
id = Column(Integer, primary_key=True)
start_time = Column(String, nullable=False, default="12:00") # "HH:MM"
end_time = Column(String, nullable=False, default="13:00") # "HH:MM"
is_active = Column(Boolean, default=False, nullable=False)
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
class Vote(Base):
__tablename__ = "votes"
id = Column(Integer, primary_key=True)
playlist_id = Column(Integer, ForeignKey("playlists.id", ondelete="CASCADE"), nullable=False)
voter_token = Column(String, nullable=False)
voted_at = Column(DateTime(timezone=True), nullable=False)
__table_args__ = (Index("ix_vote_voter_token_time", "voter_token", "voted_at"),)
class PlayHistory(Base):
__tablename__ = "play_history"
id = Column(Integer, primary_key=True)
track_id = Column(String, nullable=False)
track_name = Column(String, nullable=False)
artists = Column(String, nullable=False) # "Artist1, Artist2"
genres = Column(String, default="") # "rock, pop"
played_at = Column(DateTime(timezone=True), nullable=False)
__table_args__ = (UniqueConstraint("track_id", "played_at", name="uq_track_played_at"),)