Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter delete Hive Database on Update

I have a Flutter app and I am using Hive to store data.

I have deleted some adapters which were used previously. This caused an error and I have to delete the old database.

Now, if I roll out an update, how do I make sure the old Hive database gets deleted when the user updates the app so that it causes no issues.

like image 817
Raghav Aggiwal Avatar asked May 26 '26 04:05

Raghav Aggiwal


1 Answers

Instead of deleting, run a database migration.

Hive.box("myBox", version: 5, migrator: (oldVersion, newVersion, box) async {
  await box.delete("unusedKey");
  await box.put("newKey", 7);
});

If you want to delete it anyway,

  • Read the app version, package_info may come in handy for that.
  • Delete the old db if this app version/build is running for the first time after installing/updating.
like image 146
shb Avatar answered May 27 '26 23:05

shb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!