mizzle
v2.0.0
Published
Simple migrations. CLI and JS API. DB agnostic.
Downloads
1
Maintainers
Readme
mizzle
Simple migrations. CLI and JS API. DB Agnostic.
Usage
CLI
Usage: migrate [options] [command]
Commands:
apply [migration] apply all unapplied migrations or just [migration]
reverse [migration] reverse all applied migrations or just [migration]
create [name] create a new migration file with optional [name]
list [options] list migrations and whether they have been applied
Options:
-h, --help output usage information
-V, --version output the version number
-p, --path <path> Path to migrations (default: migrations)
-s, --storage <path> Path to storage module
Javascript
var Migration = require('mizzle').Migration;
Migration({
path: 'migrations',
storage: require('./migration.store.js') // a module to store version in DB
})
.on('apply', function (name) {
console.log('apply : ' + name);
})
.on('reverse', function (name) {
console.log('reverse : ' + name);
})
.on('error', function (err) {
console.error(err);
})
.on('completed', function (completed) {
if (completed.length) {
console.log('migration : complete');
} else {
console.log('migration : nothing to do');
}
})
.run('up');
Migrations
Migrations export apply(callback)
and reverse(callback)
functions.
Create migrations using migrate create [name]
. Migrations are modules kept in
the migrations path and have file names prefixed with a timestamp for ordering.
Example:
module.exports = {
apply: function (done) {
// ...
done();
},
reverse: function (done) {
// ...
done();
}
};
Storage module
Store which migrations have been applied in your DB by specifying a
--storage
module.
A storage module exports methods get(callback)
and set(applied, callback)
where applied
is an array of the migrations applied.
The default storage module persists to disk at [path]/.applied
.