Home > Mobile >  Android Room where is DB version stored?
Android Room where is DB version stored?

Time:09-20

Refering to: enter image description here

Or is a new version only valid if the schema changes? How would I then trigger a migration if I e.g. just added some more entries to my database (e.g. by adding a new product)?

Simply updating the version number in the @Database annotation is all that is required to initiate a Migration, a schema change itself does not trigger the Migration.

Rather a schema change will be recognised as Room generates a hash of the schema as part of the code. This hash is compared against a hash that is stored in the database in the table room_master. The hashes mismatch them Room sees a change and will then expect that a Migration is provided, if not then an exception is raised and the App crashes.

The Migration can do nothing if required.

AutoMigrations are similar except that the Migration code is generated automatically, although it needs in the circumstances of an ambiguity (e.g. a column rename) to be provided with additional information via migration specs.

Obviously you cannot use a manual and an AutoMigration together.

  • Related