當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。