v1.0.1Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Call for maintainers

Since I'm no longer actively developing an app that uses migrations, I've lost touch with the codebase and the project. I'm looking for folks to take over development and maintenance, please raise your hand if you're interested via this issue.


Build Status

A simple migration system for Meteor supporting up/downwards migrations and command line usage.


Meteor Migrations can be installed through Meteor's package manager. Type:

$ meteor add percolate:migrations



To write a simple migration, somewhere in the server section of your project define:

2  version: 1,
3  up: function() {//code to migrate up to version 1}

To run this migration from within your app call:

1Meteor.startup(() => {
2  Migrations.migrateTo('latest');


A more complete set of migrations might look like:

2  version: 1,
3  name: 'Adds pants to some people in the db.',
4  up: function() {//code to migrate up to version 1}
5  down: function() {//code to migrate down to version 0}
9  version: 2,
10  name: 'Adds a hat to all people in the db who are wearing pants.',
11  up: function() {//code to migrate up to version 2}
12  down: function() {//code to migrate down to version 1}

As in 'Basics', you can migrate to the latest by running:

1Meteor.startup(function() {
2  Migrations.migrateTo('latest');

Note: Migrations should be run from Meteor.startup to allow for log output configuration.

By specifying a version, you can migrate directly to that version (if possible). The migrations system will automatically determine which direction to migrate in.

In the above example, you could migrate directly to version 2 by running:


If you wanted to undo all of your migrations, you could migrate back down to version 0 by running:


Sometimes (usually when somethings gone awry), you may need to re-run a migration. You can do this with the rerun subcommand, like:


NOTE: You cannot create your own migration at version 0. This version is reserved by migrations for a 'vanilla' system, that is, one without any migrations applied.

To see what version the database is at, call:



You can configure Migrations with the config method. Defaults are:

2  // Log job run details to console
3  log: true,
5  // Use a custom logger function (defaults to Meteor's logging package)
6  logger: null,
8  // Enable/disable logging "Not migrating, already at version {number}"
9  logIfLatest: true,
11  // migrations collection name to use in the database
12  collectionName: "migrations"


Migrations uses Meteor's logging package by default. If you want to use your own logger (for sending to other consumers or similar) you can do so by configuring the logger option.

Migrations expects a function as logger, and will pass arguments to it for you to take action on.

1var MyLogger = function(opts) {
2  console.log('Level', opts.level);
3  console.log('Message', opts.message);
4  console.log('Tag', opts.tag);
8  logger: MyLogger
11Migrations.add({ name: 'Test Job', ... });

The opts object passed to MyLogger above includes level, message, and tag.

  • level will be one of info, warn, error, debug.
  • message is something like Finished migrating..
  • tag will always be "Migrations" (handy for filtering).

Custom collection name

By default, the collection name is migrations. There may be cases where this is inadequate such as using the same Mongo database for multiple Meteor applications that each have their own set of migrations that need to be run.

Command line use


This info is for pre 0.9 users as post 0.9 the script is no longer included in the package folder.

You can also run migrations from the command line using the included shell script. This will

  1. Launch your Meteor app
  2. Call Migrations.migrateTo(version)
  3. Exit your app

For instance, from your project's root, run:

$ ./packages/percolatestudio-migrations/ latest

You can also specify additional arguments to be passed into meteor, like:

$ ./packages/percolatestudio-migrations/ latest --settings ./setting.json


  1. Not migrating, control is locked

Migrations set a lock when they are migrating, to prevent multiple instances of your clustered app from running migrations simultaneously. If your migrations throw an exception, you will need to manually remove the lock (and ensure your db is still consistent) before re-running the migration.

From the mongo shell update the migrations collection like this:

$ meteor mongo

db.migrations.update({_id:"control"}, {$set:{"locked":false}});

Alternatively you can unlock the collection from either server code or the meteor shell using:



  1. Write some code.

  2. Write some tests.

  3. From this package's local directory, start the test runner:

    $ meteor test-packages ./
  4. Open http://localhost:3000/ in your browser to see the test results.


MIT. (c) Percolate Studio, maintained by Zoltan Olah (@zol).

Meteor Migrations was developed as part of the Verso project.