Roomigrant icon indicating copy to clipboard operation
Roomigrant copied to clipboard

Testing migrations

Open reixa00 opened this issue 6 years ago • 1 comments
trafficstars

This should be more a question than an issue, don't know if theres a StackOverflow tag to ask them there, feel free to close if so.

At the moment I'm testing the migrations that I use like this:

@SmallTest
class MigrationTest {

    private val TEST_DB = "migration-test"

    @get:Rule
    var helper: MigrationTestHelper? = null

    init {
        helper = MigrationTestHelper(InstrumentationRegistry.getInstrumentation(),
                AnomalyDatabase::class.java.canonicalName, FrameworkSQLiteOpenHelperFactory())
    }

    @Test
    fun migrate57To58() {
        val db = helper?.createDatabase(TEST_DB, 57)
        db?.close()
        helper?.runMigrationsAndValidate(TEST_DB, 58, true, DBMigrations.MIGRATION_57_58)
    }
}

Is there a way to test the migrations created by the library? Maybe being created at compile time makes this task difficult.

Thanks in advance. I really think this could be a powerful tool.

reixa00 avatar Aug 26 '19 12:08 reixa00

Hey axierjhtjz,

I'm glad that you found this library useful.

In the above sample you can just iterate over migrations and test each migration in a loop? It should be pretty easy as each migration object has versions of database to migrate to/from.

Best regards.

MatrixDev avatar Aug 27 '19 10:08 MatrixDev