def __init__(self): """ Create database tables or manage update if needed """ f = Lio.File.new_for_path(self.DB_PATH) if not f.query_exists(): db_version = Lp().settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version) try: d = Lio.File.new_for_path(self.__LOCAL_PATH) if not d.query_exists(): d.make_directory_with_parents() # Create db schema with SqlCursor(self) as sql: sql.execute(self.__create_albums) sql.execute(self.__create_artists) sql.execute(self.__create_genres) sql.execute(self.__create_album_genres) sql.execute(self.__create_album_artists) sql.execute(self.__create_tracks) sql.execute(self.__create_track_artists) sql.execute(self.__create_track_genres) sql.execute(self.__create_album_artists_idx) sql.execute(self.__create_track_artists_idx) sql.execute(self.__create_album_genres_idx) sql.execute(self.__create_track_genres_idx) sql.commit() Lp().settings.set_value('db-version', GLib.Variant('i', upgrade.count())) except Exception as e: print("Database::__init__(): %s" % e)
def __init__(self): """ Create database tables or manage update if needed """ if os.path.exists(self.DB_PATH): with SqlCursor(self) as sql: db_version = Lp().settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version, self) upgrade.do_db_upgrade() Lp().settings.set_value('db-version', GLib.Variant('i', upgrade.count())) else: try: if not os.path.exists(self.LOCAL_PATH): os.mkdir(self.LOCAL_PATH) # Create db schema with SqlCursor(self) as sql: sql.execute(self.create_albums) sql.execute(self.create_artists) sql.execute(self.create_genres) sql.execute(self.create_album_genres) sql.execute(self.create_album_artists) sql.execute(self.create_tracks) sql.execute(self.create_track_artists) sql.execute(self.create_track_genres) sql.commit() except Exception as e: print("Database::__init__(): %s" % e)
def upgrade(self): """ Upgrade database """ db_version = Lp().settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version, self) if os.path.exists(self.DB_PATH): upgrade.do_db_upgrade() Lp().settings.set_value('db-version', GLib.Variant('i', upgrade.count()))
def upgrade(self): """ Upgrade database """ db_version = Lp().settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version) f = Lio.File.new_for_path(self.DB_PATH) if f.query_exists(): upgrade.do_db_upgrade() Lp().settings.set_value('db-version', GLib.Variant('i', upgrade.count()))