From 03ae8325c9fd854fdb493732f04c2862f8b8317f Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 10 Aug 2020 18:50:54 -0700 Subject: [PATCH] Use same transactional try-except-else as YCDL. --- utilities/database_upgrader/database_upgrader.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/utilities/database_upgrader/database_upgrader.py b/utilities/database_upgrader/database_upgrader.py index 661d96c..6237f8d 100644 --- a/utilities/database_upgrader/database_upgrader.py +++ b/utilities/database_upgrader/database_upgrader.py @@ -284,9 +284,17 @@ def upgrade_all(data_directory): print('Upgrading from %d to %d.' % (current_version, version_number)) upgrade_function = 'upgrade_%d_to_%d' % (current_version, version_number) upgrade_function = eval(upgrade_function) - upgrade_function(photodb) - photodb.sql.cursor().execute('PRAGMA user_version = %d' % version_number) - photodb.commit() + + try: + photodb.sql.execute('BEGIN') + upgrade_function(photodb) + except Exception as exc: + photodb.rollback() + raise + else: + photodb.sql.cursor().execute('PRAGMA user_version = %d' % version_number) + photodb.commit() + current_version = version_number print('Upgrades finished.')