Skip to content
Snippets Groups Projects
Commit 791d8ce3 authored by David Trattnig's avatar David Trattnig
Browse files

Default playlist fields, db init. #52 #58

parent 4d4a2566
No related branches found
No related tags found
No related merge requests found
......@@ -101,15 +101,11 @@ class AuraDatabaseModel():
@staticmethod
def init_database():
"""
Initializes the database.
Initializes the database tables if they are not existing.
Raises:
sqlalchemy.exc.ProgrammingError: In case the DB model is invalid
"""
if AuraConfig.config().get("recreate_db") is not None:
AuraDatabaseModel.recreate_db(systemexit=True)
# Check if tables exists, if not create them
try:
Playlist.is_empty()
except sa.exc.ProgrammingError as e:
......@@ -125,7 +121,7 @@ class AuraDatabaseModel():
@staticmethod
def recreate_db(systemexit = False):
"""
Re-creates the database for developments purposes.
Deletes all tables and re-creates the database.
"""
Base.metadata.drop_all()
Base.metadata.create_all()
......@@ -144,6 +140,14 @@ class AuraDatabaseModel():
class Timeslot(DB.Model, AuraDatabaseModel):
"""
One specific timeslot for a show.
Relationships:
playlist (Playlist): The specific playlist for this timeslot
schedule_default (Playlist): Some playlist played by default, when no specific playlist is assigned
show_default (Playlist): Some playlist played by default, when no default schedule playlist is assigned
schedule_fallback (Playlist): Some playlist played as fallback, when no specific playlist is assigned or if it is errorneous (includes silence detection)
show_fallback (Playlist): Some playlist played as fallback, when no schedule fallback playlist is assigned or if some specific playlist is errorneous (includes silence detection)
station_fallback (Playlist): Defined in the original AURA API but not implemented, as station fallbacks are handled locally
"""
__tablename__ = 'timeslot'
......@@ -155,10 +159,18 @@ class Timeslot(DB.Model, AuraDatabaseModel):
primaryjoin="and_(Timeslot.timeslot_start==Playlist.timeslot_start, \
Timeslot.playlist_id==Playlist.playlist_id, Timeslot.show_name==Playlist.show_name)",
uselist=False, back_populates="timeslot")
default_schedule_playlist = relationship("Playlist",
primaryjoin="and_(Timeslot.timeslot_start==Playlist.timeslot_start, \
Timeslot.default_schedule_playlist_id==Playlist.playlist_id, Timeslot.show_name==Playlist.show_name)",
uselist=False, back_populates="timeslot")
default_show_playlist = relationship("Playlist",
primaryjoin="and_(Timeslot.timeslot_start==Playlist.timeslot_start, \
Timeslot.default_show_playlist_id==Playlist.playlist_id, Timeslot.show_name==Playlist.show_name)",
uselist=False, back_populates="timeslot")
schedule_fallback = relationship("Playlist",
primaryjoin="and_(Timeslot.timeslot_start==Playlist.timeslot_start, \
Timeslot.schedule_fallback_id==Playlist.playlist_id, Timeslot.show_name==Playlist.show_name)",
uselist=False, back_populates="timeslot")
uselist=False, back_populates="timeslot")
show_fallback = relationship("Playlist",
primaryjoin="and_(Timeslot.timeslot_start==Playlist.timeslot_start, \
Timeslot.show_fallback_id==Playlist.playlist_id, Timeslot.show_name==Playlist.show_name)",
......@@ -169,6 +181,8 @@ class Timeslot(DB.Model, AuraDatabaseModel):
uselist=False, back_populates="timeslot")
playlist_id = Column(Integer)
default_schedule_playlist_id = Column(Integer)
default_show_playlist_id = Column(Integer)
schedule_fallback_id = Column(Integer)
show_fallback_id = Column(Integer)
station_fallback_id = Column(Integer)
......@@ -276,6 +290,8 @@ class Timeslot(DB.Model, AuraDatabaseModel):
"languages": self.languages,
"comment": self.comment,
"playlist_id": self.playlist_id,
"schedule_default_id": self.schedule_default_id,
"show_default_id": self.show_default_id,
"schedule_fallback_id": self.schedule_fallback_id,
"show_fallback_id": self.show_fallback_id,
"station_fallback_id": self.station_fallback_id,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment