How to protect sqflite database when updating flutter app

292

flutter install deletes app and database. The solution is to use streamed install. Instead of flutter install, run this: adb install build/app/outputs/flutter-apk/app.apk. This will update the app and leave the database intact.

You must have sdk platform-tools installed and an environment variable pointing to the platform-tools.

Share:
292
Thomas Schulz
Author by

Thomas Schulz

Updated on December 26, 2022

Comments

  • Thomas Schulz
    Thomas Schulz over 1 year

    I use an sqflite database in my app. The database is filled with entries by the users. It is essential that the database is unchanged when I deliver a new app version.

    When I deploy a new version of the app as apk to my real phone the database is deleted. Is there a way to protect the database during update?

    I wonder if it is the method how I deploy the new app version? I use "flutter install". Maybe the uninstall method removes everything from the app including the database and creates a fresh app directory!?

    • dm_tr
      dm_tr over 3 years
      Are you uninstalling the previous version when installing the new one ?
    • Thomas Schulz
      Thomas Schulz over 3 years
      No (not that I know of). I presumed the database would not be touched when I deliver a new app version.
    • Martyns
      Martyns over 3 years
      are you passing a version to the the openDatabase method? You should pass a version number and update it every time you create new tables or update existing ones. github.com/tekartik/sqflite/blob/master/sqflite/doc/…
    • Thomas Schulz
      Thomas Schulz over 3 years
      I make no changes to the database. It is the app that is updated. When opening it checks if there is an existing database and opens it. But obviouly the database is deleted during the update process via "flutter install"
    • Thomas Schulz
      Thomas Schulz over 3 years
      I found that I can preserve the database via system backup. I forced a system backup. Afterwards the database was restored during the update process.
  • Thomas Schulz
    Thomas Schulz over 3 years
    Thanks for your suggestion. I wonder why I should have to do this. Preserving a database during app update should be quite normal. As it is when delivering using debug mode.