Я создал миграцию от 1 до 2 версии моей базы данных.
У меня есть приложение в нескольких модулях, таких как:
- Приложение
- данные
- 1010 домен * *
Я попытался добавить это в build.gradle приложения и модулей данных:
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
Вот мой класс MigrationTest:
@RunWith(AndroidJUnit4.class)
public class MigrationTest {
private static final String TEST_DB = "migration-test";
@Rule public MigrationTestHelper helper;
private Profile profile;
public MigrationTest() {
helper = new MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
AppDatabase.class.getCanonicalName(),
new FrameworkSQLiteOpenHelperFactory());
}
@Before
public void setUp(){
profile = createProfile();
}
@Test public void migrate1To2() throws IOException {
SupportSQLiteDatabase db = helper.createDatabase(TEST_DB, 1);
insertProfile(db);
db.close();
AppDatabase database = (AppDatabase) helper.runMigrationsAndValidate(TEST_DB, 2, true, MIGRATION_1_2);
Single<ProfileData> profileDataSingle = database.profileDao().getById("userId");
ProfileData profileData = profileDataSingle.blockingGet();
Profile currentProfile = ProfileMapper.transform(profileData);
assertEquals(currentProfile.getUserId(), profile.getUserId());
}
Здесь не пройден тест:
java.io.FileNotFoundException: не удается найти файл схемы в
папка активов. Не забудьте включить экспортированные схемы JSON в ваш
проверить ввод данных. Увидеть
https://developer.android.com/topic/libraries/architecture/room.html#db-migration-testing
для деталей. Отсутствующий файл: org.app.app.data.sql.AppDatabase / 1.json