Restructure playlists table

to have all tags, not just playlists.
Notably, this means playlist ids may be null.
pull/401/head
Mike Lang 3 months ago committed by Mike Lang
parent 145ddfc7ff
commit a3aaa37bb0

@ -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)

@ -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).

@ -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",
}

@ -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"] == "<all>" 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

@ -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 = [

Loading…
Cancel
Save