Right way to update data schema

Author: bokolobCreated Feb 5, 2024Updated Feb 5, 2024

Hello. I do it in this way

    if (!doc.content.trip_settings || doc.content.trip_settings.version < 2) {
       let migration = Automerge.change(Automerge.clone(this.doc, { actorId: "0002" }), { time: 1 }, (doc) => {
           doc.content.events = {};
           doc.content.trip_settings = {
                name: this.text_node(db_record.name),
               version: 2,
       };
     });
   
     let [new_doc, patch] = Automerge.applyChanges(this.doc, [migration]);
     this.doc = new_doc; 
  }

As you can see - all migrations are different, because they set different name, so I can't prepare a blob.

After this migration was written I have some glitches, which I can't debug (Not sure that it's because of migration). E.g. sometimes last version of document becomes empty. And sometimes applying that migration again can return data back.

Is my code correct? Don't I forget something?

Source: automerge/automerge-classic