Use inspect instead of Inspector.from_engine()
SQLAlchemy is likely going to deprecate Inspector.from_engine() which will start emitting a deprecation warning in 1.4. Use sqlalchemy.inspect() instead. Change-Id: I287ba10f2e3308950b9caf6f51f3ee1db29a6448
This commit is contained in:
parent
99733f172f
commit
527b1587e1
@ -12,7 +12,6 @@
|
||||
|
||||
import migrate
|
||||
import sqlalchemy as sql
|
||||
from sqlalchemy.engine import reflection
|
||||
|
||||
from keystone.common.sql import upgrades
|
||||
|
||||
@ -20,7 +19,7 @@ from keystone.common.sql import upgrades
|
||||
def upgrade(migrate_engine):
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
inspector = reflection.Inspector.from_engine(migrate_engine)
|
||||
inspector = sql.inspect(migrate_engine)
|
||||
|
||||
user = sql.Table('user', meta, autoload=True)
|
||||
local_user = sql.Table('local_user', meta, autoload=True)
|
||||
|
@ -22,7 +22,7 @@ def upgrade(migrate_engine):
|
||||
service_table = sql.Table('service', meta, autoload=True)
|
||||
region_table = sql.Table('region', meta, autoload=True)
|
||||
|
||||
inspector = sql.engine.reflection.Inspector.from_engine(migrate_engine)
|
||||
inspector = sql.inspect(migrate_engine)
|
||||
for fk in inspector.get_foreign_keys('registered_limit'):
|
||||
if fk['referred_table'] == 'service':
|
||||
fkey = ForeignKeyConstraint([registered_limit_table.c.service_id],
|
||||
|
@ -26,7 +26,7 @@ def upgrade(migrate_engine):
|
||||
|
||||
if migrate_engine.name != 'sqlite':
|
||||
project_table = sql.Table('project', meta, autoload=True)
|
||||
inspector = sql.engine.reflection.Inspector.from_engine(migrate_engine)
|
||||
inspector = sql.inspect(migrate_engine)
|
||||
for fk in inspector.get_foreign_keys('limit'):
|
||||
fkey = migrate.ForeignKeyConstraint(
|
||||
[limit_table.c.project_id],
|
||||
|
@ -56,8 +56,8 @@ from oslo_log import log
|
||||
from oslo_serialization import jsonutils
|
||||
from oslotest import base as test_base
|
||||
import pytz
|
||||
from sqlalchemy.engine import reflection
|
||||
import sqlalchemy.exc
|
||||
from sqlalchemy import inspect
|
||||
from testtools import matchers
|
||||
|
||||
from keystone.cmd import cli
|
||||
@ -312,13 +312,13 @@ class SqlMigrateBase(db_fixtures.OpportunisticDBTestMixin,
|
||||
|
||||
def does_pk_exist(self, table, pk_column):
|
||||
"""Check whether a column is primary key on a table."""
|
||||
inspector = reflection.Inspector.from_engine(self.engine)
|
||||
inspector = inspect(self.engine)
|
||||
pk_columns = inspector.get_pk_constraint(table)['constrained_columns']
|
||||
|
||||
return pk_column in pk_columns
|
||||
|
||||
def does_fk_exist(self, table, fk_column):
|
||||
inspector = reflection.Inspector.from_engine(self.engine)
|
||||
inspector = inspect(self.engine)
|
||||
for fk in inspector.get_foreign_keys(table):
|
||||
if fk_column in fk['constrained_columns']:
|
||||
return True
|
||||
@ -333,7 +333,7 @@ class SqlMigrateBase(db_fixtures.OpportunisticDBTestMixin,
|
||||
return index_name in [idx.name for idx in table.indexes]
|
||||
|
||||
def does_unique_constraint_exist(self, table_name, column_names):
|
||||
inspector = reflection.Inspector.from_engine(self.engine)
|
||||
inspector = inspect(self.engine)
|
||||
constraints = inspector.get_unique_constraints(table_name)
|
||||
for c in constraints:
|
||||
if (len(c['column_names']) == 1 and
|
||||
@ -668,7 +668,7 @@ class SqlLegacyRepoUpgradeTests(SqlMigrateBase):
|
||||
|
||||
def test_add_trust_unique_constraint_upgrade(self):
|
||||
self.upgrade(86)
|
||||
inspector = reflection.Inspector.from_engine(self.engine)
|
||||
inspector = inspect(self.engine)
|
||||
constraints = inspector.get_unique_constraints('trust')
|
||||
constraint_names = [constraint['name'] for constraint in constraints]
|
||||
self.assertIn('duplicate_trust_constraint', constraint_names)
|
||||
@ -701,7 +701,7 @@ class SqlLegacyRepoUpgradeTests(SqlMigrateBase):
|
||||
session = self.sessionmaker()
|
||||
self.assertTableColumns('role', ['id', 'name', 'domain_id', 'extra'])
|
||||
# Check the domain_id has been added to the uniqueness constraint
|
||||
inspector = reflection.Inspector.from_engine(self.engine)
|
||||
inspector = inspect(self.engine)
|
||||
constraints = inspector.get_unique_constraints('role')
|
||||
constraint_columns = [
|
||||
constraint['column_names'] for constraint in constraints
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
fixes:
|
||||
- >
|
||||
Replaced the usage of SQLAlchemy Inspector.from_engine() with the
|
||||
sqlalchemy.inspect() call, within several Alembic migration files as well
|
||||
as a test suite. SQLAlchemy will be deprecating the former syntax,
|
||||
so this change allows forwads compatibility with the next series of
|
||||
SQLAlchemy.
|
Loading…
x
Reference in New Issue
Block a user