Skip to content

Commit

Permalink
Fix database functions for SQLAlchemy 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Mar 31, 2023
1 parent ba9afaf commit 741da20
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions isimip_publisher/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,7 @@ def update_views(session):


def update_words_view(session):
engine = session.get_bind()
if 'words' in inspect(engine).get_materialized_view_names():
if 'words' in get_materialized_view_names(session):
session.connection().execute(text('''
REFRESH MATERIALIZED VIEW words
'''))
Expand All @@ -757,8 +756,7 @@ def update_words_view(session):


def update_identifiers_view(session):
engine = session.get_bind()
if 'identifiers' in inspect(engine).get_materialized_view_names():
if 'identifiers' in get_materialized_view_names(session):
session.connection().execute(text('''
REFRESH MATERIALIZED VIEW identifiers
'''))
Expand All @@ -777,3 +775,12 @@ def update_identifiers_view(session):
CREATE INDEX ON identifiers(identifier)
'''))
logger.debug('create identifiers view')


def get_materialized_view_names(session):
engine = session.get_bind()
try:
return inspect(engine).get_materialized_view_names()
except AttributeError:
# for SQLAlchemy < 2
return inspect(engine).get_view_names()

0 comments on commit 741da20

Please sign in to comment.