Scheme fixed for v2.4 (nee v3)
This commit is contained in:
parent
2d886f3413
commit
64799ccc61
171
app/models.py
171
app/models.py
@ -9,7 +9,7 @@ from datetime import datetime
|
||||
from typing import List, Optional
|
||||
#
|
||||
# from pydub import AudioSegment
|
||||
# from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
# from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
@ -20,7 +20,7 @@ from sqlalchemy import (
|
||||
# func,
|
||||
Integer,
|
||||
String,
|
||||
# UniqueConstraint,
|
||||
UniqueConstraint,
|
||||
select,
|
||||
)
|
||||
# from sqlalchemy.exc import IntegrityError
|
||||
@ -52,13 +52,19 @@ Base = declarative_base()
|
||||
class NoteColours(Base):
|
||||
__tablename__ = 'notecolours'
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
substring: str = Column(String(256), index=False)
|
||||
colour: str = Column(String(21), index=False)
|
||||
enabled: bool = Column(Boolean, default=True, index=True)
|
||||
is_regex: bool = Column(Boolean, default=False, index=False)
|
||||
is_casesensitive: bool = Column(Boolean, default=False, index=False)
|
||||
order: int = Column(Integer, index=True)
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
substring = Column(String(256), index=False)
|
||||
colour = Column(String(21), index=False)
|
||||
enabled = Column(Boolean, default=True, index=True)
|
||||
is_regex = Column(Boolean, default=False, index=False)
|
||||
is_casesensitive = Column(Boolean, default=False, index=False)
|
||||
order = Column(Integer, index=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<NoteColour(id={self.id}, substring={self.substring}, "
|
||||
f"colour={self.colour}>"
|
||||
)
|
||||
#
|
||||
# def __init__(
|
||||
# self, session: Session, substring: str, colour: str,
|
||||
@ -74,12 +80,6 @@ class NoteColours(Base):
|
||||
# session.add(self)
|
||||
# session.flush()
|
||||
#
|
||||
# def __repr__(self) -> str:
|
||||
# return (
|
||||
# f"<NoteColour(id={self.id}, substring={self.substring}, "
|
||||
# f"colour={self.colour}>"
|
||||
# )
|
||||
#
|
||||
# @classmethod
|
||||
# def get_all(cls, session: Session) -> Optional[List["NoteColours"]]:
|
||||
# """Return all records"""
|
||||
@ -122,17 +122,17 @@ class NoteColours(Base):
|
||||
# return rec.colour
|
||||
#
|
||||
# return None
|
||||
|
||||
|
||||
class Notes(Base):
|
||||
__tablename__ = 'notes'
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
playlist_id: int = Column(Integer, ForeignKey('playlists.id'))
|
||||
playlist: RelationshipProperty = relationship(
|
||||
"Playlists", back_populates="notes", lazy="joined")
|
||||
row: int = Column(Integer, nullable=False)
|
||||
note: str = Column(String(256), index=False)
|
||||
#
|
||||
#
|
||||
#class Notes(Base):
|
||||
# __tablename__ = 'notes'
|
||||
#
|
||||
# id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
# playlist_id: int = Column(Integer, ForeignKey('playlists.id'))
|
||||
# playlist: RelationshipProperty = relationship(
|
||||
# "Playlists", back_populates="notes", lazy="joined")
|
||||
# row: int = Column(Integer, nullable=False)
|
||||
# note: str = Column(String(256), index=False)
|
||||
#
|
||||
# def __init__(self, session: Session, playlist_id: int,
|
||||
# row: int, text: str) -> None:
|
||||
@ -213,10 +213,15 @@ class Playdates(Base):
|
||||
__tablename__ = 'playdates'
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
lastplayed: datetime = Column(DateTime, index=True, default=None)
|
||||
track_id: int = Column(Integer, ForeignKey('tracks.id'))
|
||||
track: RelationshipProperty = relationship(
|
||||
"Tracks", back_populates="playdates", lazy="joined")
|
||||
lastplayed = Column(DateTime, index=True, default=None)
|
||||
track_id = Column(Integer, ForeignKey('tracks.id'))
|
||||
track = relationship("Tracks", back_populates="playdates")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<Playdates(id={self.id}, track_id={self.track_id} "
|
||||
f"lastplayed={self.lastplayed}>"
|
||||
)
|
||||
#
|
||||
# def __init__(self, session: Session, track_id: int) -> None:
|
||||
# """Record that track was played"""
|
||||
@ -268,23 +273,20 @@ class Playlists(Base):
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name: str = Column(String(32), nullable=False, unique=True)
|
||||
last_used: datetime = Column(DateTime, default=None, nullable=True)
|
||||
last_used = Column(DateTime, default=None, nullable=True)
|
||||
loaded: bool = Column(Boolean, default=True, nullable=False)
|
||||
# notes = relationship(
|
||||
# "Notes", order_by="Notes.row",
|
||||
# back_populates="playlist", lazy="select"
|
||||
# )
|
||||
#
|
||||
# tracks = association_proxy('playlist_tracks', 'tracks')
|
||||
# row = association_proxy('playlist_tracks', 'row')
|
||||
rows = relationship("PlaylistRows", back_populates="playlist",
|
||||
cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Playlists(id={self.id}, name={self.name}>"
|
||||
|
||||
|
||||
#
|
||||
# def __init__(self, session: Session, name: str) -> None:
|
||||
# self.name = name
|
||||
# session.add(self)
|
||||
# session.flush()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Playlists(id={self.id}, name={self.name}>"
|
||||
#
|
||||
# def add_track(
|
||||
# self, session: Session, track_id: int,
|
||||
@ -409,30 +411,32 @@ class Playlists(Base):
|
||||
# cascade="all, delete-orphan"
|
||||
# )
|
||||
# )
|
||||
|
||||
|
||||
class PlaylistRows(Base):
|
||||
__tablename__ = 'playlist_rows'
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
playlist_id: int = Column(Integer, ForeignKey('playlists.id'),
|
||||
primary_key=True)
|
||||
row: int = Column(Integer, nullable=False)
|
||||
text: str = Column(String(2048), index=False)
|
||||
track_id: int = Column(Integer, ForeignKey('tracks.id'), primary_key=True)
|
||||
tracks: RelationshipProperty = relationship("Tracks")
|
||||
playlist: RelationshipProperty = relationship(
|
||||
Playlists,
|
||||
backref=backref(
|
||||
"playlist_tracks",
|
||||
collection_class=attribute_mapped_collection("row"),
|
||||
lazy="joined",
|
||||
cascade="all, delete-orphan"
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
row_number = Column(Integer, nullable=False)
|
||||
note = Column(String(2048), index=False)
|
||||
playlist_id = Column(Integer, ForeignKey('playlists.id'), nullable=False)
|
||||
playlist = relationship(Playlists, back_populates="rows")
|
||||
track_id = Column(Integer, ForeignKey('tracks.id'), nullable=True)
|
||||
track = relationship("Tracks", back_populates="playlistrows")
|
||||
|
||||
# Ensure row numbers are unique within each playlist
|
||||
__table_args__ = (UniqueConstraint
|
||||
('row_number', 'playlist_id', name="uniquerow"),
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<PlaylistRow(id={self.id}, playlist_id={self.playlist_id}, "
|
||||
f"track_id={self.track_id}, "
|
||||
f"note={self.note} row_number={self.row_number}>"
|
||||
)
|
||||
)
|
||||
# # Ensure row numbers are unique within each playlist
|
||||
# __table_args__ = (UniqueConstraint
|
||||
# ('row', 'playlist_id', name="uniquerow"),
|
||||
# )
|
||||
#
|
||||
|
||||
|
||||
# def __init__(
|
||||
# self, session: Session, playlist_id: int, track_id: int,
|
||||
# row: int) -> None:
|
||||
@ -478,9 +482,9 @@ class Settings(Base):
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name: str = Column(String(64), nullable=False, unique=True)
|
||||
f_datetime: datetime = Column(DateTime, default=None, nullable=True)
|
||||
f_datetime = Column(DateTime, default=None, nullable=True)
|
||||
f_int: int = Column(Integer, default=None, nullable=True)
|
||||
f_string: str = Column(String(128), default=None, nullable=True)
|
||||
f_string = Column(String(128), default=None, nullable=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
value = self.f_datetime or self.f_int or self.f_string
|
||||
@ -517,22 +521,25 @@ class Tracks(Base):
|
||||
__tablename__ = 'tracks'
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title: str = Column(String(256), index=True)
|
||||
artist: str = Column(String(256), index=True)
|
||||
duration: int = Column(Integer, index=True)
|
||||
start_gap: int = Column(Integer, index=False)
|
||||
fade_at: int = Column(Integer, index=False)
|
||||
silence_at: int = Column(Integer, index=False)
|
||||
path: str = Column(String(2048), index=False, nullable=False)
|
||||
mtime: float = Column(Float, index=True)
|
||||
lastplayed: datetime = Column(DateTime, index=True, default=None)
|
||||
playlists: RelationshipProperty = relationship("PlaylistRows",
|
||||
back_populates="tracks",
|
||||
lazy="joined")
|
||||
playdates: RelationshipProperty = relationship("Playdates",
|
||||
back_populates="track"
|
||||
"",
|
||||
lazy="joined")
|
||||
title = Column(String(256), index=True)
|
||||
artist = Column(String(256), index=True)
|
||||
duration = Column(Integer, index=True)
|
||||
start_gap = Column(Integer, index=False)
|
||||
fade_at = Column(Integer, index=False)
|
||||
silence_at = Column(Integer, index=False)
|
||||
path = Column(String(2048), index=False, nullable=False)
|
||||
mtime = Column(Float, index=True)
|
||||
lastplayed = Column(DateTime, index=True, default=None)
|
||||
playlistrows = relationship("PlaylistRows", back_populates="track")
|
||||
playlists = association_proxy("playlistrows", "playlist")
|
||||
playdates = relationship("Playdates", back_populates="track")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<Track(id={self.id}, title={self.title}, "
|
||||
f"artist={self.artist}, path={self.path}>"
|
||||
)
|
||||
#
|
||||
#
|
||||
# def __init__(
|
||||
# self,
|
||||
@ -560,12 +567,6 @@ class Tracks(Base):
|
||||
# session.add(self)
|
||||
# session.flush()
|
||||
#
|
||||
# def __repr__(self) -> str:
|
||||
# return (
|
||||
# f"<Track(id={self.id}, title={self.title}, "
|
||||
# f"artist={self.artist}, path={self.path}>"
|
||||
# )
|
||||
#
|
||||
# @staticmethod
|
||||
# def get_all_paths(session) -> List[str]:
|
||||
# """Return a list of paths of all tracks"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user