Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change indices in a room migration?

The old Entity as below:

@Entity(tableName = "d_course",
    foreignKeys = @ForeignKey(entity = DUser.class, parentColumns = "id", childColumns = "studio"),
    indices = @Index(value = "studio"))

The new Entity as below:

@Entity(tableName = "d_course",
    foreignKeys = @ForeignKey(entity = DUser.class, parentColumns = "id", childColumns = "studio"),
    indices = @Index(value = {"id", "studio"}))

How do I migrate this indices change.

like image 257
boybeak Avatar asked Jan 02 '23 19:01

boybeak


1 Answers

Try to specify this index changes in migration, for example (Kotlin):

val MIGRATION_1_2 = object : Migration(1, 2) {
    override fun migrate(database : SupportSQLiteDatabase) {
        ...
        database.execSQL("CREATE INDEX index_d_course_id_studio ON  d_course(id, studio)")
    }
}
like image 162
Oleh Avatar answered Jan 05 '23 18:01

Oleh