Пример #1
0
def create_and_migrate_db(db_engine, db_connection_string):
    """
    Configures alembic and runs any none applied migrations found in the
    `scripts_location` folder.
    :param db_engine: engine handle for the database to apply the migrations to
    :return: None
    """
    # TODO Do not hard code
    alembic_cfg = AlembicConfig('config/alembic.ini')
    alembic_cfg.set_main_option("script_location", "alembic/")

    with db_engine.begin() as connection:
        alembic_cfg.attributes["connection"] = connection
        upgrade_db(alembic_cfg, "head")
Пример #2
0
def create_and_migrate_db(db_engine, alembic_path, db_connection_string):
    """
    Configures alembic and runs any none applied migrations found in the
    `scripts_location` folder.
    :param db_engine: engine handle for the database to apply the migrations to
    :param alembic_path: path to root directory for alembic migrations
    :return: None
    """
    alembic_cfg = AlembicConfig()
    alembic_cfg.set_main_option("sqlalchemy.url", db_connection_string)
    alembic_cfg.set_main_option("script_location", os.path.join(alembic_path))

    with db_engine.begin() as connection:
        alembic_cfg.attributes["connection"] = connection
        upgrade_db(alembic_cfg, "head")
Пример #3
0
def do_migratedb(config: Config, args: argparse.Namespace) -> None:
    if not config.queues:
        log.error('Could not migrate the database: no event queue configured')
        raise NoEventQueueExit()

    alembic_config = get_alembic_config(config)

    if not alembic_config.get_main_option('version_locations'):
        log.info("Configured queue handlers don't have migrations")
        return None

    db = Db(config.postgresql)

    with db as dbsession:
        alembic_config.attributes['connection'] = dbsession.connection()
        upgrade_db(alembic_config, 'heads')

    log.info('Successfully migrated the database')