Scheme fixed for v2.4 (nee v3)

This commit is contained in:
Keith Edmunds 2022-07-06 21:40:35 +01:00
parent 2d886f3413
commit 64799ccc61

View File

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