hive icon indicating copy to clipboard operation
hive copied to clipboard

I screwed up, is there anything I can do?

Open danielRi opened this issue 9 months ago • 5 comments

Hi,

I shipped an update of my app with changes to my Hive objects that are not compatible with my users old local data (e.G. changed data type, changed data structure etc..). Some users havent updated in months and Im not sure what old data they have. Now my users getting app crashes because their old data conflicts with the new data objects of the app update. I have to tell affected users to delete their app cache/ app data or the app is bricked, which is an awful experience.

Is there a general approach how can make sure the old data is not used anymore, like increasing data base version or a onMigrate: function? I could not find anything like that in the docs.

Edit:

To make myself more clear Im getting

HiveError: Box not found. Did you forget to call Hive.openBox()

in crashlytics from users on release side but I cannot reproduce the errors.

Thanks a lot!

danielRi avatar Feb 17 '25 11:02 danielRi

Sorry to hear. When I faced a similar thing,I implemented a 'clean up' job that runs once on app update. Run it after initializing Hive, and make sure old data is removed or migrated: Hive.deleteFromDisk() should do the trick on the boxes that need cleaning

lisovyk avatar Mar 12 '25 19:03 lisovyk

You can push a new update that does the migration.

iambenkay avatar Mar 12 '25 23:03 iambenkay

Hey, thanks for the input. I ended up changing the names of all my boxes, so the old data will not be requested by the old boxes. Kind of hacky but I think it worked. Just out of curiousity: Are there plans to bring back something like a onMigrate function, and the versioning of boxes?

danielRi avatar Mar 14 '25 06:03 danielRi

I don't think there are plans for that.

But how I currently do it.

At initialization I check if the old box exists and do the migration at startup. Then I delete the old box after migrating. Subsequently that piece of code won't be run anymore since the old box is gone from that device

iambenkay avatar Mar 14 '25 06:03 iambenkay

@danielRi Last changes to the repo were made 2 years ago – Hive is not in active development, developer went on to work on isar as far as I know. So no updates are coming, maybe some critical bugfixes and that's it.

lisovyk avatar Mar 14 '25 17:03 lisovyk