avoid deprecated engine.table_names

deprecated in sqlalchemy 1.4

use recommended inspect(engine).get_table_names() instead
This commit is contained in:
Min RK
2021-03-26 12:54:40 +01:00
parent 8f2b14429f
commit caae99aa09
6 changed files with 9 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ tables = ('oauth_access_tokens', 'oauth_codes')
def add_column_if_table_exists(table, column): def add_column_if_table_exists(table, column):
engine = op.get_bind().engine engine = op.get_bind().engine
if table not in engine.table_names(): if table not in sa.inspect(engine).get_table_names():
# table doesn't exist, no need to upgrade # table doesn't exist, no need to upgrade
# because jupyterhub will create it on launch # because jupyterhub will create it on launch
logger.warning("Skipping upgrade of absent table: %s", table) logger.warning("Skipping upgrade of absent table: %s", table)

View File

@@ -17,7 +17,8 @@ from jupyterhub.orm import JSONDict
def upgrade(): def upgrade():
tables = op.get_bind().engine.table_names() engine = op.get_bind().engine
tables = sa.inspect(engine).get_table_names()
if 'spawners' in tables: if 'spawners' in tables:
op.add_column('spawners', sa.Column('user_options', JSONDict())) op.add_column('spawners', sa.Column('user_options', JSONDict()))

View File

@@ -20,7 +20,8 @@ logger = logging.getLogger('alembic')
def upgrade(): def upgrade():
tables = op.get_bind().engine.table_names() engine = op.get_bind().engine
tables = sa.inspect(engine).get_table_names()
op.add_column('api_tokens', sa.Column('created', sa.DateTime(), nullable=True)) op.add_column('api_tokens', sa.Column('created', sa.DateTime(), nullable=True))
op.add_column( op.add_column(
'api_tokens', sa.Column('last_activity', sa.DateTime(), nullable=True) 'api_tokens', sa.Column('last_activity', sa.DateTime(), nullable=True)

View File

@@ -31,7 +31,7 @@ def upgrade():
% (now,) % (now,)
) )
tables = c.engine.table_names() tables = sa.inspect(c.engine).get_table_names()
if 'spawners' in tables: if 'spawners' in tables:
op.add_column('spawners', sa.Column('started', sa.DateTime, nullable=True)) op.add_column('spawners', sa.Column('started', sa.DateTime, nullable=True))

View File

@@ -16,7 +16,8 @@ import sqlalchemy as sa
def upgrade(): def upgrade():
tables = op.get_bind().engine.table_names() engine = op.get_bind().engine
tables = sa.inspect(engine).get_table_names()
if 'oauth_clients' in tables: if 'oauth_clients' in tables:
op.add_column( op.add_column(
'oauth_clients', sa.Column('description', sa.Unicode(length=1023)) 'oauth_clients', sa.Column('description', sa.Unicode(length=1023))

View File

@@ -768,7 +768,7 @@ def check_db_revision(engine):
- Empty databases are tagged with the current revision - Empty databases are tagged with the current revision
""" """
# Check database schema version # Check database schema version
current_table_names = set(engine.table_names()) current_table_names = set(inspect(engine).get_table_names())
my_table_names = set(Base.metadata.tables.keys()) my_table_names = set(Base.metadata.tables.keys())
from .dbutil import _temp_alembic_ini from .dbutil import _temp_alembic_ini