Coder Social home page Coder Social logo

pobuchi / meteor-migrations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from percolatestudio/meteor-migrations

0.0 2.0 0.0 65 KB

Simple migration system for Meteor

Home Page: https://atmospherejs.com/percolate/migrations

License: MIT License

CSS 0.19% HTML 1.33% JavaScript 94.33% Shell 4.14%

meteor-migrations's Introduction

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.

percolate:migrations

Build Status

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

Installation

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

$ meteor add percolate:migrations

API

Basics

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

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

To run this migration from within your app call:

Migrations.migrateTo('latest');

Advanced

A more complete set of migrations might look like:

Migrations.add({
  version: 1,
  name: 'Adds pants to some people in the db.',
  up: function() {//code to migrate up to version 1}
  down: function() {//code to migrate down to version 0}
});

Migrations.add({
  version: 2,
  name: 'Adds a hat to all people in the db who are wearing pants.',
  up: function() {//code to migrate up to version 2}
  down: function() {//code to migrate down to version 1}
});

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

Meteor.startup(function() {
  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:

Migrations.migrateTo(2);

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

Migrations.migrateTo(0);

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

Migrations.migrateTo('3,rerun');

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:

Migrations.getVersion();

Configuration

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

Migrations.config({
  // Log job run details to console
  log: true,

  // Use a custom logger function (defaults to Meteor's logging package)
  logger: null,

  // Enable/disable logging "Not migrating, already at version {number}"
  logIfLatest: true,

  // migrations collection name to use in the database
  collectionName: "migrations"
});

Logging

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.

var MyLogger = function(opts) {
  console.log('Level', opts.level);
  console.log('Message', opts.message);
  console.log('Tag', opts.tag);
}

Migrations.config({
  logger: MyLogger
});

Migrations.add({ name: 'Test Job', ... });
Migrations.start();

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

*** DEPRECATED ***

This info is for pre 0.9 users as post 0.9 the migrate.sh 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/migrate.sh latest

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

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

Errors

  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. Update the migrations collection like this:

$ meteor mongo

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

Contributing

  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.

License

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

Meteor Migrations was developed as part of the Verso project.

meteor-migrations's People

Contributors

zol avatar meonkeys avatar jamesmgreene avatar maerf0x0 avatar tmeasday avatar achtan avatar gsuess avatar kristijanhusak avatar rgm avatar dimofte avatar omasopust avatar

Watchers

James Cloos avatar Po Buchi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.