eos icon indicating copy to clipboard operation
eos copied to clipboard

How to add a table entry field in multi_index without deleting node data

Open yhc166188 opened this issue 8 years ago • 1 comments

I want to save the additional data information of the user. I know I will put it into the database, for example, resource_limits_index. This will generate content of memory does not match data expected by executable.How can you avoid this without deleting the original node data?

yhc166188 avatar Sep 18 '18 11:09 yhc166188

You must create the new version of your multi_index alongside the old and transfer data from the old to the new. You may do so as part of your normal access pattern, first checking the new table to see if the entry you seek is present and if not, check the original table, and if it's present, migrate it while adding the data for the new field, then remove it from the original table to save RAM costs. You must retain both versions of your multi_index until you have completed this migration, at which point you may update your contract to remove the original version of your multi_index.

If you prefer less code complexity and can accept downtime for your application, you may upload a version of your contract solely for migration purposes, and run migration transactions on every row of your table until complete, then transition to a new contract using only the new version of the table.

Either way, you must write code supporting both versions of your multi_index and migrate the data yourself. There are no native provisions for adding fields to an existing multi_index.

jgiszczak avatar Sep 18 '18 23:09 jgiszczak