Merge branch 'images-db-issues' into 'master'

Bypass image db updates if the db has already been upgraded

Closes #1533

See merge request openlp/openlp!654
This commit is contained in:
Tim Bentley 2023-08-25 19:07:46 +00:00
commit 6779be4433
1 changed files with 14 additions and 1 deletions

View File

@ -53,9 +53,15 @@ def upgrade_2(session: Session, metadata: MetaData):
Version 2 upgrade - Move file path from old db to JSON encoded path to new db. Added during 2.5 dev
"""
log.debug('Starting upgrade_2 for file_path to JSON')
op = get_upgrade_op(session)
conn = op.get_bind()
# Check if the table exists
table_names = inspect(conn).get_table_names()
if 'image_filenames' not in table_names:
# Bypass this upgrade, it has already been performed
return
images_table = Table('image_filenames', metadata, extend_existing=True, autoload_with=metadata.bind)
if 'file_path' not in [col.name for col in images_table.c.values()]:
op = get_upgrade_op(session)
with op.batch_alter_table('image_filenames') as batch_op:
batch_op.add_column(Column('file_path', PathType()))
# Refresh the table definition
@ -80,6 +86,13 @@ def upgrade_3(session: Session, metadata: MetaData):
Version 3 upgrade - add sha256 hash
"""
log.debug('Starting upgrade_3 for adding sha256 hashes')
op = get_upgrade_op(session)
conn = op.get_bind()
# Check if the table exists
table_names = inspect(conn).get_table_names()
if 'image_filenames' not in table_names:
# Bypass this upgrade, it has already been performed
return
images_table = Table('image_filenames', metadata, extend_existing=True, autoload_with=metadata.bind)
if 'file_hash' not in [col.name for col in images_table.c.values()]:
op = get_upgrade_op(session)