initial commit
This commit is contained in:
62
backend/app/models/models.py
Normal file
62
backend/app/models/models.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Table, DateTime, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from app.database import Base
|
||||
|
||||
playlist_songs = Table('playlist_songs', Base.metadata,
|
||||
Column('playlist_id', Integer, ForeignKey('playlists.id')),
|
||||
Column('song_id', Integer, ForeignKey('songs.id'))
|
||||
)
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
username = Column(String, unique=True, index=True)
|
||||
email = Column(String, unique=True, index=True)
|
||||
hashed_password = Column(String)
|
||||
is_admin = Column(Boolean, default=False)
|
||||
is_owner = Column(Boolean, default=False)
|
||||
is_banned = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
songs = relationship("Song", back_populates="owner")
|
||||
playlists = relationship("Playlist", back_populates="owner")
|
||||
rooms = relationship("Room", back_populates="creator")
|
||||
|
||||
class Song(Base):
|
||||
__tablename__ = "songs"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, index=True)
|
||||
artist = Column(String)
|
||||
file_path = Column(String)
|
||||
cover_path = Column(String, nullable=True)
|
||||
duration = Column(Integer)
|
||||
owner_id = Column(Integer, ForeignKey("users.id"))
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
owner = relationship("User", back_populates="songs")
|
||||
playlists = relationship("Playlist", secondary=playlist_songs, back_populates="songs")
|
||||
|
||||
class Playlist(Base):
|
||||
__tablename__ = "playlists"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String)
|
||||
description = Column(String, nullable=True)
|
||||
is_public = Column(Boolean, default=False)
|
||||
owner_id = Column(Integer, ForeignKey("users.id"))
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
owner = relationship("User", back_populates="playlists")
|
||||
songs = relationship("Song", secondary=playlist_songs, back_populates="playlists")
|
||||
|
||||
class Room(Base):
|
||||
__tablename__ = "rooms"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String)
|
||||
code = Column(String, unique=True, index=True)
|
||||
creator_id = Column(Integer, ForeignKey("users.id"))
|
||||
current_song_id = Column(Integer, ForeignKey("songs.id"), nullable=True)
|
||||
is_playing = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
creator = relationship("User", back_populates="rooms")
|
||||
Reference in New Issue
Block a user