本文整理汇总了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
)
示例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)
示例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)
)
示例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)
示例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)
示例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')
示例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")
示例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')
示例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)
示例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)
示例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()
示例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")
示例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 = {}
示例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)
示例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)