How to use the alembic.context.begin_transaction function in alembic

To help you get started, we’ve selected a few alembic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github att-comdev / shipyard / src / bin / shipyard_airflow / alembic / env.py View on Github external
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()
    # Default code: url = config.get_main_option("sqlalchemy.url")
    context.configure(
        url=url, target_metadata=target_metadata, literal_binds=True)

    with context.begin_transaction():
        context.run_migrations()
github paasmaker / paasmaker / migrations / env.py View on Github external
# TODO: Allow loading a configuration file from a different location.
    paasmaker_configuration = paasmaker.common.configuration.Configuration()
    paasmaker_configuration.load_from_file(['paasmaker.yml', '/etc/paasmaker/paasmaker.yml'])
    paasmaker_configuration.setup_database()

    engine = create_engine(paasmaker_configuration.get_flat('pacemaker.dsn'))

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

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
github assembl / assembl / assembl / alembic / versions / 2df3bdfbc594_facebook_update_fields.py View on Github external
def upgrade(pyramid_env):
    with context.begin_transaction():
        op.add_column('abstract_agent_account',
            sa.Column('full_name', sa.Unicode))

    # Do stuff with the app's models here.
    from assembl import models as m
    db = m.get_session_maker()()
    with transaction.manager:
        pass
github elemental-lf / benji / src / backy2 / sql_migrations / alembic / env.py View on Github external
if connectable is None:
            # only create Engine if we don't have a Connection
            # from the outside
        connectable = create_engine(engine_url)
        # 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()
github assembl / assembl / assembl / alembic / versions / 1af8bd2cb75e_profile_in_abstract_.py View on Github external
def upgrade(pyramid_env):
    with context.begin_transaction():
        op.add_column('abstract_agent_account',
            sa.Column(
                'profile_id',
                sa.Integer,
                sa.ForeignKey('agent_profile.id', ondelete='CASCADE')))
        op.execute(
            '''UPDATE abstract_agent_account SET profile_id=(
                SELECT profile_id FROM agent_email_account 
                    WHERE agent_email_account.id = abstract_agent_account.id)
                WHERE "type" = 'agent_email_account' ''')
        op.execute('''UPDATE abstract_agent_account 
                SET type = 'idprovider_agent_account'
                WHERE type = 'idprovider_account' ''')
        op.execute(
            '''UPDATE abstract_agent_account SET profile_id=(
                SELECT profile_id FROM idprovider_agent_account 
github iawia002 / Diana / alembic / env.py View on Github external
"""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)

    with context.begin_transaction():
        context.run_migrations()
github assembl / assembl / assembl / alembic / versions / 42a76adf343c_store_truly_raw_mess.py View on Github external
def downgrade(pyramid_env):
    with context.begin_transaction():
        ### commands auto generated by Alembic - please adjust! ###
        pass
        ### end Alembic commands ###
github NMGRL / pychron / alembic_dvc / env.py View on Github external
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()
github planbrothers / ml-annotate / annotator / migrations / env.py View on Github external
In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    url = app.config['SQLALCHEMY_DATABASE_URI']
    engine = create_engine(url, poolclass=pool.NullPool)

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

    try:
        with context.begin_transaction():
            connection.execute('SELECT pg_advisory_lock(1)')
            context.run_migrations()
    finally:
        connection.close()
github lfos / aurweb / migrations / env.py View on Github external
In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connectable = sqlalchemy.create_engine(
        aurweb.db.get_sqlalchemy_url(),
        poolclass=sqlalchemy.pool.NullPool,
    )

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

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