Commit a47862d1 authored by David Trattnig's avatar David Trattnig
Browse files

Initial working version of trackservice table.

parent b0348592
......@@ -80,6 +80,7 @@ class AuraDatabaseModel():
def _asdict(self):
return self.__dict__
@staticmethod
def recreate_db(systemexit = False):
"""
......@@ -88,16 +89,13 @@ class AuraDatabaseModel():
manualschedule = Schedule()
manualschedule.schedule_id = 0
manualschedule.show_name = "Manual Show"
self.logger.debug("Recreating Database...")
DB.drop_all()
self.logger.debug("All dropped. creating...")
DB.create_all()
# self.logger.debug("inserting manual scheduling possibility and fallback trackservice schedule")
# DB.session.add(manualschedule)
# db.session.add(fallback_trackservice_schedule)
# self.logger.debug("all created. commiting...")
# self.logger.debug("inserting manual scheduling possibility and fallback trackservice schedule")
# DB.session.add(manualschedule)
# db.session.add(fallback_trackservice_schedule)
# self.logger.debug("all created. commiting...")
DB.session.commit()
self.logger.debug("Database recreated!")
if systemexit:
sys.exit(0)
......@@ -426,22 +424,27 @@ class TrackService(DB.Model, AuraDatabaseModel):
"""
__tablename__ = 'trackservice'
# Primary keys
trackservice_id = Column(Integer, primary_key=True, autoincrement=True)
schedule_entry_id = Column(Integer, ForeignKey("schedule_entry.id"))
playlist_id = Column(Integer, nullable=False)
entry_num = Column(Integer, nullable=False)
source = Column(String(255), nullable=False)
start = Column(DateTime, nullable=False, default=func.now())
__table_args__ = (
ForeignKeyConstraint(['playlist_id', 'entry_num'], ['schedule_entry.playlist_id', 'schedule_entry.entry_num']),
)
schedule_entry = relationship("ScheduleEntry", primaryjoin="and_(TrackService.playlist_id==ScheduleEntry.playlist_id, TrackService.entry_num==ScheduleEntry.entry_num)", lazy="joined")
schedule = relationship("Schedule", foreign_keys=[schedule_id], lazy="joined")
trackservice_entry = relationship("ScheduleEntry", foreign_keys=[playlist_id, entry_num], lazy="joined")
schedule_entry = relationship("ScheduleEntry", primaryjoin="and_(TrackService.schedule_entry_id==ScheduleEntry.id)", lazy="joined")
# Foreign keys
schedule_start = Column(DateTime, ForeignKey("schedule.schedule_start"))
artificial_playlist_entry_id = Column(Integer, ForeignKey("playlist_entry.artificial_id"))
# Data
entry_start = Column(DateTime, nullable=False, default=func.now())
schedule = relationship("Schedule", foreign_keys=[schedule_start], lazy="joined")
playlist_entry = relationship("PlaylistEntry", primaryjoin="and_(TrackService.artificial_playlist_entry_id==PlaylistEntry.artificial_id)", lazy="joined")
fallback = Column(String(255), nullable=True)
def __init__(self, playlist_entry):
"""
Initializes a trackservice entry based on a playlist entry.
"""
self.artificial_playlist_entry_id = playlist_entry.artificial_id
self.schedule_start = playlist_entry.playlist.schedule_start
@staticmethod
def select_one(trackservice_id):
......@@ -479,55 +482,55 @@ class TrackService(DB.Model, AuraDatabaseModel):
class TrackServiceSchedule(db.Model, AuraDatabaseModel):
"""
Trackservice is tracking every schedule.
"""
__tablename__ = 'trackservice_schedule'
# primary and foreign keys
ts_schedule_id = Column(Integer, primary_key=True, autoincrement=True)
schedule_id = Column(Integer, ForeignKey("schedule.schedule_id"))
schedule = relationship("Schedule", foreign_keys=[schedule_id], lazy="joined")
# class TrackServiceSchedule(DB.Model, AuraDatabaseModel):
# """
# Trackservice is tracking every schedule.
# """
# __tablename__ = 'trackservice_schedule'
# ------------------------------------------------------------------------------------------ #
@staticmethod
def select_one(schedule_id):
# damn BAND-AID
# db.session.commit()
# # primary and foreign keys
# ts_schedule_id = Column(Integer, primary_key=True, autoincrement=True)
# schedule_id = Column(Integer, ForeignKey("schedule.schedule_id"))
# schedule = relationship("Schedule", foreign_keys=[schedule_id], lazy="joined")
return db.session.query(ScheduleEntry).filter(TrackServiceSchedule.schedule_id == schedule_id).first()
# # ------------------------------------------------------------------------------------------ #
# @staticmethod
# def select_one(schedule_id):
# # damn BAND-AID
# # db.session.commit()
# return DB.session.query(PlaylistEntry).filter(TrackServiceSchedule.schedule_id == schedule_id).first()
class TrackServiceScheduleEntry(db.Model, AuraDatabaseModel):
"""
And a schedule can have multiple entries
"""
__tablename__ = 'trackservice_entry'
# class TrackServiceScheduleEntry(DB.Model, AuraDatabaseModel):
# """
# And a schedule can have multiple entries
# """
# __tablename__ = 'trackservice_entry'
# primary and foreign keys. the foreign keys here can be null, because of fallback stuff
ts_entry_id = Column(Integer, primary_key=True, autoincrement=True)
ts_schedule_id = Column(Integer, ForeignKey("trackservice_schedule.ts_schedule_id"), nullable=True)
playlist_id = Column(Integer, nullable=True)
entry_num = Column(Integer, nullable=True)
# # Primary and foreign keys. the foreign keys here can be null, because of fallback stuff
# ts_entry_id = Column(Integer, primary_key=True, autoincrement=True)
# ts_schedule_id = Column(Integer, ForeignKey("trackservice_schedule.ts_schedule_id"), nullable=True)
# artificial_playlist_id = Column(Integer, nullable=True)
# entry_num = Column(Integer, nullable=True)
fallback = Column(Boolean, default=False)
fallback_start = Column(DateTime, nullable=True, default=None)
source = Column(String(256), nullable=True, default=None)
# fallback = Column(Boolean, default=False)
# fallback_start = Column(DateTime, nullable=True, default=None)
# source = Column(String(256), nullable=True, default=None)
# foreign key definitions
__table_args__ = (
ForeignKeyConstraint(['playlist_id', 'entry_num'], ['schedule_entry.playlist_id', 'schedule_entry.entry_num']),
)
# # Foreign key definitions
# __table_args__ = (
# ForeignKeyConstraint(['artificial_playlist_id', 'entry_num'], ['playlist_entry.artificial_playlist_id', 'playlist_entry.entry_num']),
# )
trackservice_schedule = relationship("TrackServiceSchedule", foreign_keys=[ts_schedule_id], lazy="joined")
#trackservice_entry = relationship("ScheduleEntry", foreign_keys=[playlist_id, entry_num], lazy="joined")
trackservice_entry = relationship("ScheduleEntry", primaryjoin="and_(TrackServiceScheduleEntry.playlist_id==ScheduleEntry.playlist_id, TrackServiceScheduleEntry.entry_num==ScheduleEntry.entry_num)" , lazy="joined")
# trackservice_schedule = relationship("TrackServiceSchedule", foreign_keys=[ts_schedule_id], lazy="joined")
# #trackservice_entry = relationship("PlaylistEntry", foreign_keys=[playlist_id, entry_num], lazy="joined")
# trackservice_entry = relationship("PlaylistEntry", primaryjoin="and_(TrackServiceScheduleEntry.artificial_playlist_id==PlaylistEntry.artificial_playlist_id, TrackServiceScheduleEntry.entry_num==PlaylistEntry.entry_num)" , lazy="joined")
@staticmethod
def select_all():
return db.session.query(TrackServiceScheduleEntry).filter().all()
# @staticmethod
# def select_all():
# return DB.session.query(TrackServiceScheduleEntry).filter().all()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment