Skip to content

Commit

Permalink
Add DB migration scripts for the outreach column #181 (#182)
Browse files Browse the repository at this point in the history
* updated the migrations
See issue #181

* version updated

* snapshot version upgraded

* snapshot version upgraded

* added timber for logs
  • Loading branch information
junaidwarsivd authored Nov 22, 2021
1 parent 4ff6acf commit a6722e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=4.0.1-SNAPSHOT
VERSION_CODE=2
VERSION_NAME=4.0.2-SNAPSHOT
VERSION_CODE=3
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
POM_SETTING_URL=https://github.com/OpenSRP/opensrp-client-immunization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class VaccineRepository extends BaseRepository {
public static final String UPDATE_TABLE_ADD_TEAM_COL = "ALTER TABLE " + VACCINE_TABLE_NAME + " ADD COLUMN " + TEAM + " VARCHAR;";
public static final String UPDATE_TABLE_ADD_TEAM_ID_COL = "ALTER TABLE " + VACCINE_TABLE_NAME + " ADD COLUMN " + TEAM_ID + " VARCHAR;";
public static final String UPDATE_TABLE_ADD_CHILD_LOCATION_ID_COL = "ALTER TABLE " + VACCINE_TABLE_NAME + " ADD COLUMN " + CHILD_LOCATION_ID + " VARCHAR;";
public static final String UPDATE_TABLE_VACCINES_ADD_OUTREACH_COL = "ALTER TABLE "+ VACCINE_TABLE_NAME + " ADD COLUMN "+ OUTREACH + " INTEGER DEFAULT 0;";
public static final String UPDATE_OUTREACH_QUERRY = "UPDATE "+ VACCINE_TABLE_NAME+" SET " + OUTREACH + " = 1 WHERE location_id != ?;";
private static final String TAG = VaccineRepository.class.getCanonicalName();
private static final String VACCINE_SQL = "CREATE TABLE vaccines (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,base_entity_id VARCHAR NOT NULL,program_client_id VARCHAR NULL,name VARCHAR NOT NULL,calculation INTEGER,date DATETIME NOT NULL,anmid VARCHAR NULL,location_id VARCHAR NULL,sync_status VARCHAR, updated_at INTEGER NULL, UNIQUE(base_entity_id, program_client_id, name) ON CONFLICT IGNORE)";
private static final String BASE_ENTITY_ID_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + BASE_ENTITY_ID + "_index ON " + VACCINE_TABLE_NAME + "(" + BASE_ENTITY_ID + " COLLATE NOCASE);";
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "DATABASE_VERSION", '5'
buildConfigField "int", "DATABASE_VERSION", '6'
}

debug {
buildConfigField "int", "DATABASE_VERSION", '5'
buildConfigField "int", "DATABASE_VERSION", '6'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
import org.smartregister.immunization.repository.VaccineRepository;
import org.smartregister.immunization.repository.VaccineTypeRepository;
import org.smartregister.immunization.sample.BuildConfig;
import org.smartregister.immunization.sample.application.SampleApplication;
import org.smartregister.immunization.util.IMDatabaseUtils;
import org.smartregister.repository.AlertRepository;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.repository.Repository;

import timber.log.Timber;

/**
* Created by keyman on 01/08/2017.
*/
Expand Down Expand Up @@ -83,6 +87,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
case 5:
upgradeToVersion5(db);
break;
case 6:
upgradeToVersion6(db);
default:
break;
}
Expand Down Expand Up @@ -199,4 +205,17 @@ private void upgradeToVersion5(SQLiteDatabase db) {
}
}

private void upgradeToVersion6(SQLiteDatabase db)
{
try{
AllSharedPreferences sharedPreferences = SampleApplication.getInstance().context().userService()
.getAllSharedPreferences();
db.execSQL(VaccineRepository.UPDATE_TABLE_VACCINES_ADD_OUTREACH_COL);
db.execSQL(VaccineRepository.UPDATE_OUTREACH_QUERRY, new String[]{sharedPreferences.fetchDefaultLocalityId(sharedPreferences.fetchPioneerUser())});

} catch (Exception e) {
Timber.e(TAG,"upgradeToVersion6" + Log.getStackTraceString(e));
}
}

}

0 comments on commit a6722e8

Please sign in to comment.