linted plenario/database.py
@@ -12,6 +12,7 @@ from plenario.settings import DATABASE_CONN, REDSHIFT_CONN
logger = getLogger(__name__)
+
postgres_engine = create_engine(DATABASE_CONN)
postgres_session = scoped_session(sessionmaker(bind=postgres_engine))
postgres_base = declarative_base(bind=postgres_engine)
@@ -24,38 +25,38 @@ redshift_base.query = redshift_session.query_property()
def create_database(bind: Engine, database: str) -> None:
- """Setup a database (schema) in postgresql."""
-
- print('[plenario] Create database %s' % database)
+ """Setup a database (schema) in postgresql.
+ """
+ logger.info('[plenario] Create database %s' % database)
connection = bind.connect()
- connection.execute("commit")
- connection.execute("create database %s" % database)
+ connection.execute('commit')
+ connection.execute('create database %s' % database)
connection.close()
def drop_database(bind: Engine, database: str) -> None:
- """Drop a database (schema) in postgresql."""
-
- print('[plenario] Drop database %s' % database)
+ """Drop a database (schema) in postgresql.
+ """
+ logger.info('[plenario] Drop database %s' % database)
connection = bind.connect()
- connection.execute("commit")
- connection.execute("drop database %s" % database)
+ connection.execute('commit')
+ connection.execute('drop database %s' % database)
connection.close()
def create_extension(bind: Engine, extension: str) -> None:
- """Setup an extension in postgresql."""
-
- print('[plenario] Create extension %s' % extension)
+ """Setup an extension in postgresql.
+ """
+ logger.info('[plenario] Create extension %s' % extension)
connection = bind.connect()
- connection.execute("create extension %s" % extension)
+ connection.execute('create extension %s' % extension)
connection.close()
def psql(path: str) -> None:
- """Use psql to run a file at some path."""
-
- print('[plenario] Psql file %s' % path)
+ """Use psql to run a file at some path.
+ """
+ logger.info('[plenario] Psql file %s' % path)
command = 'psql {} -f {}'.format(DATABASE_CONN, path)
subprocess.check_call(command, shell=True)
@@ -64,8 +65,8 @@ def psql(path: str) -> None:
def postgres_session_context():
"""A helper method for keeping the state of an connection with the database
separate from the work being done, and ensuring that the session is always
- cleaned up after use."""
-
+ cleaned up after use.
+ """
logger.info('Begin.')
transactional_session = postgres_session()
try:
@@ -84,8 +85,8 @@ def postgres_session_context():
def redshift_session_context():
"""A helper method for keeping the state of an connection with the database
separate from the work being done, and ensuring that the session is always
- cleaned up after use."""
-
+ cleaned up after use.
+ """
logger.info('Begin.')
transactional_session = redshift_session()
try:
