The DatabaseMigration
annotation is used to mark manually created database migrations. When this annotation is applied to a class, it ensures that the migration is automatically included as a dependency for the database, making it part of the migration process.
version: Int
Specifies the database version for which this migration applies. Each manual migration should be assigned a version number that corresponds to a database update. This helps the system recognize and apply the migration correctly when updating the database schema.kotlin
@DatabaseMigration(version = 3)
class AddNewFieldsMigration {
// Migration logic for version 3
}
In this example, the AddNewFieldsMigration
class represents a manual migration for version 3 of the database. When the system detects this annotation, it automatically registers the migration as part of the database update process.
✅ Ensures manual migrations are automatically recognized and applied.
✅ Provides better version control for database schema updates.
✅ Allows flexible migration management by specifying the exact version.
By using DatabaseMigration
, developers can integrate custom migrations seamlessly while maintaining database version consistency.