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


Python operations.Operations方法代码示例

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


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

示例1: __init__

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [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

示例2: setUp

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def setUp(self):
        self.conn = config.db.connect()
        self.metadata = MetaData()
        t1 = Table(
            "foo",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("data", String(50)),
            Column("x", Integer),
            mysql_engine="InnoDB",
        )
        t1.create(self.conn)

        self.conn.execute(
            t1.insert(),
            [
                {"id": 1, "data": "d1", "x": 5},
                {"id": 2, "data": "22", "x": 6},
                {"id": 3, "data": "8.5", "x": 7},
                {"id": 4, "data": "9.46", "x": 8},
                {"id": 5, "data": "d5", "x": 9},
            ],
        )
        context = MigrationContext.configure(self.conn)
        self.op = Operations(context) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:27,代码来源:test_batch.py

示例3: recheck_alembic_table

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def recheck_alembic_table(conn):
    """check and update alembic version table.

    Should check current alembic version table against conf and rename the
    existing table if the two values don't match.
    """
    conf_table = getattr(CONF, 'version_table')
    conf_table_version = get_table_version(conn, conf_table)
    current_table, default_table = get_db_tables(conn)
    if current_table[0]:
        if current_table[0] != conf_table:
            context = alembic_migration.MigrationContext.configure(conn)
            op = Operations(context)
            if conf_table and not conf_table_version:
                # make sure there is not present-but-empty table
                # that will prevent us from renaming the current table
                op.drop_table(conf_table)
            op.rename_table(current_table[0], conf_table) 
开发者ID:openstack-archive,项目名称:refstack,代码行数:20,代码来源:utils.py

示例4: __init__

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def __init__(self, migration_context, impl=None):
        """Construct a new :class:`.Operations`

        :param migration_context: a :class:`.MigrationContext`
         instance.

        """
        self.migration_context = migration_context
        if impl is None:
            self.impl = migration_context.impl
        else:
            self.impl = impl

        self.schema_obj = schemaobj.SchemaObjects(migration_context) 
开发者ID:jpush,项目名称:jbox,代码行数:16,代码来源:base.py

示例5: context

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def context(cls, migration_context):
        op = Operations(migration_context)
        op._install_proxy()
        yield op
        op._remove_proxy() 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:base.py

示例6: invoke

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def invoke(self, operation):
        """Given a :class:`.MigrateOperation`, invoke it in terms of
        this :class:`.Operations` instance.

        .. versionadded:: 0.8.0

        """
        fn = self._to_impl.dispatch(
            operation, self.migration_context.impl.__dialect__)
        return fn(self, operation) 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:base.py

示例7: fix

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [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

示例8: invoke

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def invoke(self, operation):
        """Given a :class:`.MigrateOperation`, invoke it in terms of
        this :class:`.Operations` instance.

        .. versionadded:: 0.8.0

        """
        fn = self._to_impl.dispatch(
            operation, self.migration_context.impl.__dialect__
        )
        return fn(self, operation) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:13,代码来源:base.py

示例9: _fixture

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def _fixture(self):
        self.metadata = MetaData()
        self.table = Table(
            "foo",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("data", String(50)),
            Column("x", Integer),
        )

        context = op_fixture(dialect="sqlite", as_sql=True)
        self.op = Operations(context)
        return context 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:15,代码来源:test_batch.py

示例10: test_standalone_op

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def test_standalone_op(self):
        eng, buf = capture_db()

        env = MigrationContext.configure(eng)
        op = Operations(env)

        op.alter_column("t", "c", nullable=True)
        eq_(buf, ["ALTER TABLE t ALTER COLUMN c DROP NOT NULL"]) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:10,代码来源:test_config.py

示例11: setUp

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def setUp(self):
        self.conn = self.bind.connect()
        ctx = MigrationContext.configure(self.conn)
        self.op = Operations(ctx) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:6,代码来源:test_postgresql.py

示例12: op

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def op(self):
        """Get an alembic operations context."""
        ctx = MigrationContext.configure(self.executable)
        return Operations(ctx) 
开发者ID:bkerler,项目名称:android_universal,代码行数:6,代码来源:database.py

示例13: f

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def f(self, name):
        """Indicate a string name that has already had a naming convention
        applied to it.

        This feature combines with the SQLAlchemy ``naming_convention`` feature
        to disambiguate constraint names that have already had naming
        conventions applied to them, versus those that have not.  This is
        necessary in the case that the ``"%(constraint_name)s"`` token
        is used within a naming convention, so that it can be identified
        that this particular name should remain fixed.

        If the :meth:`.Operations.f` is used on a constraint, the naming
        convention will not take effect::

            op.add_column('t', 'x', Boolean(name=op.f('ck_bool_t_x')))

        Above, the CHECK constraint generated will have the name
        ``ck_bool_t_x`` regardless of whether or not a naming convention is
        in use.

        Alternatively, if a naming convention is in use, and 'f' is not used,
        names will be converted along conventions.  If the ``target_metadata``
        contains the naming convention
        ``{"ck": "ck_bool_%(table_name)s_%(constraint_name)s"}``, then the
        output of the following:

            op.add_column('t', 'x', Boolean(name='x'))

        will be::

            CONSTRAINT ck_bool_t_x CHECK (x in (1, 0)))

        The function is rendered in the output of autogenerate when
        a particular constraint name is already converted, for SQLAlchemy
        version **0.9.4 and greater only**.   Even though ``naming_convention``
        was introduced in 0.9.2, the string disambiguation service is new
        as of 0.9.4.

        .. versionadded:: 0.6.4

        """
        if conv:
            return conv(name)
        else:
            raise NotImplementedError(
                "op.f() feature requires SQLAlchemy 0.9.4 or greater.") 
开发者ID:jpush,项目名称:jbox,代码行数:48,代码来源:base.py

示例14: f

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def f(self, name):
        """Indicate a string name that has already had a naming convention
        applied to it.

        This feature combines with the SQLAlchemy ``naming_convention`` feature
        to disambiguate constraint names that have already had naming
        conventions applied to them, versus those that have not.  This is
        necessary in the case that the ``"%(constraint_name)s"`` token
        is used within a naming convention, so that it can be identified
        that this particular name should remain fixed.

        If the :meth:`.Operations.f` is used on a constraint, the naming
        convention will not take effect::

            op.add_column('t', 'x', Boolean(name=op.f('ck_bool_t_x')))

        Above, the CHECK constraint generated will have the name
        ``ck_bool_t_x`` regardless of whether or not a naming convention is
        in use.

        Alternatively, if a naming convention is in use, and 'f' is not used,
        names will be converted along conventions.  If the ``target_metadata``
        contains the naming convention
        ``{"ck": "ck_bool_%(table_name)s_%(constraint_name)s"}``, then the
        output of the following:

            op.add_column('t', 'x', Boolean(name='x'))

        will be::

            CONSTRAINT ck_bool_t_x CHECK (x in (1, 0)))

        The function is rendered in the output of autogenerate when
        a particular constraint name is already converted, for SQLAlchemy
        version **0.9.4 and greater only**.   Even though ``naming_convention``
        was introduced in 0.9.2, the string disambiguation service is new
        as of 0.9.4.

        .. versionadded:: 0.6.4

        """
        if conv:
            return conv(name)
        else:
            raise NotImplementedError(
                "op.f() feature requires SQLAlchemy 0.9.4 or greater."
            ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:49,代码来源:base.py

示例15: downgrade

# 需要导入模块: from alembic import operations [as 别名]
# 或者: from alembic.operations import Operations [as 别名]
def downgrade(engine, desired_version):
    """Downgrades the assets db at the given engine to the desired version.

    Parameters
    ----------
    engine : Engine
        An SQLAlchemy engine to the assets database.
    desired_version : int
        The desired resulting version for the assets database.
    """

    # Check the version of the db at the engine
    conn = engine.connect()
    metadata = sa.MetaData(conn)
    metadata.reflect(bind=engine)
    version_info_table = metadata.tables['version_info']
    starting_version = sa.select((version_info_table.c.version,)).scalar()

    # Check for accidental upgrade
    if starting_version < desired_version:
        raise AssetDBImpossibleDowngrade(db_version=starting_version,
                                         desired_version=desired_version)

    # Check if the desired version is already the db version
    if starting_version == desired_version:
        # No downgrade needed
        return

    # Create alembic context
    ctx = MigrationContext.configure(conn)
    op = Operations(ctx)

    # Integer keys of downgrades to run
    # E.g.: [5, 4, 3, 2] would downgrade v6 to v2
    downgrade_keys = range(desired_version, starting_version)[::-1]

    # Disable foreign keys until all downgrades are complete
    _pragma_foreign_keys(conn, False)

    # Execute the downgrades in order
    for downgrade_key in downgrade_keys:
        _downgrade_methods[downgrade_key](op, version_info_table)

    # Re-enable foreign keys
    _pragma_foreign_keys(conn, True) 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:47,代码来源:asset_db_migrations.py


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