How do you guys migrate sql columns which contain json? (where that json changed)
02/03/2021, 9:44 AM
i would say you can migrate it normally like it was a normal string. When you use the proper converter later the value will be changed
02/03/2021, 3:45 PM
but that means you need to keep the previous moshi models in order to read it
02/03/2021, 6:07 PM
Well if you are removing fields from that json, then the new model would just omit those fields and ignore them, no harm no foul, and the new/updated JSON that gets inserted later on into your table just wouldn't contain those fields.
If you add new fields, you could specify default values or mark the new field as nullable, which would safely handle converting old json stored in your table that doesn't contain the new json fields.
If you wanted to migrate the value of a field that is present in the old model and in the new model, simplify load the record, modify the field in the json string, reinsert the record.
Hope I understood your question and this was helpful..
I had to do something like this, I used Moshi in this particular project btw for serializing to/from the JSON that I was storing in the table
02/04/2021, 4:50 AM
Yes thats my plan b, but id like for the model to not collect nullable and default values just for purposes of migration, then they are there for ever 😔