当前位置: 首页>>代码示例>>Python>>正文


Python MigrationContext.configure方法代码示例

本文整理汇总了Python中alembic.migration.MigrationContext.configure方法的典型用法代码示例。如果您正苦于以下问题:Python MigrationContext.configure方法的具体用法?Python MigrationContext.configure怎么用?Python MigrationContext.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alembic.migration.MigrationContext的用法示例。


在下文中一共展示了MigrationContext.configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_filters

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def run_filters(self, object_, name, type_, reflected, compare_to):
        """Run the context's object filters and return True if the targets
        should be part of the autogenerate operation.

        This method should be run for every kind of object encountered within
        an autogenerate operation, giving the environment the chance
        to filter what objects should be included in the comparison.
        The filters here are produced directly via the
        :paramref:`.EnvironmentContext.configure.include_object`
        and :paramref:`.EnvironmentContext.configure.include_symbol`
        functions, if present.

        """
        for fn in self._object_filters:
            if not fn(object_, name, type_, reflected, compare_to):
                return False
        else:
            return True 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:api.py

示例2: check_migrations

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def check_migrations(timeout):
    """
    Function to wait for all airflow migrations to complete.
    @param timeout:
    @return:
    """
    from alembic.runtime.migration import MigrationContext
    from alembic.script import ScriptDirectory

    config = _get_alembic_config()
    script_ = ScriptDirectory.from_config(config)
    with settings.engine.connect() as connection:
        context = MigrationContext.configure(connection)
        ticker = 0
        while True:
            source_heads = set(script_.get_heads())
            db_heads = set(context.get_current_heads())
            if source_heads == db_heads:
                break
            if ticker >= timeout:
                raise TimeoutError("There are still unapplied migrations after {} "
                                   "seconds.".format(ticker))
            ticker += 1
            time.sleep(1)
            log.info('Waiting for migrations... %s second(s)', ticker) 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:db.py

示例3: __init__

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def __init__(self, registry):
        self.withoutautomigration = registry.withoutautomigration
        self.conn = registry.connection()
        self.loaded_views = registry.loaded_views
        self.metadata = registry.declarativebase.metadata
        self.ddl_compiler = self.conn.dialect.ddl_compiler(
            self.conn.dialect, None)

        opts = {
            'include_schemas': True,
            'compare_server_default': True,
            'render_item': self.render_item,
            'compare_type': self.compare_type,
        }
        self.context = MigrationContext.configure(self.conn, opts=opts)
        self.operation = Operations(self.context)
        self.reinit_all = Configuration.get('reinit_all', False)
        self.reinit_tables = Configuration.get('reinit_tables', False)
        self.reinit_columns = Configuration.get('reinit_columns', False)
        self.reinit_indexes = Configuration.get('reinit_indexes', False)
        self.reinit_constraints = Configuration.get(
            'reinit_constraints', False) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:24,代码来源:migration.py

示例4: setUp

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def setUp(self):
        self.conn = conn = self.bind.connect()
        ctx_opts = {
            "compare_type": True,
            "compare_server_default": True,
            "target_metadata": self.m2,
            "upgrade_token": "upgrades",
            "downgrade_token": "downgrades",
            "alembic_module_prefix": "op.",
            "sqlalchemy_module_prefix": "sa.",
            "include_object": _default_object_filters,
        }
        if self.configure_opts:
            ctx_opts.update(self.configure_opts)
        self.context = context = MigrationContext.configure(
            connection=conn, opts=ctx_opts
        )

        self.autogen_context = api.AutogenContext(context, self.m2) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:_autogen_fixtures.py

示例5: setUp

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def setUp(self):
        self.conn = config.db.connect()
        self.conn.execute(
            text(
                """
            create table foo(
                id integer primary key,
                data varchar(50),
                x integer
            )
        """
            )
        )
        context = MigrationContext.configure(self.conn)
        self.op = op.Operations(context)
        self.t1 = table("foo", column("id"), column("data"), column("x")) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:18,代码来源:test_bulk_insert.py

