From 48593e2b0645ab4a7e933083a31fe31d283e868c Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Wed, 16 Oct 2019 17:13:32 +1100 Subject: [PATCH] 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. --- DATABASE.md | 1 + postgres/setup.sh | 1 + sheetsync/sheetsync/main.py | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DATABASE.md b/DATABASE.md index e689b83..01946c9 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -125,6 +125,7 @@ Edit input values are initially NULL, but must not be NULL once the state is no 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. +`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. `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. diff --git a/postgres/setup.sh b/postgres/setup.sh index 256783c..20d8141 100644 --- a/postgres/setup.sh +++ b/postgres/setup.sh @@ -49,6 +49,7 @@ CREATE TYPE event_state as ENUM ( CREATE TABLE events ( id UUID PRIMARY KEY, + sheet_name TEXT NOT NULL, event_start TIMESTAMP, event_end TIMESTAMP, category TEXT NOT NULL DEFAULT '', diff --git a/sheetsync/sheetsync/main.py b/sheetsync/sheetsync/main.py index 25231e2..5ffa076 100644 --- a/sheetsync/sheetsync/main.py +++ b/sheetsync/sheetsync/main.py @@ -190,7 +190,7 @@ class SheetSync(object): logging.info("Inserting new event {}".format(row['id'])) # Insertion conflict just means that another sheet sync beat us to the insert. # We can ignore it. - insert_cols = ['id'] + self.input_columns + insert_cols = ['id', 'sheet_name'] + self.input_columns built_query = sql.SQL(""" INSERT INTO events ({}) VALUES ({}) @@ -199,7 +199,7 @@ class SheetSync(object): sql.SQL(", ").join(sql.Identifier(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 # Update database with any changed inputs