What is the best way to handle database alteration in a No-SQL DB like Hive for Flutter?

430

This seems like General No-SQL database usage regardless of the Flutter context.

Using No-SQL database means that they don't tend to have a migration protocol since its focus is to read and write with great speed and efficiency.

Most of the time when dealing with No-SQL databases the whole structure of your data exist within your code and not in the database. This is totally opposite to SQL databases.

Hive has a way to handle this changes in classes https://docs.hivedb.dev/#/custom-objects/generate_adapter?id=updating-a-class even then bear in mind that the documentation says that if you change the field number you will lose your structure.

Still regardless of Flutter you need to bear in mind that when working with No-SQL database regardless of the coding language, in order to go from this:

box.put('schema', {'foo': true, 'bar' : 2, 'baz': 'baz'});

to this:

box.put('schema', {'f00': true, 'b@r' : 2, 'baz': 'baz'});

And still support both. You will need to write code that supports both entries at the same time indefinitely, also everytime you read the old format you will have to decide if leaving it like that and give support to both or change the old format to the new format.

Also notice that the change from the old format to the new one should be done as they are read when used.

Because to change all entries at once you will have to read and rewrite all of the entries in the database and this will be too inefficient.

Since in No-SQL each individual entry (file,document,.json) doesn't have a strict format meaning they can store literally anything in anyway you see fit even if the belong to the same storage/table. And things like changing the column name in the table like you would do in SQL do not exist in this type of databases.

Share:
430
Nico Rodsevich
Author by

Nico Rodsevich

Love programming and nice border-edge techs

Updated on December 27, 2022

Comments

  • Nico Rodsevich
    Nico Rodsevich over 1 year

    Suppose you launch an App with the following DB schema with Hive:

    box.put('schema', {'foo': true, 'bar' : 2, 'baz': 'baz'});
    

    Some time after you launch a new version of the app and suppose the schema changes the names as follows:

    box.put('schema', {'f00': true, 'b@r' : 2, 'baz': 'baz'});
    

    What is the best approach to take with the already existing DBs of your clients?