Skip to content

Commit

Permalink
updated the migrations
Browse files Browse the repository at this point in the history
See issue #181
  • Loading branch information
junaidwarsivd committed Nov 19, 2021
1 parent ca33942 commit 2947b79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
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;

Expand Down Expand Up @@ -83,6 +85,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 +203,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) {
Log.e(TAG,"upgradeToVersion6" + Log.getStackTraceString(e));
}
}

}

0 comments on commit 2947b79

Please sign in to comment.