percolatestudio/meteor-migrations

Fail to migrate a collection with an autovalue

cndys opened this issue · 1 comments

cndys commented

Error: Created by is required

the migration:

Migrations.add({
    version: 7,
    up: function() {
      Tasks.find({taskValue: 0}).forEach(function (tsk) {
          var tv = taskValue(tsk.importance,  new Date(), tsk.deadline, "");
        ###  Tasks.update(tsk._id,  {$set: {taskValue: tv}}    );
      });
    },
});

a piece of my schema:

    taskValue: {
        type: Number,
        decimal: true,
    },

    createdBy: {
        type: String,
        autoValue: function(){
             return this.userId
        },
    },

Thank you for your work ! :-)

Your autoValue runs on every insert/update and there is no userId when you run an update in up or down.

You could do this:

createdBy: {
        type: String,
        autoValue: function(){
              if(this.isInsert)
             return this.userId
        }