Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy CCC Global database changes - Version 6 #2815

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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