Where for runing "Migrations.migrateTo('latest')" (on CLI / JS (client/server))?


#1

I try to use percolate:migrations package to migrate data.

// In server
Migrations.add({
  version: 1,
  up: function() {//code to migrate up to version 1
  ......................
  }
});

But I don’t know where to run Migrations.migrateTo('latest')?
In command line or JS (client/server).
Please help me.


#2

On a Heroku hosted application, I have a file called migrator.js:

if (Meteor.isServer) {
  Meteor.startup(function(){
    Migrations.migrateTo('latest');
  });
}

Alongside it I keep a folder /migrations with files 1.js, 2.js etc, each containing migrations for a specific version.

I think down migrations are only intended for development use, since you can’t use “$ meteor shell” in production. To run down migrations, I run “Migrations.migrateTo()” the version I need from the meteor shell, and then I git checkout to the right commit. When I go forward in time again I don’t need to use the meteor shell, it’ll migrate to automatically.


#3

@thomasvanlankveld

In your migrations folder, you are having files like 1.js, 2.js etc. Can you give any example of the contents of those files?
I am trying to achieve the following:
Let’s say for an upgrade I need to run migrations for two different collections. How can we add those migrations in one file like 1.js?


#4

You basically use the up and down functions as scripts to modify your collections.

Migrations.add({
  version: 1,
  name: 'Change some stuff.',
  up: function() {
    collectionOne.update({}, { $rename: { oldName: 'newName' } }); // One collection...
    collectionTwo.remove({ prop: 'removeMe' }); // And two collections updated in one migration!
  },
  down: function() {
    collectionOne.update({}, { $rename: { newName: 'oldName' } });
  }
});