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


Python Inspector.from_engine方法代码示例

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


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

示例1: _produce_net_changes

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def _produce_net_changes(autogen_context, upgrade_ops):

    connection = autogen_context.connection
    include_schemas = autogen_context.opts.get('include_schemas', False)

    inspector = Inspector.from_engine(connection)

    default_schema = connection.dialect.default_schema_name
    if include_schemas:
        schemas = set(inspector.get_schema_names())
        # replace default schema name with None
        schemas.discard("information_schema")
        # replace the "default" schema with None
        schemas.add(None)
        schemas.discard(default_schema)
    else:
        schemas = [None]

    comparators.dispatch("schema", autogen_context.dialect.name)(
        autogen_context, upgrade_ops, schemas
    ) 
开发者ID:jpush,项目名称:jbox,代码行数:23,代码来源:compare.py

示例2: upgrade

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def upgrade(migrate_engine):
    meta.bind = migrate_engine

    pool_ns_records_table = Table('pool_ns_records', meta, autoload=True)

    # Only apply it if it's not there (It's been backported to L)
    insp = Inspector.from_engine(migrate_engine)
    unique_constraints = insp.get_unique_constraints('pool_ns_records')
    unique_constraint_names = [i['name'] for i in unique_constraints]

    if CONSTRAINT_NAME not in unique_constraint_names:
        # We define the constraint here if not it shows in the list above.
        constraint = UniqueConstraint('pool_id', 'hostname',
                                      name=CONSTRAINT_NAME,
                                      table=pool_ns_records_table)
        try:
            constraint.create()
        except exc.IntegrityError as e:
            LOG.error(explanation, e)
            # Use sys.exit so we don't blow up with a huge trace
            sys.exit(1) 
开发者ID:openstack,项目名称:designate,代码行数:23,代码来源:082_unique_ns_record.py

示例3: upgrade

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def upgrade():   # noqa: D103
    # first check if the user already has this done. This should only be
    # true for users who are upgrading from a previous version of Airflow
    # that predates Alembic integration
    conn = op.get_bind()
    inspector = Inspector.from_engine(conn)

    # this will only be true if 'connection' already exists in the db,
    # but not if alembic created it in a previous migration
    if 'connection' in inspector.get_table_names():
        col_names = [c['name'] for c in inspector.get_columns('connection')]
        if 'is_encrypted' in col_names:
            return

    op.add_column(
        'connection',
        sa.Column('is_encrypted', sa.Boolean, unique=False, default=False))

    conn = op.get_bind()
    conn.execute(
        connectionhelper.update().values(is_encrypted=False)
    ) 
开发者ID:apache,项目名称:airflow,代码行数:24,代码来源:1507a7289a2f_create_is_encrypted.py

示例4: from_engine

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def from_engine(cls, bind):
        """Construct a new dialect-specific Inspector object from the given
        engine or connection.

        :param bind: a :class:`~sqlalchemy.engine.Connectable`,
          which is typically an instance of
          :class:`~sqlalchemy.engine.Engine` or
          :class:`~sqlalchemy.engine.Connection`.

        This method differs from direct a direct constructor call of
        :class:`.Inspector` in that the
        :class:`~sqlalchemy.engine.interfaces.Dialect` is given a chance to
        provide a dialect-specific :class:`.Inspector` instance, which may
        provide additional methods.

        See the example at :class:`.Inspector`.

        """
        if hasattr(bind.dialect, 'inspector'):
            return bind.dialect.inspector(bind)
        return Inspector(bind) 
开发者ID:yfauser,项目名称:planespotter,代码行数:23,代码来源:reflection.py

示例5: from_engine

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def from_engine(cls, bind):
        """Construct a new dialect-specific Inspector object from the given
        engine or connection.

        :param bind: a :class:`~sqlalchemy.engine.Connectable`,
          which is typically an instance of
          :class:`~sqlalchemy.engine.Engine` or
          :class:`~sqlalchemy.engine.Connection`.

        This method differs from direct a direct constructor call of
        :class:`_reflection.Inspector` in that the
        :class:`~sqlalchemy.engine.interfaces.Dialect` is given a chance to
        provide a dialect-specific :class:`_reflection.Inspector` instance,
        which may
        provide additional methods.

        See the example at :class:`_reflection.Inspector`.

        """
        return cls._construct(cls._init_legacy, bind) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:reflection.py

示例6: upgrade

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def upgrade():
    bind = op.get_bind()

    inspector = insp.from_engine(bind)
    foreign_keys = inspector.get_foreign_keys(CONTAINER_ACTIONS)

    for foreign_key in foreign_keys:
        if foreign_key.get('referred_table') == CONTAINER:
            op.drop_constraint(foreign_key.get('name'), CONTAINER_ACTIONS,
                               type_="foreignkey")
            op.create_foreign_key(
                None, CONTAINER_ACTIONS, CONTAINER, ['container_uuid'],
                ['uuid'], ondelete='CASCADE') 
