Beispiel #1
0
def main():
    config_name = os.environ.get('APP_SETTINGS',
                                 'service.config.DevelopmentConfig')
    config = Config.create(config_name)

    app = create_app(config)

    init_basic_auth(app)

    init_db()

    app.run(use_reloader=False)
Beispiel #2
0
SQL_CREATE_USER = '''
    INSERT INTO users (
        name,
        password,
        is_admin
    )
    
    VALUES (%(name)s, %(password)s, %(is_admin)s);
'''


class InitDBError(Exception):
    pass


config = Config.create()


def _open_admin_connection() -> connection:
    # User and DB should be created by Postgres admin
    connection = connect_with(
        host=config.DB_HOST,
        port=config.DB_PORT,
        dbname=None,
        user=config.DB_ADMIN_USER,
        password=config.DB_ADMIN_PASSWORD,
    )

    # CREATE DB statement should be done outside of transaction block
    connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)