How to delete/rename multiple columns with Room Auto-Migration

Viewed 839

Note: Room Auto Migration is in Beta - 2.4.0-beta02

I've deleted two columns in two different tables. And I tried repeat the @DeleteColumn annotation, like so

    @DeleteColumn(tableName = "User", columnName = "phone")
    @DeleteColumn(tableName = "Product", columnName = "description")
    @DeleteTable(tableName = "Category")
    class TestRoomAutoMigration: AutoMigrationSpec {   }

but I get this error

Repeatable annotations with non-SOURCE retention are not yet supported

Questions

  1. How delete/rename multiple columns if I can't repeat the annotation with Auto Migration
2 Answers

Kotlin has yet to add full support for repeatable annotations with the same syntax as Java. So we'll have to use the container annotation, like this:

@DeleteColumn.Entries(
    DeleteColumn(tableName = "User", columnName = "phone"),
    DeleteColumn(tableName = "Product", columnName = "description"),
)
@DeleteTable(tableName = "Category")
class TestRoomAutoMigration: AutoMigrationSpec {   }

This works for renaming columns too.

This was first answered on the Google issue tracker - link

Kotlin is now supports repeatable annotations in version 1.6

org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0

Related