diff --git a/playlist_manager/playlist_manager/main.py b/playlist_manager/playlist_manager/main.py index 23eec5e..cabf031 100644 --- a/playlist_manager/playlist_manager/main.py +++ b/playlist_manager/playlist_manager/main.py @@ -110,7 +110,11 @@ class PlaylistManager(object): [tag.lower() for tag in row.tags], row.first_event_id, row.last_event_id, - ) for row in query(conn, "SELECT playlist_id, tags, first_event_id, last_event_id FROM playlists WHERE tags IS NOT NULL") + ) for row in query(conn, """ + SELECT playlist_id, tags, first_event_id, last_event_id + FROM playlists + WHERE tags IS NOT NULL AND playlist_id IS NOT NULL + """) } self.dbmanager.put_conn(conn) duplicates = set(playlists) & set(self.static_playlists) diff --git a/postgres/setup.sh b/postgres/setup.sh index 2495c50..254947e 100644 --- a/postgres/setup.sh +++ b/postgres/setup.sh @@ -141,16 +141,24 @@ CREATE TABLE editors ( name TEXT NOT NULL ); +-- A slight misnomer, this is all rows of the tags sheet. +-- It includes tags that have been promoted to actual playlists, and ones that have not. -- Playlists are communicated to playlist manager via this table. CREATE TABLE playlists ( - playlist_id TEXT PRIMARY KEY, - name TEXT NOT NULL, + id TEXT PRIMARY KEY, + -- These are sheet inputs, and aren't used directly by anything (except reverse sync) + name TEXT NOT NULL DEFAULT '', + description TEXT NOT NULL DEFAULT '' -- When tags is NULL, it indicates tags have not been set and so the playlist should -- match nothing. Conversely, when tags is empty, it indicates the playlist should match everything. tags TEXT[], - first_event_id UUID REFERENCES events(id) ON DELETE SET NULL, - last_event_id UUID REFERENCES events(id) ON DELETE SET NULL, - show_in_description BOOLEAN NOT NULL + playlist_id TEXT, + show_in_description BOOLEAN NOT NULL DEFAULT FALSE, + -- These event ids are references into the events table, but they aren't foreign keys + -- because we don't want invalid input to cause integrity errors. + -- It's totally safe for these to point to non-existent events, it just does nothing. + first_event_id TEXT, + last_event_id TEXT ); -- This table records time series data gleaned from the bus cam (right now, just the odometer). diff --git a/sheetsync/sheetsync/main.py b/sheetsync/sheetsync/main.py index 6786460..12e5e1f 100644 --- a/sheetsync/sheetsync/main.py +++ b/sheetsync/sheetsync/main.py @@ -312,9 +312,12 @@ class PlaylistsSync(SheetSync): table = "playlists" input_columns = { - "playlist_id", - "tags", "name", + "description", + "tags", + "playlist_id", + "first_event_id", + "last_event_id", "show_in_description", } diff --git a/sheetsync/sheetsync/streamlog.py b/sheetsync/sheetsync/streamlog.py index 0055880..9db2eb7 100644 --- a/sheetsync/sheetsync/streamlog.py +++ b/sheetsync/sheetsync/streamlog.py @@ -65,9 +65,11 @@ class StreamLogPlaylistsMiddleware(Middleware): # Special case for the "all everything" list, otherwise all playlists have a single tag. "tags": [] if tag["tag"] == "" else [tag["tag"]], "playlist_id": tag["playlist"] + "description": tag["description"], "name": "unknown", # TODO missing in StreamLog "show_in_description": False, # TODO missing in StreamLog - "description": tag["description"], + "first_event_id": None, # TODO missing in StreamLog + "last_event_id": None, # TODO missing in StreamLog }) return True, rows diff --git a/thrimshim/thrimshim/main.py b/thrimshim/thrimshim/main.py index 6129f9b..2099026 100644 --- a/thrimshim/thrimshim/main.py +++ b/thrimshim/thrimshim/main.py @@ -303,7 +303,7 @@ def update_row(ident, editor=None): playlists = database.query(conn, """ SELECT playlist_id, name, tags FROM playlists - WHERE show_in_description AND tags IS NOT NULL + WHERE show_in_description AND tags IS NOT NULL AND playlist_id IS NOT NULL """) # Filter for matching playlists for this video playlists = [