From ff5c1f8ecd9ce8036f8bf1b9b02a10f9215f182e Mon Sep 17 00:00:00 2001 From: Christopher Usher Date: Tue, 24 Sep 2019 14:43:28 +0100 Subject: [PATCH] fixes based on ekim's suggestions --- common/common/database.py | 17 +++++++++-------- postgres/setup.sh | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/common/common/database.py b/common/common/database.py index fbf5bfb..467da11 100644 --- a/common/common/database.py +++ b/common/common/database.py @@ -14,21 +14,22 @@ from psycogreen.gevent import patch_psycopg class DBManager(object): - """Patches psycopg2 before any connections are created, and applies the schema. - Stores connect info for easy creation of new connections, and sets some defaults before + """Patches psycopg2 before any connections are created. Stores connect info + for easy creation of new connections, and sets some defaults before returning them. - It has the ability to serve as a primitive connection pool, as getting a new conn will - return existing conns it knows about first, but this mainly just exists to re-use - the initial conn used to apply the schema, and you should use a real conn pool for - any non-trivial use. + It has the ability to serve as a primitive connection pool, as getting a + new conn will return existing conns it knows about first, but this mainly + just exists to re-use the initial conn used to test the connection, and you + should use a real conn pool for any non-trivial use. - Returned conns are set to seralizable isolation level, autocommit, and use NamedTupleCursor cursors. - """ + Returned conns are set to seralizable isolation level, autocommit, and use + NamedTupleCursor cursors.""" def __init__(self, **connect_kwargs): patch_psycopg() self.conns = [] self.connect_kwargs = connect_kwargs + # get a connection to test whether connection is working. conn = self.get_conn() self.put_conn(conn) diff --git a/postgres/setup.sh b/postgres/setup.sh index ab88c66..256783c 100644 --- a/postgres/setup.sh +++ b/postgres/setup.sh @@ -36,19 +36,16 @@ fi echo "Applying schema for $POSTGRES_DB" psql -v ON_ERROR_STOP=1 -U $WUBLOADER_USER -d $POSTGRES_DB <<-EOSQL --- Create type if it doesn't already exist -DO \$\$ BEGIN - CREATE TYPE event_state as ENUM ( - 'UNEDITED', - 'EDITED', - 'CLAIMED', - 'FINALIZING', - 'TRANSCODING', - 'DONE' - ); -EXCEPTION WHEN duplicate_object THEN - NULL; -END \$\$; + +CREATE TYPE event_state as ENUM ( + 'UNEDITED', + 'EDITED', + 'CLAIMED', + 'FINALIZING', + 'TRANSCODING', + 'DONE' +); + CREATE TABLE events ( id UUID PRIMARY KEY,