From 948abfb04eac1d92ba1960a169d9025a8b9b1cb4 Mon Sep 17 00:00:00 2001 From: Allan Date: Tue, 24 May 2022 13:19:50 +0300 Subject: [PATCH] :bug: Add migration to update visit pre_processed values --- .../chw/util/RepositoryUtils.java | 3 + .../chw/repository/ChwRepositoryFlv.java | 73 +++++++++++-------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java b/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java index abcb2e487f..a21adcf8ec 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java @@ -47,6 +47,9 @@ public interface RepositoryUtils { "having count(*) > 1 " + ")"; + String UPDATE_NULL_VISIT_PRE_PROCESSED_JSON_SQL= "UPDATE visits SET pre_processed = visit_json " + + "WHERE pre_processed IS NULL AND processed = 0"; + static void addDetailsColumnToFamilySearchTable(SQLiteDatabase db) { try { diff --git a/opensrp-chw/src/nigeria/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/nigeria/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index 1b275cf098..c6cdbbe663 100644 --- a/opensrp-chw/src/nigeria/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/nigeria/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -64,6 +64,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 15: upgradeToVersion15(db); break; + case 16: + upgradeToVersion16(db); + break; default: break; } @@ -71,25 +74,6 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, } } - private static void upgradeToVersion15(SQLiteDatabase db) { - try { - // add new column - db.execSQL("ALTER TABLE ec_family_member ADD COLUMN marital_status VARCHAR;"); - } catch (Exception e) { - Timber.e(e, "upgradeToVersion15"); - } - } - - private static void upgradeToVersion14(SQLiteDatabase db) { - try { - // form configuration - ClientFormRepository.createTable(db); - ManifestRepository.createTable(db); - } catch (Exception e) { - Timber.e(e, "upgradeToVersion14"); - } - } - private static void upgradeToVersion2(SQLiteDatabase db) { try { @@ -172,6 +156,29 @@ private static void upgradeToVersion8(SQLiteDatabase db) { } } + private static void upgradeToVersion10(SQLiteDatabase db, int oldDbVersion) { + try { + ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance(); + if (oldDbVersion == 9) { + reportingLibraryInstance.truncateIndicatorDefinitionTables(db); + } + initializeIndicatorDefinitions(reportingLibraryInstance, db); + } catch (Exception e) { + Timber.e(e); + } + } + + private static void upgradeToVersion11(Context context, SQLiteDatabase db) { + try { + db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL); + db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL_INDEX); + + IMDatabaseUtils.accessAssetsAndFillDataBaseForVaccineTypes(context, db); + } catch (Exception e) { + Timber.e(e); + } + } + private static void upgradeToVersion12(SQLiteDatabase db) { try { db.execSQL(VisitRepository.ADD_VISIT_GROUP_COLUMN); @@ -190,26 +197,30 @@ private static void upgradeToVersion13(SQLiteDatabase db) { } } - private static void upgradeToVersion10(SQLiteDatabase db, int oldDbVersion) { + private static void upgradeToVersion14(SQLiteDatabase db) { try { - ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance(); - if (oldDbVersion == 9) { - reportingLibraryInstance.truncateIndicatorDefinitionTables(db); - } - initializeIndicatorDefinitions(reportingLibraryInstance, db); + // form configuration + ClientFormRepository.createTable(db); + ManifestRepository.createTable(db); } catch (Exception e) { - Timber.e(e); + Timber.e(e, "upgradeToVersion14"); } } - private static void upgradeToVersion11(Context context, SQLiteDatabase db) { + private static void upgradeToVersion15(SQLiteDatabase db) { try { - db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL); - db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL_INDEX); + // add new column + db.execSQL("ALTER TABLE ec_family_member ADD COLUMN marital_status VARCHAR;"); + } catch (Exception e) { + Timber.e(e, "upgradeToVersion15"); + } + } - IMDatabaseUtils.accessAssetsAndFillDataBaseForVaccineTypes(context, db); + private static void upgradeToVersion16(SQLiteDatabase db) { + try { + db.execSQL(RepositoryUtils.UPDATE_NULL_VISIT_PRE_PROCESSED_JSON_SQL); } catch (Exception e) { - Timber.e(e); + Timber.e(e, "Error upgrading to Version16"); } }