Example #1
0
File: env.py Project: nlisgo/h
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    section = config.config_ini_section

    config.set_section_option(section, 'sqlalchemy.url', get_database_url())

    engine = engine_from_config(
        config.get_section(section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        transaction_per_migration=True,
    )

    try:
        context.run_migrations()
    finally:
        connection.close()
Example #2
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.

    """
    # for the --sql use case, run migrations for each URL into
    # individual files.

    engines = {'': {'url': context.config.get_main_option('sqlalchemy.url')}}
    for name in bind_names:
        engines[name] = rec = {}
        rec['url'] = context.config.get_section_option(name,
                                                       "sqlalchemy.url")

    for name, rec in engines.items():
        logger.info("Migrating database %s" % (name or '<default>'))
        file_ = "%s.sql" % name
        logger.info("Writing output to %s" % file_)
        with open(file_, 'w') as buffer:
            context.configure(url=rec['url'], output_buffer=buffer,
                              target_metadata=get_metadata(name),
                              literal_binds=True)
            with context.begin_transaction():
                context.run_migrations(engine_name=name)
Example #3
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    # we can get the table prefix via the tag object
    tag = context.get_tag_argument()
    if tag and isinstance(tag, dict):
        table_prefix = tag.get('table_prefix', '')
    else:
        table_prefix = ''

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            version_table=table_prefix + 'alembic_version'
        )

        with context.begin_transaction():
            context.run_migrations(table_prefix=table_prefix)
Example #4
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    # the connection may come from the config object
    if hasattr(config, 'connection'):
        # load connection from config object
        connection = config.connection
    else:
        # load connection from config file
        engine = engine_from_config(
            config.get_section(config.config_ini_section),
            prefix='sqlalchemy.',
            poolclass=pool.NullPool
        )
        connection = engine.connect()

    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        # don't close connection if it is from outside
        if not hasattr(config, 'connection'):
            connection.close()
Example #5
0
File: env.py Project: yehiaa/clinic
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    # this callback is used to prevent an auto-migration from being generated
    # when there are no changes to the schema
    # reference: http://alembic.readthedocs.org/en/latest/cookbook.html
    def process_revision_directives(context, revision, directives):
        if getattr(config.cmd_opts, 'autogenerate', False):
            script = directives[0]
            if script.upgrade_ops.is_empty():
                directives[:] = []
                logger.info('No changes in schema detected.')

    engine = engine_from_config(config.get_section(config.config_ini_section),
                                prefix='sqlalchemy.',
                                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      process_revision_directives=process_revision_directives,
                      **current_app.extensions['migrate'].configure_args)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #6
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    if isinstance(engine, Engine):
        connection = engine.connect()
    else:
        raise Exception(
            'Expected engine instance got %s instead' % type(engine)
        )

    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #7
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    cfg = config.get_section(config.config_ini_section)
    if 'use_flask_db_url' in cfg and cfg['use_flask_db_url'] == 'true':
        cfg['sqlalchemy.url'] = get_app_config('SQLALCHEMY_DATABASE_URI')

    engine = engine_from_config(
        cfg,
        prefix='sqlalchemy.',
        poolclass=pool.NullPool
    )

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #8
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.
    
    """
    from uliweb.manage import make_simple_application
    from uliweb import orm, settings

#    engine = engine_from_config(
#                config.get_section(config.config_ini_section), 
#                prefix='sqlalchemy.', 
#                poolclass=pool.NullPool)

    name = config.get_main_option("engine_name")
    make_simple_application(project_dir='.')
    target_metadata = orm.get_metadata(name)
    connection = orm.get_connection(engine_name=name).connect()
#    connection = engine.connect()
    
    context.configure(
                connection=connection, 
                target_metadata=target_metadata,
                compare_server_default=True,
                include_object=uliweb_include_object,
#                compare_server_default=uliweb_compare_server_default,
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #9
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    options = config.get_section(config.config_ini_section)
    options['sqlalchemy.url'] = db_url
    engine = engine_from_config(options,
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    # url="sqlalchemy.url" + "postgresql://" + environ['DB_1_PORT'][7:]

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #10
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    core_configs = config.get_section(config.config_ini_section)
    core_configs['sqlalchemy.url'] = settings.SQLALCHEMY_DATABASE_URI
    engine = engine_from_config(
                core_configs,
                prefix='sqlalchemy.',
                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #11
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    # Override sqlalchemy.url value to application's value
    alembic_config = config.get_section(config.config_ini_section)
    alembic_config['sqlalchemy.url'] = app.config['SQLALCHEMY_DATABASE_URI']
    
    engine = engine_from_config(
        alembic_config,
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=db.metadata,
        compare_type=True
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #12
0
File: env.py Project: rshorey/moxie
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    dbcfg = config.get_section(config.config_ini_section)

    if 'DATABASE_URL' in os.environ:
        dbcfg['sqlalchemy.url'] = os.environ['DATABASE_URL']

    engine = engine_from_config(
                dbcfg,
                prefix='sqlalchemy.',
                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #13
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    if 'DB_URL' in os.environ:
        engine = engine_from_config(
            config.get_section("app:pyramidapp"),
            prefix='sqlalchemy.',
            url=os.environ['DB_URL'],
            poolclass=pool.NullPool)
    else:
        engine = engine_from_config(
            config.get_section("app:pyramidapp"),
            prefix='sqlalchemy.',
            poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #14
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    alembic_config = config.get_section(config.config_ini_section)
    alembic_config['sqlalchemy.url'] = seplis_config['api']['database']
    engine = engine_from_config(
        alembic_config,
        prefix='sqlalchemy.',
        poolclass=pool.NullPool
    )

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )
    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #15
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    alembic_config = config.get_section(config.config_ini_section)

    # if there is a .env at the root, add them to the system variables.

    abs_file_path = os.path.abspath('../../../.env')
    load_environment_variables(abs_file_path)

    alembic_config['sqlalchemy.url'] = os.environ["DATABASE_URL"]


    connectable = engine_from_config(
        alembic_config,
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()
Example #16
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    if config.get_main_option('bdr').strip().lower() == 'true':
        def enable_bdr(connection, connection_record):
            with connection.cursor() as cursor:
                cursor.execute('SET LOCAL bdr.permit_ddl_locking = true')
        event.listen(engine, 'connect', enable_bdr)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
def run_migrations_online():
    """Run migrations in 'online' mode.
    """
    engine = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.'
    )

    connection = engine.connect()

    if isinstance(engine, Engine):
        connection = engine.connect()
    else:
        raise Exception(
            'Expected engine instance got %s instead' % type(engine)
        )

    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #18
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.
    
    """
    engine = engine_from_config(
                config.get_section(config.config_ini_section), 
                prefix='sqlalchemy.', 
                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
                connection=connection, 
                target_metadata=target_metadata,
                render_as_batch=True,
                version_table='alembic_ziggurat_foundations_version',
                transaction_per_migration=True
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #19
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    target_metadata.reflect(engine)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        include_object=include_object,
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
        try:
            impl = context.get_impl().context_opts['template_args']
            downgrades = impl['downgrades']
            upgrades = impl['upgrades']
            if 'pass' in downgrades and 'pass' in upgrades:
                raise Exception("Empty migration")
        except KeyError:
            pass
    finally:
        connection.close()
Example #20
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    #if getenv('PRODUCTION_FLAG', None) is not None:
    #    from app.config.production_config import SQLALCHEMY_DATABASE_URI
    #    alembic_config['sqlalchemy.url'] = SQLALCHEMY_DATABASE_URI
    #elif getenv('TESTING_FLAG', None) is not None:
    #    from app.config.testing_config import SQLALCHEMY_DATABASE_URI
    #    alembic_config['sqlalchemy.url'] = SQLALCHEMY_DATABASE_URI
    #else:
    #    from app.config.development_config import SQLALCHEMY_DATABASE_URI
    #    alembic_config['sqlalchemy.url'] = SQLALCHEMY_DATABASE_URI

    engine = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #21
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.

    """
    kwargs = dict()
    if subunit2sql_config.database.connection:
        kwargs['url'] = subunit2sql_config.database.connection
    elif subunit2sql_config.database.engine:
        kwargs['dialect_name'] = subunit2sql_config.database.engine
    else:
        kwargs['url'] = config.get_main_option("sqlalchemy.url")
    kwargs['target_metadata'] = target_metadata
    kwargs['render_as_batch'] = True
    context.configure(**kwargs)

    with context.begin_transaction():
        context.run_migrations()
Example #22
0
def runMigrationsOnline():
  """Run migrations in 'online' mode.

  See Alembic documentation for more details on these functions.

  In this scenario we need to create an Engine
  and associate a connection with the context.
  """
  CONFIG.set_main_option("sqlalchemy.url", repository.getDbDSN())

  engine = engine_from_config(
      CONFIG.get_section(CONFIG.config_ini_section),
      prefix="sqlalchemy.",
      poolclass=pool.NullPool)

  connection = engine.connect()
  context.configure(
    connection=connection,
    target_metadata=TARGET_METADATA
  )

  try:
    with context.begin_transaction():
      context.run_migrations()
  finally:
    connection.close()
Example #23
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    alembic_config = config.get_section(config.config_ini_section)

    engine = engine_from_config(
        alembic_config,
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    connection = None
    start_time = datetime.now()
    while connection is None:
        try:
            connection = engine.connect()
        except Exception:
            if datetime.now() > start_time + timedelta(seconds=60):
                print("Timed out connecting to database")
                raise
            time.sleep(1)

    context.configure(
        connection=connection,
        target_metadata=target_metadata)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #24
0
File: env.py Project: deti/boss
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.

    """
    # for the --sql use case, run migrations for each URL into
    # individual files.

    engines = {}
    for name in db_uri:
        engines[name] = rec = {}
        rec['url'] = db_uri[name]

    for name, rec in engines.items():
        logger.info("Migrating database %s" % name)
        file_ = "%s.sql" % name
        logger.info("Writing output to %s" % file_)
        with open(file_, 'w') as buffer:
            context.configure(url=rec['url'], output_buffer=buffer,
                              target_metadata=target_metadata.get(name),
                              compare_type=compare_type)
            with context.begin_transaction():
                context.run_migrations(engine_name=name)
Example #25
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    conf = config.get_section(config.config_ini_section)
    conf.update(url_dict)
    engine = engine_from_config(
                conf,
                prefix='sqlalchemy.',
                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #26
0
def run_migrations_online():
    if DBSession.bind is None:
        raise ValueError(
            "\nYou must run Kotti's migration using the 'kotti-migrate' script"
            "\nand not through 'alembic' directly."
            )

    transaction.begin()
    connection = DBSession.connection()

    context.configure(
        connection=connection,
        target_metadata=metadata,
        )

    try:
        context.run_migrations()
        mark_changed(DBSession())
    except:
        traceback.print_exc()
        transaction.abort()
    else:
        transaction.commit()
    finally:
        # connection.close()
        pass
Example #27
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    Runs for both wikimetrics and wikimetrics_testing
    database.

    """
    config = db.config
    engine = get_engine(config)
    migrations = [(engine, target_metadata)]

    if db.config['DEBUG'] is True:
        test_config = setup_testing_config(deepcopy(config))
        test_engine = get_engine(test_config)
        test_metadata = db.WikimetricsBase.metadata
        migrations.append((test_engine, test_metadata))

    for eng, meta_data in migrations:
        connection = eng.connect()
        context.configure(connection=connection, target_metadata=meta_data)

        print("Running migration for " + eng.url.database)
        try:
            with context.begin_transaction():
                context.run_migrations()
        finally:
            connection.close()
Example #28
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    Runs for wikimetrics, wikimetrics_testing
    and centralauth_testing databases.

    """
    config = db.config
    engine = get_engine(config)
    migrations = [(engine, target_metadata)]

    if db.config['DEBUG'] is True:
        test_config = setup_testing_config(deepcopy(config))
        # add wikimetrics_testing migrations
        test_engine = get_engine(test_config)
        test_metadata = db.WikimetricsBase.metadata
        migrations.append((test_engine, test_metadata))
        # NOTE: centralauth and mediawiki schemas should be maintained
        # manually and not managed with alembic, as they are not schemas
        # we own

    for eng, meta_data in migrations:
        connection = eng.connect()
        context.configure(connection=connection, target_metadata=meta_data)

        print("Running migration for " + eng.url.database)
        try:
            with context.begin_transaction():
                context.run_migrations()
        finally:
            connection.close()
Example #29
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        version_table_schema=config.get_main_option('version_table_schema'),
        version_table=config.get_main_option('version_table'),
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #30
0
File: env.py Project: pudo/aleph
def run_migrations_offline():
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url,
                      include_object=ignore_autogen)

    with context.begin_transaction():
        context.run_migrations()
Example #31
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            compare_server_default=True,
            compare_type=True,
        )

        with context.begin_transaction():
            context.run_migrations()
Example #32
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = engine_from_config(
                config.get_section(config.config_ini_section),
                prefix='sqlalchemy.',
                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #33
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.

    """

    url = config.get_main_option("sqlalchemy.url")
    context.configure(
        url=url,
        target_metadata=target_metadata,
        literal_binds=True,
        dialect_opts={"paramstyle": "named"},
    )

    with context.begin_transaction():
        context.run_migrations()
Example #34
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.

    """
    url = config.get_main_option('sqlalchemy.url')
    context.configure(url=url,
                      target_metadata=target_metadata,
                      include_schemas=True,
                      include_symbol=_include_symbol,
                      render_item=_render_item,
                      version_table=version_table,
                      version_table_schema='public')

    with context.begin_transaction():
        context.run_migrations()
Example #35
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    from clscraper.models import url
    _config = config.get_section(config.config_ini_section)
    _config["sqlalchemy.url"] = url
    connectable = engine_from_config(
        _config,
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(
            connection=connection, target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()
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.

    """
    url = get_url()
    context.configure(url=url,
                      target_metadata=target_metadata,
                      literal_binds=True,
                      compare_type=True)

    with context.begin_transaction():
        context.run_migrations()

    with context.begin_transaction():
        context.run_migrations()
Example #37
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    if os.environ.get('DATABASE_URL') is None:
        connectable = engine_from_config(
            config.get_section(config.config_ini_section),
            prefix='sqlalchemy.',
            poolclass=pool.NullPool)
    else:
        connectable = create_engine(os.environ.get('DATABASE_URL'))

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()
Example #38
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    settings = get_settings()

    configuration = config.get_section(config.config_ini_section)
    configuration["sqlalchemy.url"] = settings.DATABASE_URL
    connectable = engine_from_config(
        configuration,
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
Example #39
0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with either a URL
    or an Engine.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    set_mysql_engine()

    kwargs = dict()
    if neutron_config.database.connection:
        kwargs['url'] = neutron_config.database.connection
    else:
        kwargs['dialect_name'] = neutron_config.database.engine
    kwargs['include_object'] = include_object
    kwargs['version_table'] = alembic_migrations.VERSION_TABLE
    context.configure(**kwargs)

    with context.begin_transaction():
        context.run_migrations()
Example #40
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.

    """
    url = os.getenv("DATABASE_URI")
    if url is None:
        print('Environment variable DATABASE_URI is not set. Exiting...')
        sys.exit(1)
    context.configure(url=url,
                      target_metadata=target_metadata,
                      literal_binds=True,
                      compare_type=True)

    with context.begin_transaction():
        context.run_migrations()
Example #41
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(connection=connection, target_metadata=target_metadata)

        with context.begin_transaction():

            context.run_migrations()

        if context.get_x_argument(as_dictionary=True).get("apply_hasura_metadata"):
            apply_hasura_metadata(context)
Example #42
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool
    )

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            # see: https://stackoverflow.com/a/32510603/1027706
            render_as_batch=True,
        )

        with context.begin_transaction():
            context.run_migrations()
Example #43
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = create_engine(
        qinling_config.database.connection,
        poolclass=pool.NullPool
    )

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #44
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    # Enable reusing an existing connection.
    # http://alembic.readthedocs.org/en/latest/cookbook.html#sharing-a-connection-with-a-series-of-migration-commands-and-environments
    connectable = config.attributes.get('connection', None)

    if connectable is None:
        alembic_config = config.get_section(config.config_ini_section)
        alembic_config['sqlalchemy.url'] = settings.DATABASE_URI
        connectable = engine_from_config(alembic_config,
                                         prefix='sqlalchemy.',
                                         poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)
        with context.begin_transaction():
            context.run_migrations()
Example #45
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    connectable = create_engine(get_url())
    # Default/generated code:
    #  connectable = engine_from_config(
    #     config.get_section(config.config_ini_section),
    #     prefix='sqlalchemy.',
    #     poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()
Example #46
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    #import pdb; pdb.set_trace()
    alembic_config = config.get_section(config.config_ini_section)
    alembic_config['sqlalchemy.url'] = CONNECTION_STR

    connectable = engine_from_config(
        alembic_config,
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
Example #47
0
File: env.py Project: BBN-Q/bbndb
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    # connectable = engine_from_config(
    #     config.get_section(config.config_ini_section),
    #     prefix="sqlalchemy.",
    #     poolclass=pool.NullPool,
    # )

    connectable = create_engine(get_url())
    # with connectable.connect() as connection:

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata,
                          render_as_batch=True)

        with context.begin_transaction():
            context.run_migrations()
Example #48
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    facade = db_api._create_facade_lazily()
    engine = facade.get_engine()
    connection = engine.connect()
    facade.get_sessionmaker().configure(bind=connection)

    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      render_as_batch=True)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
        facade.get_sessionmaker().configure(bind=engine)
Example #49
0
def run_migrations_online(engine, target_metadata, version_table,
                          include_object):
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    connectable = engine

    with connectable.connect() as connection:

        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            version_table=version_table,
            include_object=include_object,
            compare_type=True,  # http://stackoverflow.com/a/17176843/315168
        )

        with context.begin_transaction():
            context.run_migrations()
Example #50
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    postgresConn = os.environ.get("POSTGRES_CONN", "")
    engine = create_engine(postgresConn)
    #engine = engine_from_config(
    #    config.get_section(config.config_ini_section),
    #    prefix='sqlalchemy.',
    #    poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection, target_metadata=target_metadata)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #51
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    # overriding the sqlalchemy.url based on env settings
    from src import settings
    config.set_main_option('sqlalchemy.url', settings.SQLALCHEMY_DATABASE_URI)

    connectable = engine_from_config(config.get_section(
        config.config_ini_section),
                                     prefix='sqlalchemy.',
                                     poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
Example #52
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    ini_section = config.get_section(config.config_ini_section)
    db_url = context.get_x_argument(as_dictionary=True).get('db_url')
    if db_url:
        ini_section['sqlalchemy.url'] = db_url

    connectable = engine_from_config(ini_section, poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata,
                          sqlalchemy_module_prefix="sq.",
                          compare_server_default=True)

        with context.begin_transaction():
            context.run_migrations()
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    connectable = config.get_main_option('connectable')
    if not connectable:
        connectable = engine_from_config(
            config.get_section(config.config_ini_section),
            prefix='sqlalchemy.',
            poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()
Example #54
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connectable = engine_from_config(
        # Replaced this with a static dict since we are loading from a settings object
        {
            'sqlalchemy.url': settings.db_url
        },
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(
            connection=connection, target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()
Example #55
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.

    """
    alembic_config = config.get_section(config.config_ini_section)
    alembic_config['sqlalchemy.url'] = DatabaseConfig.get_uri()

    engine = engine_from_config(alembic_config)

    with engine.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
Example #56
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    cfg = config.get_section(config.config_ini_section)
    if 'use_flask_db_url' in cfg and cfg['use_flask_db_url'] == 'true':
        cfg['sqlalchemy.url'] = get_app_config('SQLALCHEMY_URL')

    engine = engine_from_config(cfg,
                                prefix='sqlalchemy.',
                                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection, target_metadata=target_metadata)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Example #57
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            render_as_batch=config.get_main_option(
                'sqlalchemy.url').startswith('sqlite:///'),
        )

        with context.begin_transaction():
            context.run_migrations()
Example #58
0
def run_migrations_online():
    def process_revision_directives(context, revision, directives):
        if getattr(config.cmd_opts, 'autogenerate', False):
            script = directives[0]
            if script.upgrade_ops.is_empty():
                directives[:] = []
                logger.info('No changes in schema detected.')

    engine = engine_from_config(config.get_section(config.config_ini_section),
                                prefix='sqlalchemy.',
                                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      process_revision_directives=process_revision_directives,
                      **current_app.extensions['migrate'].configure_args)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    url = get_url()
    parsed = urlparse(url)
    query = parse_qs(parsed.query)
    con_args = {}
    if 'sslmode' in query:
        con_args['sslmode'] = query['sslmode'][0]

    connectable = create_engine(url, connect_args=con_args)

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
Example #60
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    if config.config_file_name:
        engine = engine_from_config(settings, prefix='sqlalchemy.')
    else:
        engine = create_engine(config.get_main_option('sqlalchemy.url'))

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      render_as_batch=True,
                      compare_type=True)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()