How to use the alembic.context 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 assembl / assembl / assembl / alembic / versions / c3f8bc9c75d5_column_synthesis_post.py View on Github external
columns = db.query(m.IdeaMessageColumn).all()
        for column in columns:
            synthesis = column.get_column_synthesis()
            header_id = columns_headers.get(column.id, None)
            if header_id is not None and synthesis is None:
                name_en = column.name.closest_entry('en') or column.name.first_original()
                name_fr = column.name.closest_entry('fr') or column.name.first_original()
                subject_ls = m.LangString.create(u"Synthesis: {}".format(name_en.value), 'en')
                subject_ls.add_value(u"Synthèse : {}".format(name_fr.value), 'fr')
                body_ls = m.LangString.get(header_id)  # don't clone, reuse the same langstring
                column.create_column_synthesis(
                    subject=subject_ls,
                    body=body_ls,
                    creator_id=creator_id)

    with context.begin_transaction():
        op.drop_column('idea_message_column', 'header_id')
github CTFd / CTFd / migrations / env.py View on Github external
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,
            process_revision_directives=process_revision_directives,
            **current_app.extensions["migrate"].configure_args
        )

        with context.begin_transaction():
            context.run_migrations()
github dropbox / nsot / nsot / migrations / 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 leosussan / fastapi-gino-arq-uvicorn / app / models / orm / migrations / 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.

    """
    context.configure(
        url=ALEMBIC_CONFIG.url.__to_string__(hide_password=False), target_metadata=target_metadata, literal_binds=True
    )

    with context.begin_transaction():
        context.run_migrations()
github assembl / assembl / assembl / alembic / versions / ce427c9d6013_add_profile_select_fields.py View on Github external
def upgrade(pyramid_env):
    with context.begin_transaction():
        op.create_table(
            'select_field',
            sa.Column(
                "id", sa.Integer,
                sa.ForeignKey("configurable_field.id", ondelete='CASCADE', onupdate='CASCADE'),
                primary_key=True),
            sa.Column(
                "multivalued", sa.Boolean)
        )
        op.create_table(
            'select_field_option',
            sa.Column('id', sa.Integer, primary_key=True),
            sa.Column('order', sa.Float, nullable=False),
            sa.Column('label_id', sa.Integer, sa.ForeignKey('langstring.id'), nullable=False, index=True),
            sa.Column(
                'select_field_id',
github sholsapp / flask-skeleton / alembic / env.py View on Github external
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
    )

    with context.begin_transaction():
        context.run_migrations()
github hyperkitty / kittystore / kittystore / sa / alembic / env.py View on Github external
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool, create_engine
import logging
import logging.config

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Setup logging if necessary
root_logger = logging.getLogger()
if not root_logger.handlers:
    logging.config.fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
#target_metadata = None
import kittystore.sa
target_metadata = kittystore.sa.model.Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
github assembl / assembl / assembl / alembic / versions / 2df4150af427_idea_widget_link.py View on Github external
def downgrade(pyramid_env):
    with context.begin_transaction():
        op.add_column(
            'idea',
            sa.Column('widget_id', sa.Integer,
                      sa.ForeignKey('widget.id')))
        op.create_table(
            'idea_view_widget',
            sa.Column(
                'id', sa.Integer, sa.ForeignKey(
                    'widget.id', ondelete='CASCADE', onupdate='CASCADE'),
                primary_key=True),
            sa.Column(
                'main_idea_view_id', sa.Integer, sa.ForeignKey(
                    'idea_graph_view.id', ondelete="CASCADE",
                    onupdate="CASCADE"),
                nullable=True))
github simse / chronos / alembic / env.py View on Github external
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()
github bslatkin / dpxdt / alembic / 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()