Browse Source

Merge "Use inspect instead of Inspector.from_engine()"

changes/66/709366/1
Zuul 2 years ago
committed by Gerrit Code Review
parent
commit
cdab9284d1
  1. 3
      keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py
  2. 2
      keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py
  3. 2
      keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py
  4. 12
      keystone/tests/unit/test_sql_upgrade.py
  5. 8
      releasenotes/notes/use-correct-inspect-8142e317c1e39c2a.yaml

3
keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py

@ -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)

2
keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py

@ -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],

2
keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py

@ -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],

12
keystone/tests/unit/test_sql_upgrade.py

@ -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

8
releasenotes/notes/use-correct-inspect-8142e317c1e39c2a.yaml

@ -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…
Cancel
Save