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