Skip to content

Commit

Permalink
Added migration for the resources db. (#1943)
Browse files Browse the repository at this point in the history
* Added migration for the db.

* Added migration for the db.

* Review comment: Added parameter name

* Review comments : Updated the migration test
  • Loading branch information
aditya-07 committed Apr 4, 2023
1 parent 81246b1 commit f44f7cd
Show file tree
Hide file tree
Showing 9 changed files with 2,031 additions and 3 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ object Dependencies {
const val compiler = "androidx.room:room-compiler:${Versions.Androidx.room}"
const val ktx = "androidx.room:room-ktx:${Versions.Androidx.room}"
const val runtime = "androidx.room:room-runtime:${Versions.Androidx.room}"
const val testing = "androidx.room:room-testing:${Versions.Androidx.room}"
}

object Mlkit {
Expand Down
29 changes: 29 additions & 0 deletions buildSrc/src/main/kotlin/RoomSchemaArgProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.io.File
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.process.CommandLineArgumentProvider

// https://developer.android.com/training/data-storage/room/migrating-db-versions#test
class RoomSchemaArgProvider(
@get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) val schemaDir: File
) : CommandLineArgumentProvider {

override fun asArguments() = listOf("-Aroom.schemaLocation=${schemaDir.path}")
}
12 changes: 11 additions & 1 deletion engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ android {
testInstrumentationRunner = Dependencies.androidJunitRunner
// need to specify this to prevent junit runner from going deep into our dependencies
testInstrumentationRunnerArguments["package"] = "com.google.android.fhir"

javaCompileOptions {
annotationProcessorOptions {
compilerArgumentProviders(RoomSchemaArgProvider(File(projectDir, "schemas")))
}
}
}

sourceSets {
getByName("androidTest").apply { resources.setSrcDirs(listOf("test-data")) }
getByName("androidTest").apply {
resources.setSrcDirs(listOf("test-data"))
assets.srcDirs("$projectDir/schemas")
}

getByName("test").apply { resources.setSrcDirs(listOf("test-data")) }
}
Expand Down Expand Up @@ -88,6 +97,7 @@ dependencies {
androidTestImplementation(Dependencies.AndroidxTest.extJunitKtx)
androidTestImplementation(Dependencies.AndroidxTest.runner)
androidTestImplementation(Dependencies.AndroidxTest.workTestingRuntimeKtx)
androidTestImplementation(Dependencies.Room.testing)
androidTestImplementation(Dependencies.junit)
androidTestImplementation(Dependencies.truth)

Expand Down

0 comments on commit f44f7cd

Please sign in to comment.