Skip to content

Adding an "extras" column to transport databases #578

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

Merged
merged 12 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -92,7 +92,8 @@ final class SchemaManager extends SQLiteOpenHelper {
db.execSQL("DROP INDEX contexts_backend_priority");
};

static final List<Migration> INCREMENTAL_MIGRATIONS = Arrays.asList(MIGRATE_TO_V1, MIGRATE_TO_V2);
private static final List<Migration> INCREMENTAL_MIGRATIONS =
Arrays.asList(MIGRATE_TO_V1, MIGRATE_TO_V2);

@Inject
SchemaManager(Context context, @Named("SCHEMA_VERSION") int schemaVersion) {
Expand Down Expand Up @@ -148,7 +149,7 @@ public void onOpen(SQLiteDatabase db) {

private void upgrade(SQLiteDatabase db, int fromVersion, int toVersion) {
if (toVersion > INCREMENTAL_MIGRATIONS.size()) {
throw new RuntimeException(
throw new IllegalArgumentException(
"Migration from "
+ fromVersion
+ " to "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.android.datatransport.runtime.time.TestClock;
import com.google.android.datatransport.runtime.time.UptimeClock;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -131,13 +132,17 @@ public void downgradeV2ToV1_withNonEmptyDB_isLossy() {
assertThat(store.loadBatch(CONTEXT1)).doesNotContain(event1);
}

@Test(expected = RuntimeException.class)
@Test
public void upgrade_toANonExistentVersion_fails() {
int oldVersion = 1;
int nonExistentVersion = 1000;
SchemaManager schemaManager = new SchemaManager(RuntimeEnvironment.application, oldVersion);

schemaManager.onUpgrade(schemaManager.getWritableDatabase(), oldVersion, nonExistentVersion);
Assert.assertThrows(
RuntimeException.class,
() ->
schemaManager.onUpgrade(
schemaManager.getWritableDatabase(), oldVersion, nonExistentVersion));
}

private PersistedEvent simulatedPersistOnV1Database(
Expand Down