The DatabaseVersion
annotation is used to specify the current version of the database. It is placed above the MainActivity
or any relevant class to indicate the version of the database schema being used in the application. This helps to manage database migrations and ensure that the application is working with the correct version of the database.
version: Int
Defines the version number of the database schema. This is essential for handling database migrations. Each time the database structure is changed (e.g., adding new tables or modifying existing ones), the version number should be updated. The system can use this version to determine which migrations need to be applied.kotlin
КопіюватиРедагувати
@DatabaseVersion(version = 2)
class MainActivity : AppCompatActivity() {
// MainActivity implementation
}
In the example above, the DatabaseVersion
annotation is applied to the MainActivity
class, and it specifies that the database schema version is 2
. This helps ensure that the app handles the appropriate migrations based on the specified version.
This annotation simplifies the management of database schema versions and migration processes, especially when there are multiple versions of the app with different database structures.