Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right way to update data schema #535

Open
bokolob opened this issue Feb 5, 2024 · 0 comments
Open

Right way to update data schema #535

bokolob opened this issue Feb 5, 2024 · 0 comments

Comments

@bokolob
Copy link

bokolob commented 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant