The @CeAutoMigration
annotation is used to define automatic migrations in the database. It reduces manual coding and keeps migrations well-structured.
CeAutoMigration(from = 1, to = 2)
class MyMigration
from: Int
— the database version from which the migration starts.to: Int
— the database version to which the migration applies.useSpec: Boolean
(optional, default false
) — if true
, the spec
field is added, referring to the class where the annotation is applied.useSpec
:When useSpec = true
, the generated @Database
will include a spec
reference to the annotated class:
@CeAutoMigration(from = 2, to = 3, useSpec = true)
class MyExampleAutoMigration
Generated @Database
annotation:
@Database(
entities = [MyEntity::class],
version = 3,
autoMigrations = [
AutoMigration(from = 2, to = 3, spec = MyExampleAutoMigration::class)
]
)
abstract class AppDatabase : RoomDatabase()
✅ Automatically adds migrations to @Database
.
✅ Sorts migrations by version numbers.
✅ Supports spec
when required.
✅ Removes unnecessary commas.
This functionality simplifies database version management and eliminates the need to manually define autoMigrations
in @Database
.