androidandroid-roomandroid-room-prepackageddatabase

update pre-packaged database


I have a SQLite file downloaded from the server with all static data a round the application. I used it to fill the room data base.

With Room 2.1.0, I used to copy the file to databases directory and it was working fine when update the SQLite file schema (adding new columns) on the versions with old Entities.

Now with Room 2.4.0, If the SQLite file schema changed It throws exception
IllegalStateException("Pre-packaged database has an invalid schema:").

Is there anyway to skip schema Validation ?


Solution

  • Is there anyway to skip schema Validation ?

    No. The schema in the pre-packaged database must meet the expectations of the schema that Room builds from the Entities OR you can use the prePackagedDatabaseCallback to modify the copied pre-packaged database to meet the expectations.

    Here's an example of using the callback where you use the SQL copied from the generated java.

    However, it is suggested that always alter the pre-packaged database using whatever tool you utilise to match the schema as per the generated java rather than use the callback.