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