How to force drop room database if version number was unchanged and migration was unsuccessful

21 Views Asked by At

My app has local cache, stored in Room database, and data integrity isn't a priority to me at all, but what is the issue is a need to manually change version number each time, and it's hella annoying, especially during active development phase.

What I want — is simply delete a database and recreate it from scratch without worrying.

1

There are 1 best solutions below

0
Osanosa On

My solution to this is creating an uncaught exception handler in the onCreate block and deleting database.

        Thread.setDefaultUncaughtExceptionHandler {  throwable ->
        if (throwable is IllegalStateException) {
            this.deleteDatabase("database-name.db")
        }
    }