示例6: test_render_server_default_context_passed

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def test_render_server_default_context_passed(self):
        uo = ops.UpgradeOps(
            ops=[
                ops.CreateTableOp(
                    "sometable",
                    [Column("x", types.DateTime(), server_default=func.now())],
                )
            ]
        )
        context = MigrationContext.configure(dialect_name="sqlite")
        eq_ignore_whitespace(
            autogenerate.render_python_code(uo, migration_context=context),
            "# ### commands auto generated by Alembic - please adjust! ###\n"
            "    op.create_table('sometable',\n"
            "    sa.Column('x', sa.DateTime(), "
            "server_default=sa.text(!U'(CURRENT_TIMESTAMP)'), nullable=True)\n"
            "    )\n"
            "    # ### end Alembic commands ###",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:test_autogen_render.py

示例7: setUp

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def setUp(self):

        convention = {
            "ix": "ix_%(custom)s_%(column_0_label)s",
            "uq": "uq_%(custom)s_%(table_name)s_%(column_0_name)s",
            "ck": "ck_%(custom)s_%(table_name)s",
            "fk": "fk_%(custom)s_%(table_name)s_"
            "%(column_0_name)s_%(referred_table_name)s",
            "pk": "pk_%(custom)s_%(table_name)s",
            "custom": lambda const, table: "ct",
        }

        self.metadata = MetaData(naming_convention=convention)

        ctx_opts = {
            "sqlalchemy_module_prefix": "sa.",
            "alembic_module_prefix": "op.",
            "target_metadata": MetaData(),
        }
        context = MigrationContext.configure(
            dialect_name="postgresql", opts=ctx_opts
        )
        self.autogen_context = api.AutogenContext(context) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:25,代码来源:test_autogen_render.py

示例8: create

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def create(force=False):
    """Create tables if the database has not been configured yet."""
    # Fail if there's an alembic version set
    engine = db.get_engine(flask.current_app)
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_rev = context.get_current_revision()
    alembic_config = flask.current_app.extensions['migrate'].migrate.get_config(
            directory=migrate_path)
    script = ScriptDirectory.from_config(alembic_config)
    latest_rev = script.get_current_head()
    if current_rev == latest_rev and not force:
        print(u"You need to run 'evesrp -c config.py db migrate' to "
              u"migrate to the latest database schema.")
    else:
        db.create_all()
        if current_rev is None:
            stamp() 
开发者ID:paxswill,项目名称:evesrp,代码行数:20,代码来源:manage.py

示例9: configure_db

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def configure_db(app):
    """
    0.10 is the first version of ARA that ships with a stable database schema.
    We can identify a database that originates from before this by checking if
    there is an alembic revision available.
    If there is no alembic revision available, assume we are running the first
    revision which contains the latest state of the database prior to this.
    """
    db.init_app(app)
    log = logging.getLogger(app.logger_name)

    if app.config.get('ARA_AUTOCREATE_DATABASE'):
        with app.app_context():
            migrations = app.config['DB_MIGRATIONS']
            flask_migrate.Migrate(app, db, directory=migrations)
            config = app.extensions['migrate'].migrate.get_config(migrations)

            # Verify if the database tables have been created at all
            inspector = Inspector.from_engine(db.engine)
            if len(inspector.get_table_names()) == 0:
                log.info('Initializing new DB from scratch')
                flask_migrate.upgrade(directory=migrations)

            # Get current alembic head revision
            script = ScriptDirectory.from_config(config)
            head = script.get_current_head()

            # Get current revision, if available
            connection = db.engine.connect()
            context = MigrationContext.configure(connection)
            current = context.get_current_revision()

            if not current:
                log.info('Unstable DB schema, stamping original revision')
                flask_migrate.stamp(directory=migrations,
                                    revision='da9459a1f71c')

            if head != current:
                log.info('DB schema out of date, upgrading')
                flask_migrate.upgrade(directory=migrations) 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:42,代码来源:webapp.py

示例10: fix

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def fix(self):
        """Uses Alembic batch operations to alter the column datatype in the
        table.
        """
        context = MigrationContext.configure(self.parent.engine.connect())
        op = Operations(context)
        for table in self.parent.base.metadata.sorted_tables:
            if table.name == self.table:
                for column in table.columns:
                    if column.name == self.column['name']:
                        with op.batch_alter_table(table.name) as batch_op:
                            batch_op.alter_column(column.name,
                                                  type_=column.type)
                        return 
开发者ID:Hamuko,项目名称:cum,代码行数:16,代码来源:sanity.py

示例11: drop_airflow_models

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def drop_airflow_models(connection):
    """
    Drops all airflow models.
    @param connection:
    @return: None
    """
    from airflow.models.base import Base
    # Drop connection and chart - those tables have been deleted and in case you
    # run resetdb on schema with chart or users table will fail
    chart = Table('chart', Base.metadata)
    chart.drop(settings.engine, checkfirst=True)
    user = Table('user', Base.metadata)
    user.drop(settings.engine, checkfirst=True)
    users = Table('users', Base.metadata)
    users.drop(settings.engine, checkfirst=True)
    dag_stats = Table('dag_stats', Base.metadata)
    dag_stats.drop(settings.engine, checkfirst=True)

    Base.metadata.drop_all(connection)
    # we remove the Tables here so that if resetdb is run metadata does not keep the old tables.
    Base.metadata.remove(dag_stats)
    Base.metadata.remove(users)
    Base.metadata.remove(user)
    Base.metadata.remove(chart)
    # alembic adds significant import time, so we import it lazily
    # noinspection PyUnresolvedReferences
    from alembic.migration import MigrationContext
    migration_ctx = MigrationContext.configure(connection)
    # noinspection PyProtectedMember
    version = migration_ctx._version  # pylint: disable=protected-access
    if version.exists(connection):
        version.drop(connection) 
开发者ID:apache,项目名称:airflow,代码行数:34,代码来源:db.py

示例12: current_db_revision

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def current_db_revision():
    ctx = MigrationContext.configure(db.engine.connect())
    return ctx.get_current_revision() 
开发者ID:chainer,项目名称:chainerui,代码行数:5,代码来源:db_revision.py

示例13: render_python_code

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def render_python_code(
    up_or_down_op,
    sqlalchemy_module_prefix="sa.",
    alembic_module_prefix="op.",
    render_as_batch=False,
    imports=(),
    render_item=None,
    migration_context=None,
):
    """Render Python code given an :class:`.UpgradeOps` or
    :class:`.DowngradeOps` object.

    This is a convenience function that can be used to test the
    autogenerate output of a user-defined :class:`.MigrationScript` structure.

    """
    opts = {
        "sqlalchemy_module_prefix": sqlalchemy_module_prefix,
        "alembic_module_prefix": alembic_module_prefix,
        "render_item": render_item,
        "render_as_batch": render_as_batch,
    }

    if migration_context is None:
        from ..runtime.migration import MigrationContext
        from sqlalchemy.engine.default import DefaultDialect

        migration_context = MigrationContext.configure(
            dialect=DefaultDialect()
        )

    autogen_context = AutogenContext(migration_context, opts=opts)
    autogen_context.imports = set(imports)
    return render._indent(
        render._render_cmd_body(up_or_down_op, autogen_context)
    ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:38,代码来源:api.py

示例14: setup_class

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def setup_class(cls):
        cls.bind = config.db
        staging_env()
        cls.migration_context = MigrationContext.configure(
            connection=cls.bind.connect(),
            opts={"compare_type": True, "compare_server_default": True},
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:9,代码来源:test_sqlite.py

示例15: setUp

# 需要导入模块: from alembic.migration import MigrationContext [as 别名]
# 或者: from alembic.migration.MigrationContext import configure [as 别名]
def setUp(self):
        ctx_opts = {
            "sqlalchemy_module_prefix": "sa.",
            "alembic_module_prefix": "op.",
            "target_metadata": MetaData(),
            "user_module_prefix": None,
        }
        context = MigrationContext.configure(
            dialect_name="custom_dialect", opts=ctx_opts
        )

        self.autogen_context = api.AutogenContext(context) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:14,代码来源:test_external_dialect.py


注:本文中的alembic.migration.MigrationContext.configure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。