Change database primary key from UUID to TEXT

We still store uuids, but in text form.
This allows us to store non-UUID ids for systems that have other ids.
pull/401/head
Mike Lang 1 year ago committed by Mike Lang
parent 72f7c59a77
commit be111ccb2a

@ -165,7 +165,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.
`id` | `TEXT 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.

@ -690,7 +690,7 @@ class TranscodeChecker(object):
result = query(self.conn, """
UPDATE events
SET state = 'DONE', upload_time = %s
WHERE id = ANY (%s::uuid[]) AND state = 'TRANSCODING'
WHERE id = ANY (%s) AND state = 'TRANSCODING'
""", datetime.datetime.utcnow(), list(ids.keys()))
return result.rowcount

@ -65,7 +65,7 @@ CREATE TYPE thumbnail_mode as ENUM (
);
CREATE TABLE events (
id UUID PRIMARY KEY,
id TEXT PRIMARY KEY,
sheet_name TEXT NOT NULL,
event_start TIMESTAMP,

@ -10,7 +10,7 @@ import gevent.event
import prometheus_client as prom
from monotonic import monotonic
from psycopg2 import sql
from psycopg2.extras import register_uuid, execute_values
from psycopg2.extras import execute_values
from requests import HTTPError
import common
@ -352,8 +352,6 @@ def main(dbconnect, sheets_creds_file, edit_url, bustime_start, sheet_id, worksh
common.install_stacksampler()
prom.start_http_server(metrics_port)
register_uuid()
if backdoor_port:
gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()

@ -120,7 +120,7 @@ class SheetsMiddleware():
'poster_moment': lambda v: v == '[\u2713]', # check mark
'image_links': lambda v: [link.strip() for link in v.split()] if v.strip() else [],
'tags': lambda v: [tag.strip() for tag in v.split(',') if tag.strip()],
'id': lambda v: uuid.UUID(v) if v.strip() else None,
'id': lambda v: v if v.strip() else None,
}
# tracks when to do inactive checks
self.sync_count = 0
@ -175,7 +175,7 @@ class SheetsMiddleware():
logging.warning(f"Row {worksheet!r}:{row['index']} has no valid id, skipping")
continue
# Otherwise, allocate id for a new row.
row['id'] = uuid.uuid4()
row['id'] = str(uuid.uuid4())
logging.info(f"Allocating id for row {worksheet!r}:{row['index']} = {row['id']}")
self.sheets.write_value(
self.sheet_id, worksheet,

@ -22,7 +22,6 @@ from common.flask_stats import request_stats, after_request
import google.oauth2.id_token
import google.auth.transport.requests
psycopg2.extras.register_uuid()
app = flask.Flask('thrimshim')
app.after_request(after_request)
@ -145,7 +144,7 @@ def get_defaults():
})
@app.route('/thrimshim/<uuid:ident>', methods=['GET'])
@app.route('/thrimshim/<ident>', methods=['GET'])
@request_stats
def get_row(ident):
"""Gets the row from the database with id == ident."""
@ -242,7 +241,7 @@ def get_row(ident):
return json.dumps(response, default=convert)
@app.route('/thrimshim/<uuid:ident>', methods=['POST'])
@app.route('/thrimshim/<ident>', methods=['POST'])
@request_stats
@authenticate
def update_row(ident, editor=None):
@ -450,7 +449,7 @@ def update_row(ident, editor=None):
return ''
@app.route('/thrimshim/manual-link/<uuid:ident>', methods=['POST'])
@app.route('/thrimshim/manual-link/<ident>', methods=['POST'])
@request_stats
@authenticate
def manual_link(ident, editor=None):
@ -493,7 +492,7 @@ def manual_link(ident, editor=None):
return ''
@app.route('/thrimshim/reset/<uuid:ident>', methods=['POST'])
@app.route('/thrimshim/reset/<ident>', methods=['POST'])
@request_stats
@authenticate
def reset_row(ident, editor=None):

Loading…
Cancel
Save