-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug with Room Overwriting old data
- Created MigrationsTest - Created Manual Migration from 9 to 10 - New Database has additional primary key Signed-off-by: Julius Linus <[email protected]>
- Loading branch information
1 parent
a834517
commit 857d356
Showing
11 changed files
with
135 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/androidTest/java/com/nextcloud/talk/migrations/MigrationsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Nextcloud Talk application | ||
* | ||
* @author Julius Linus | ||
* Copyright (C) 2023 Julius Linus <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.nextcloud.talk.migrations | ||
|
||
import androidx.room.Room | ||
import androidx.room.testing.MigrationTestHelper | ||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.nextcloud.talk.data.source.local.Migrations | ||
import com.nextcloud.talk.data.source.local.TalkDatabase | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.io.IOException | ||
|
||
class MigrationsTest { | ||
|
||
@get:Rule | ||
val helper: MigrationTestHelper = MigrationTestHelper( | ||
InstrumentationRegistry.getInstrumentation(), | ||
TalkDatabase::class.java.canonicalName!!, | ||
FrameworkSQLiteOpenHelperFactory() | ||
) | ||
|
||
@Test | ||
@Throws(IOException::class) | ||
fun migrateAll() { | ||
// Create earliest version of the database. | ||
helper.createDatabase(TEST_DB, 8).apply { | ||
close() | ||
} | ||
|
||
// Open latest version of the database. Room validates the schema | ||
// once all migrations execute. | ||
Room.databaseBuilder( | ||
InstrumentationRegistry.getInstrumentation().targetContext, | ||
TalkDatabase::class.java, | ||
TEST_DB | ||
).addMigrations( | ||
Migrations.MIGRATION_6_8, | ||
Migrations.MIGRATION_7_8, | ||
Migrations.MIGRATION_8_9, | ||
Migrations.MIGRATION_9_10 | ||
).build().apply { | ||
openHelper.writableDatabase.close() | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TEST_DB = "migration-test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters