database, sheetsync: Add worksheet name column 'sheet_name'

This tells us which sheet a row came from
(so we don't need to scan every sheet to find it if we're trying to do
lookups in that direction).

It is also needed in order to tag the videos with the Day number.
pull/102/head
Mike Lang 5 years ago
parent 1159a518f0
commit 48593e2b06

@ -125,6 +125,7 @@ Edit input values are initially NULL, but must not be NULL once the state is no
columns | type | role | description columns | type | role | description
-------------------------- | ---------------------------------- | :---------: | ----------- -------------------------- | ---------------------------------- | :---------: | -----------
`id` | `UUID PRIMARY KEY` | sheet input | Generated and attached to rows in the sheet to uniquely identify them even in the face of added, deleted or moved rows. `id` | `UUID PRIMARY KEY` | sheet input | Generated and attached to rows in the sheet to uniquely identify them even in the face of added, deleted or moved rows.
`sheet_name` | `TEXT NOT NULL` | sheet input | The name of the worksheet that the row is on. This is used to tag videos, and can be used to narrow down the range to look for an id in for more efficient lookup (though we never do that right now).
`event_start`, `event_end` | `TIMESTAMP` | sheet input | Start and end time of the event. Parsed from the sheet into timestamps or NULL. Used to set the editor time span, and displayed on the public sheet. The start time also determines what "day" the event lies on, for video tagging and other purposes. `event_start`, `event_end` | `TIMESTAMP` | sheet input | Start and end time of the event. Parsed from the sheet into timestamps or NULL. Used to set the editor time span, and displayed on the public sheet. The start time also determines what "day" the event lies on, for video tagging and other purposes.
`category` | `TEXT NOT NULL DEFAULT ''` | sheet input | The kind of event. By convention selected from a small list of categories, but stored as an arbitrary string because there's little to no benefit to using an enum here, it just makes our job harder when adding a new category. Used to tag videos, and for display on the public sheet. `category` | `TEXT NOT NULL DEFAULT ''` | sheet input | The kind of event. By convention selected from a small list of categories, but stored as an arbitrary string because there's little to no benefit to using an enum here, it just makes our job harder when adding a new category. Used to tag videos, and for display on the public sheet.
`description` | `TEXT NOT NULL DEFAULT ''` | sheet input | Event description. Provides the default title and description for editors, and displayed on the public sheet. `description` | `TEXT NOT NULL DEFAULT ''` | sheet input | Event description. Provides the default title and description for editors, and displayed on the public sheet.

@ -49,6 +49,7 @@ CREATE TYPE event_state as ENUM (
CREATE TABLE events ( CREATE TABLE events (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
sheet_name TEXT NOT NULL,
event_start TIMESTAMP, event_start TIMESTAMP,
event_end TIMESTAMP, event_end TIMESTAMP,
category TEXT NOT NULL DEFAULT '', category TEXT NOT NULL DEFAULT '',

@ -190,7 +190,7 @@ class SheetSync(object):
logging.info("Inserting new event {}".format(row['id'])) logging.info("Inserting new event {}".format(row['id']))
# Insertion conflict just means that another sheet sync beat us to the insert. # Insertion conflict just means that another sheet sync beat us to the insert.
# We can ignore it. # We can ignore it.
insert_cols = ['id'] + self.input_columns insert_cols = ['id', 'sheet_name'] + self.input_columns
built_query = sql.SQL(""" built_query = sql.SQL("""
INSERT INTO events ({}) INSERT INTO events ({})
VALUES ({}) VALUES ({})
@ -199,7 +199,7 @@ class SheetSync(object):
sql.SQL(", ").join(sql.Identifier(col) for col in insert_cols), sql.SQL(", ").join(sql.Identifier(col) for col in insert_cols),
sql.SQL(", ").join(sql.Placeholder(col) for col in insert_cols), sql.SQL(", ").join(sql.Placeholder(col) for col in insert_cols),
) )
query(self.conn, built_query, **row) query(self.conn, built_query, sheet_name=worksheet, **row)
return return
# Update database with any changed inputs # Update database with any changed inputs

Loading…
Cancel
Save