Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 412
clamentjohn Avatar asked Jul 26 '21 13:07

clamentjohn


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

like image 122
clamentjohn Avatar answered Sep 22 '22 08:09

clamentjohn


Kotlin is now supports repeatable annotations in version 1.6

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

like image 32
Hussien Fahmy Avatar answered Sep 22 '22 08:09

Hussien Fahmy