开发者ID:openstack,项目名称:zun,代码行数:15,代码来源:fb9ad4a050f8_drop_container_actions_foreign_key.py

示例7: upgrade

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def upgrade():
    bind = op.get_bind()

    inspector = insp.from_engine(bind)
    foreign_keys = inspector.get_foreign_keys(CONTAINER_ACTIONS)

    for foreign_key in foreign_keys:
        if foreign_key.get('referred_table') == CONTAINER:
            op.drop_constraint(foreign_key.get('name'), CONTAINER_ACTIONS,
                               type_="foreignkey") 
开发者ID:openstack,项目名称:zun,代码行数:12,代码来源:8b0082d9e7c1_drop_foreign_key_of_container_actions.py

示例8: upgrade

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def upgrade():
    bind = op.get_bind()

    inspector = insp.from_engine(bind)
    foreign_keys = inspector.get_foreign_keys(CONTAINER_ACTIONS_EVENTS)

    for foreign_key in foreign_keys:
        if foreign_key.get('referred_table') == CONTAINER_ACTIONS:
            op.drop_constraint(foreign_key.get('name'),
                               CONTAINER_ACTIONS_EVENTS,
                               type_="foreignkey")
            op.create_foreign_key(
                None, CONTAINER_ACTIONS_EVENTS, CONTAINER_ACTIONS,
                ['action_id'], ['id'], ondelete='CASCADE') 
开发者ID:openstack,项目名称:zun,代码行数:16,代码来源:50829990c965_add_ondelete_to_container_actions_.py

示例9: configure_db

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [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: inspector

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def inspector(self):
        return Inspector.from_engine(self.connection) 
开发者ID:jpush,项目名称:jbox,代码行数:4,代码来源:api.py

示例11: make_sure_there_is_a_working_database

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def make_sure_there_is_a_working_database(*args, **kwargs):
    if current_app.config.get('ENV') != 'dev':
        return
    inspector = Inspector.from_engine(db.engine)
    tables = inspector.get_table_names()
    required_tables = [models.PDFForm.__tablename__]
    if not (set(required_tables) < set(tables)):
        current_app.logger.warning(
            "database tables {} not found. Creating tables".format(required_tables))
        db.create_all() 
开发者ID:codeforamerica,项目名称:pdfhook,代码行数:12,代码来源:views.py

示例12: upgrade

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def upgrade():   # noqa: D103
    # We previously had a KnownEvent's table, but we deleted the table without
    # a down migration to remove it (so we didn't delete anyone's data if they
    # were happing to use the feature.
    #
    # But before we can delete the users table we need to drop the FK

    conn = op.get_bind()
    inspector = Inspector.from_engine(conn)

    if 'known_event' in inspector.get_table_names() != 'sqlite':
        op.drop_constraint('known_event_user_id_fkey', 'known_event')

    op.drop_table("chart")
    op.drop_table("users") 
开发者ID:apache,项目名称:airflow,代码行数:17,代码来源:cf5dc11e79ad_drop_user_and_chart.py

示例13: __init__

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def __init__(self, bind):
        """Initialize a new :class:`.Inspector`.

        :param bind: a :class:`~sqlalchemy.engine.Connectable`,
          which is typically an instance of
          :class:`~sqlalchemy.engine.Engine` or
          :class:`~sqlalchemy.engine.Connection`.

        For a dialect-specific instance of :class:`.Inspector`, see
        :meth:`.Inspector.from_engine`

        """
        # this might not be a connection, it could be an engine.
        self.bind = bind

        # set the engine
        if hasattr(bind, 'engine'):
            self.engine = bind.engine
        else:
            self.engine = bind

        if self.engine is bind:
            # if engine, ensure initialized
            bind.connect().close()

        self.dialect = self.engine.dialect
        self.info_cache = {} 
开发者ID:yfauser,项目名称:planespotter,代码行数:29,代码来源:reflection.py

示例14: _insp

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def _insp(bind):
        return Inspector.from_engine(bind) 
开发者ID:yfauser,项目名称:planespotter,代码行数:4,代码来源:reflection.py

示例15: __init__

# 需要导入模块: from sqlalchemy.engine.reflection import Inspector [as 别名]
# 或者: from sqlalchemy.engine.reflection.Inspector import from_engine [as 别名]
def __init__(self, bind):
        """Initialize a new :class:`_reflection.Inspector`.

        :param bind: a :class:`~sqlalchemy.engine.Connectable`,
          which is typically an instance of
          :class:`~sqlalchemy.engine.Engine` or
          :class:`~sqlalchemy.engine.Connection`.

        For a dialect-specific instance of :class:`_reflection.Inspector`, see
        :meth:`_reflection.Inspector.from_engine`

        """
        return self._init_legacy(bind) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:15,代码来源:reflection.py


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