Fix search path for schema in db (#188)

This commit is contained in:
Jonathan Zernik 2020-07-31 20:21:29 -07:00 committed by GitHub
parent e5f51002cc
commit d9783d8c9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,7 +51,10 @@ class PostgresDb:
create_schema_sql = sql.SQL("CREATE SCHEMA IF NOT EXISTS {};").format(
sql.Identifier(schema_name)
)
use_schema_sql = sql.SQL("ALTER ROLE {} SET search_path TO {};").format(
use_schema_sql = sql.SQL("SET search_path TO {};").format(
sql.Identifier(schema_name),
)
use_schema_for_user_sql = sql.SQL("ALTER ROLE {} SET search_path TO {};").format(
sql.Identifier(self.user),
sql.Identifier(schema_name),
)
@ -60,6 +63,7 @@ class PostgresDb:
logger.info("Creating schema: {}".format(schema_name))
curs.execute(create_schema_sql)
curs.execute(use_schema_sql)
curs.execute(use_schema_for_user_sql)
def init(self):
""" Create the tables and indices in the database. """