Summary
I'm pre-populating a database with createFromAsset() It works, now I need to add indices to the DB, however Room is not able to handle this change.
Quik note
This db is not in production, I re-installed the app after making the changes, my issue is not the common problem on how to migrate from version X to Y.
Code
This is my entity
@Entity(tableName = "myTable", indices = [Index(value = ["col1","col2"], name = "myIndex")])
...
I ran the following query to also add the indice to the pre-populated DB
CREATE INDEX myIndex ON myTable (col1,col2)
After these changes were made I re-installed the app to avoid db version issues.
The problem is that Room always fails to verify the data integrity, incrementing the version is not an option, it does fix the problem if (and only if) I install version 1 first and then increment the version.
The migration must also be empty for it to work, executing the following query fails because myIndex already exists:
db.execSQL("CREATE INDEX myIndex ON myTable (col1,col2)")
What I tried
- Running the query locally in
onCreatefunction fromRoomDatabase.Callback()instead of importing it directly from assets.
Wondering...
I can't seem to understand why Room complains about the indice, it refuses to add it because it already exists, running an empty migration fixes the problem, not running any migration gives me a verification exception.
The thing is that I can't run an empty migration just to fix it because the migration won't run at all since this DB is not in prod yet.
I feel lost.