안드로이드 자동 마이그래이션

By | 2024년 12월 6일
Table of Contents

안드로이드 자동 마이그래이션

AutoMigration 을 추가해 주면 컬럼 추가정도는 지원해 준다.

// Database class before the version update.
@Database(
  version = 1,
  entities = {User.class}
)
public abstract class AppDatabase extends RoomDatabase {
  ...
}

// Database class after the version update.
@Database(
  version = 2,
  entities = {User.class},
  autoMigrations = {
    @AutoMigration (from = 1, to = 2,
                        spec = AppDatabase.MyAutoMigration.class)
  }
)
public abstract class AppDatabase extends RoomDatabase {
  ...
    // @RenameTable(fromTableName = "User", toTableName = "AppUser")
    static class MyAutoMigration implements AutoMigrationSpec { }
}

아래의 내용이 필요한지 아닌지는 좀 애매하다.

android {
    defaultConfig {

        javaCompileOptions {
            annotationProcessorOptions {
                arguments += [
                        "room.schemaLocation": "$projectDir/schemas".toString(),
                        "room.incremental": "true"
                ]
            }
        }
    }
}

답글 남기기