From 8005b23aa12efb7fb893d293b2485f8a6e60372b Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Fri, 15 Oct 2021 14:45:41 +0300 Subject: [PATCH 1/2] fix: Migrating tables - Added exception of exercise - course and number indexes migration --- lms/lmsdb/bootstrap.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py index f5e85518..40c0f7e0 100644 --- a/lms/lmsdb/bootstrap.py +++ b/lms/lmsdb/bootstrap.py @@ -284,11 +284,8 @@ def _add_exercise_course_id_and_number_columns_constraint() -> bool: migrate( migrator.add_index('exercise', ('course_id', 'number'), True), ) - except OperationalError as e: - if 'already exists' in str(e): - log.info(f'index exercise already exists: {e}') - else: - raise + except (OperationalError, ProgrammingError) as e: + log.info(f'Index exercise course and number already exists: {e}') db_config.database.commit() From 91fe85fd64efe925a4cf348b327d9c7b314db9ab Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Fri, 15 Oct 2021 14:50:23 +0300 Subject: [PATCH 2/2] - Added exception of usercourse - user and course index constraint --- lms/lmsdb/bootstrap.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py index 40c0f7e0..64a9f401 100644 --- a/lms/lmsdb/bootstrap.py +++ b/lms/lmsdb/bootstrap.py @@ -298,11 +298,8 @@ def _add_user_course_constaint() -> bool: 'usercourse', ('user_id', 'course_id'), True, ), ) - except OperationalError as e: - if 'already exists' in str(e): - log.info(f'index usercourse already exists: {e}') - else: - raise + except (OperationalError, ProgrammingError) as e: + log.info(f'Index usercourse user and course already exists: {e}') db_config.database.commit()