Skip to content

Commit bafa004

Browse files
committed
Update migration9to10 test
1 parent 61d617d commit bafa004

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

engine/schemas/com.google.android.fhir.db.impl.ResourceDatabase/10.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 10,
5-
"identityHash": "a80ce5b4e924f9b6c9776b6b3348abba",
5+
"identityHash": "10a419846e64e0b697b709d7bafbe492",
66
"entities": [
77
{
88
"tableName": "ResourceEntity",
@@ -308,16 +308,16 @@
308308
},
309309
"indices": [
310310
{
311-
"name": "index_TokenIndexEntity_index_value_resourceType_index_name_resourceUuid",
311+
"name": "index_TokenIndexEntity_resourceType_index_name_index_value_resourceUuid",
312312
"unique": false,
313313
"columnNames": [
314-
"index_value",
315314
"resourceType",
316315
"index_name",
316+
"index_value",
317317
"resourceUuid"
318318
],
319319
"orders": [],
320-
"createSql": "CREATE INDEX IF NOT EXISTS `index_TokenIndexEntity_index_value_resourceType_index_name_resourceUuid` ON `${TABLE_NAME}` (`index_value`, `resourceType`, `index_name`, `resourceUuid`)"
320+
"createSql": "CREATE INDEX IF NOT EXISTS `index_TokenIndexEntity_resourceType_index_name_index_value_resourceUuid` ON `${TABLE_NAME}` (`resourceType`, `index_name`, `index_value`, `resourceUuid`)"
321321
},
322322
{
323323
"name": "index_TokenIndexEntity_resourceUuid",
@@ -1019,7 +1019,7 @@
10191019
"views": [],
10201020
"setupQueries": [
10211021
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
1022-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'a80ce5b4e924f9b6c9776b6b3348abba')"
1022+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '10a419846e64e0b697b709d7bafbe492')"
10231023
]
10241024
}
10251025
}

engine/src/androidTest/java/com/google/android/fhir/db/impl/ResourceDatabaseMigrationTest.kt

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,55 @@ class ResourceDatabaseMigrationTest {
418418
assertThat(retrievedTask).isEqualTo(bedNetTask)
419419
}
420420

421-
@Test fun migrate9To10_should_execute_with_no_exception(): Unit = runBlocking { TODO() }
421+
@Test
422+
fun migrate9To10_should_execute_with_no_exception(): Unit = runBlocking {
423+
val patientId = "patient-001"
424+
val patientResourceUuid = "e2c79e28-ed4d-4029-a12c-108d1eb5bedb"
425+
val patient: String =
426+
Patient().apply { id = patientId }.let { iParser.encodeResourceToString(it) }
427+
428+
val taskId = "bed-net-001"
429+
val taskResourceUuid = "8593abf6-b8dd-44d7-a35f-1c8843bc2c45"
430+
val bedNetTask =
431+
Task()
432+
.apply {
433+
id = taskId
434+
status = Task.TaskStatus.READY
435+
`for` = Reference(patient)
436+
}
437+
.let { iParser.encodeResourceToString(it) }
438+
439+
helper.createDatabase(DB_NAME, 9).apply {
440+
execSQL(
441+
"INSERT INTO ResourceEntity (resourceUuid, resourceType, resourceId, serializedResource) VALUES ('$patientResourceUuid', 'Patient', '$patientId', '$patient');",
442+
)
443+
execSQL(
444+
"INSERT INTO ResourceEntity (resourceUuid, resourceType, resourceId, serializedResource) VALUES ('$taskResourceUuid', 'Task', '$taskId', '$bedNetTask');",
445+
)
446+
447+
execSQL(
448+
"INSERT INTO ReferenceIndexEntity (resourceUuid, resourceType, index_name, index_path, index_value) VALUES ('$taskResourceUuid', 'Task', 'subject', 'Task.for', 'Patient/$patientId');",
449+
)
450+
close()
451+
}
452+
val migratedDatabase = helper.runMigrationsAndValidate(DB_NAME, 10, true, Migration_9_10)
453+
val retrievedTask: String?
454+
migratedDatabase
455+
.query(
456+
"""
457+
SELECT a.serializedResource FROM ResourceEntity a
458+
WHERE a.resourceUuid IN (SELECT resourceUuid FROM ReferenceIndexEntity
459+
WHERE resourceType = 'Task' AND index_name = 'subject' AND index_value = 'Patient/$patientId')
460+
"""
461+
.trimIndent(),
462+
)
463+
.let {
464+
it.moveToFirst()
465+
retrievedTask = it.getString(0)
466+
}
467+
migratedDatabase.close()
468+
assertThat(retrievedTask).isEqualTo(bedNetTask)
469+
}
422470

423471
companion object {
424472
const val DB_NAME = "migration_tests.db"

0 commit comments

Comments
 (0)