fixes based on ekim's suggestions

pull/77/head
Christopher Usher 5 years ago
parent f75f3e61e8
commit ff5c1f8ecd

@ -14,21 +14,22 @@ from psycogreen.gevent import patch_psycopg
class DBManager(object): class DBManager(object):
"""Patches psycopg2 before any connections are created, and applies the schema. """Patches psycopg2 before any connections are created. Stores connect info
Stores connect info for easy creation of new connections, and sets some defaults before for easy creation of new connections, and sets some defaults before
returning them. returning them.
It has the ability to serve as a primitive connection pool, as getting a new conn will It has the ability to serve as a primitive connection pool, as getting a
return existing conns it knows about first, but this mainly just exists to re-use new conn will return existing conns it knows about first, but this mainly
the initial conn used to apply the schema, and you should use a real conn pool for just exists to re-use the initial conn used to test the connection, and you
any non-trivial use. 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): def __init__(self, **connect_kwargs):
patch_psycopg() patch_psycopg()
self.conns = [] self.conns = []
self.connect_kwargs = connect_kwargs self.connect_kwargs = connect_kwargs
# get a connection to test whether connection is working.
conn = self.get_conn() conn = self.get_conn()
self.put_conn(conn) self.put_conn(conn)

@ -36,19 +36,16 @@ fi
echo "Applying schema for $POSTGRES_DB" echo "Applying schema for $POSTGRES_DB"
psql -v ON_ERROR_STOP=1 -U $WUBLOADER_USER -d $POSTGRES_DB <<-EOSQL 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 (
CREATE TYPE event_state as ENUM ( 'UNEDITED',
'UNEDITED', 'EDITED',
'EDITED', 'CLAIMED',
'CLAIMED', 'FINALIZING',
'FINALIZING', 'TRANSCODING',
'TRANSCODING', 'DONE'
'DONE' );
);
EXCEPTION WHEN duplicate_object THEN
NULL;
END \$\$;
CREATE TABLE events ( CREATE TABLE events (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,

Loading…
Cancel
Save