8

What is the best practice for migrating table when a member of a struct is added? For some structs, I have had no problems adding members, but for others I have. I get this error message:

$cleos get table <account> <contract> <table>
2628662ms thread-0   main.cpp:2552                 main                 ] Failed with error: Out of Range (8)
read datastream of length 16 over by 1
error unpacking uint32_t

This occurred after I added a uint32_t member to the table struct. Is there a way to configure the migration to the new table so that I don't have start over? I would want to default the value to zero or some other value.

5

When making structural changes to tables there are 2 basic approaches:

  1. add versioning in the data from day 1 and then support old versions of the data well enough to do "just in time" upgrades.

  2. deploy a migration contract in-between version N and N+1 which can read the data and convert it, OR ingests transactions with data converted in an out-of-chain process; then issue the setcode with the N+1 code

Both of these require some pre-planning (like the ability to put your contract into a maintenance mode for user feedback)

0

Binary_extension is a good choice when you need to add new fields in the table struct. But you should not remove fields in the middle of field-list in which case it could not retrieve table.

Actually this one is newer:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.