Extendable database agnostic migration command line tool and mini-framework for node.js. Inspired by the Rails migrate tool and node-migrate.
Simple database migration tool inspired by migrate and the rails migration tool.
- Migration scripts are stored in a folder, with a timestamp + ID + name identifier and are written in pure JS
- By default it stores which migrations have been run on the filesystem, but you can easily extend and change that behavior.
- You can have setup and teardown scripts run before and after migrations
- It will attempt to fail gracefully by saving which migrations have been run each time one has been run, and not all-or-nothing.
$ npm install milkshake
(To install globally use
npm install -g milkshake)
To initialize a new migration folder:
$ milkshake init
This will create an empty folder in your current working directory named
and include a setup.js file by default. (Hint: Look in lib/default-setup.js to see
the methods you can override in your own setup file, eg. for inserting active
migrations or removing from your own database).
Create a new migration file:
$ milkshake new "Create table users"
This will generate a new empty migration file named
You can list the migrations that will be run (changes not yet reflected in your database) by using the command:
$ milkshake list
To run the migration:
$ milkshake migrate
To run a downwards migration (downgrades, undos, whatever you'd call them):
$ milkshake migrate:down
And then you can run a single upwards migration (also applies to downwards migrations) by appending a number after the command:
$ milkshake migrate:up 2
To see the full command line options:
$ milkshake --help
Usage: milkshake [options] commandOptions:-c, --chdir <path> Change the working directory to a given migrationdirectory. eg. /home/billybob/myapp/migrationsIf no path is given, it defaults to ./migrations-h, --help Show this help screen-v, --version Displays the current version-d, --dry, --dry-run Dry run of migrationsCommands:init Initialize an initial migration directory and helper filemigrate Migrate up to the latest migrationmigrate:up [n] Migrate up by n migrationsmigrate:down [n] Migrate down by n migrationslist List the migrations to be run
- Maybe the MigrationDir thing should be a more traditional class-like thing
- Write more tests
- There might be some error cases we could handle better.
- Implement the command to list applied migrations that don't exist (helpful for debugging)
Pull requests welcome