Skip to content

Right way to update data schema #535

@bokolob

Description

@bokolob

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions