The @CeAutoMigration annotation is used to define automatic migrations in the database. It reduces manual coding and keeps migrations well-structured.

Syntax:

CeAutoMigration(from = 1, to = 2)
class MyMigration

Parameters:

Example with 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()

Features:

✅ 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.