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.
The @CeDatabaseVersion
annotation is used to specify the current version of the database schema. It is typically placed above a main or configuration class in the application to indicate the schema version in use. This annotation helps to manage database migrations and ensures that the application works with the correct database structure version.
version: Int
Specifies the version number of the database schema.
Each time the database structure changes (e.g., adding or modifying tables), this version number must be incremented.
The system uses this version to determine which migrations need to be applied.
kotlin
КопироватьРедактировать
@CeDatabaseVersion(version = 2)
class MainActivity : AppCompatActivity() {
// MainActivity implementation
}
Using this annotation simplifies the management of database schema versions and migration processes, especially when multiple app versions with different database schemas are maintained.