Skip to content

Commit

Permalink
Merge pull request #2815 from dimagi/copy-connect-database-upgrades
Browse files Browse the repository at this point in the history
Copy CCC Global database changes - Version 6
  • Loading branch information
avazirna authored Aug 19, 2024
2 parents 2ee691a + 25d10de commit 1d2f00b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.commcare.android.database.global.models;

import org.commcare.android.storage.framework.Persisted;
import org.commcare.models.framework.Persisting;
import org.commcare.modern.database.Table;

@Table(ConnectKeyRecord.STORAGE_KEY)
public class ConnectKeyRecord extends Persisted {
public static final String STORAGE_KEY = "connect_key";

@Persisting(1)
String userId;
@Persisting(2)
String encryptedPassphrase;

public ConnectKeyRecord() { }
public ConnectKeyRecord(String userId, String encryptedPassphrase) {
this.userId = userId;
this.encryptedPassphrase = encryptedPassphrase;
}

public String getUserID() { return userId; }
public String getEncryptedPassphrase() { return encryptedPassphrase; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.commcare.android.database.global.models.AndroidSharedKeyRecord;
import org.commcare.android.database.global.models.AppAvailableToInstall;
import org.commcare.android.database.global.models.ApplicationRecord;
import org.commcare.android.database.global.models.ConnectKeyRecord;
import org.commcare.android.javarosa.AndroidLogEntry;
import org.commcare.android.logging.ForceCloseLogEntry;
import org.commcare.logging.DataChangeLog;
Expand All @@ -32,8 +33,9 @@ public class DatabaseGlobalOpenHelper extends SQLiteOpenHelper {
* and InstanceProvider use per-app databases
* V.4 - Add table for storing force close log entries that occur outside of an active session
* V.5 - Add table for storing apps available for install
* V.6 - Add table for storing (encrypted) passphrase for ConnectId DB
*/
private static final int GLOBAL_DB_VERSION = 5;
private static final int GLOBAL_DB_VERSION = 6;

private static final String GLOBAL_DB_LOCATOR = "database_global";

Expand Down Expand Up @@ -66,6 +68,10 @@ public void onCreate(SQLiteDatabase database) {
builder.addData(new AppAvailableToInstall());
database.execSQL(builder.getTableCreateString());

builder = new TableBuilder(ConnectKeyRecord.STORAGE_KEY);
builder.addData(new ConnectKeyRecord());
database.execSQL(builder.getTableCreateString());

DbUtil.createNumbersTable(database);

database.setVersion(GLOBAL_DB_VERSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.commcare.CommCareApplication;
import org.commcare.android.database.global.models.AppAvailableToInstall;
import org.commcare.android.database.global.models.ConnectKeyRecord;
import org.commcare.android.logging.ForceCloseLogEntry;
import org.commcare.modern.database.TableBuilder;
import org.commcare.models.database.ConcreteAndroidDbHelper;
Expand Down Expand Up @@ -50,6 +51,11 @@ public void upgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
oldVersion = 5;
}
}
if (oldVersion == 5) {
if (upgradeFiveSix(db)) {
oldVersion = 6;
}
}
}

private boolean upgradeOneTwo(SQLiteDatabase db, int oldVersion, int newVersion) {
Expand Down Expand Up @@ -117,6 +123,10 @@ private boolean upgradeFourFive(SQLiteDatabase db) {
return addTableForNewModel(db, AppAvailableToInstall.STORAGE_KEY, new AppAvailableToInstall());
}

private boolean upgradeFiveSix(SQLiteDatabase db) {
return addTableForNewModel(db, ConnectKeyRecord.STORAGE_KEY, new ConnectKeyRecord());
}

private static boolean addTableForNewModel(SQLiteDatabase db, String storageKey,
Persistable modelToAdd) {
db.beginTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public class FormStorageTest {
, "org.commcare.suite.model.EndpointArgument"
, "org.commcare.suite.model.EndpointAction"
, "org.commcare.suite.model.QueryGroup"
, "org.commcare.android.database.global.models.ConnectKeyRecord"
);


Expand Down

0 comments on commit 1d2f00b

Please sign in to comment.