Exemplo n.º 1
0
def run_migrations_offline():
    """
    Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.
    """
    from libs.DatabaseConnection import DatabaseConnection

    url = DatabaseConnection(database=options.sql_database,
                             hostname=options.sql_host,
                             port=options.sql_port,
                             username=options.sql_user,
                             password=options.sql_password,
                             dialect=options.sql_dialect)
    context.configure(url=str(url),
                      target_metadata=TARGET_METADATA,
                      literal_binds=True)

    with context.begin_transaction():
        context.run_migrations()
Exemplo n.º 2
0
def update_db(update=True):
    db_connection = DatabaseConnection(database=options.sql_database,
                                   hostname=options.sql_host,
                                   port=options.sql_port,
                                   username=options.sql_user,
                                   password=options.sql_password,
                                   dialect=options.sql_dialect)
    alembic_cfg = Config('alembic/alembic.ini')
    alembic_cfg.attributes['configure_logger'] = False
    alembic_cfg.set_main_option('sqlalchemy.url', unquote_plus(str(db_connection)))
    if update:
        command.upgrade(alembic_cfg, "head")
    else:
        command.stamp(alembic_cfg, "head")
Exemplo n.º 3
0
def update_db(update=True):
    logging.info("Checking for Database Updates...")
    db_connection = DatabaseConnection(
        database=options.sql_database,
        hostname=options.sql_host,
        port=options.sql_port,
        username=options.sql_user,
        password=options.sql_password,
        dialect=options.sql_dialect,
    )
    alembic_cfg = Config("alembic/alembic.ini")
    alembic_cfg.attributes["configure_logger"] = False
    alembic_cfg.set_main_option("sqlalchemy.url", unquote(str(db_connection)))
    if update:
        command.upgrade(alembic_cfg, "head")
    else:
        command.stamp(alembic_cfg, "head")
Exemplo n.º 4
0
                              executemany):
        conn.info.setdefault("query_start_time", []).append(time.time())

    @event.listens_for(Engine, "after_cursor_execute")
    def after_cursor_execute(conn, cursor, statement, parameters, context,
                             executemany):
        total = time.time() - conn.info["query_start_time"].pop(-1)
        color = R if total > 0.01 else BLU
        logging.debug("Total query time: %s%s%f%s" % (bold, color, total, W))


db_connection = DatabaseConnection(
    database=options.sql_database,
    hostname=options.sql_host,
    port=options.sql_port,
    username=options.sql_user,
    password=options.sql_password,
    dialect=options.sql_dialect,
    ssl_ca=options.sql_sslca,
)

if options.auth == "azuread":
    azuread_app = ConfidentialClientApplication(
        options.client_id,
        authority="https://login.microsoftonline.com/" + options.tenant_id,
        client_credential=options.client_secret,
    )
else:
    azuread_app = None

### Setup the database session