node.js database migration tool for mongodb, sqlite, postgres, mysql
east - node.js database migration tool for different databases (extensible via adapters)
npm install east -g
alternatively you could install it locally
go to project dir and run
after that you can
rollback your migrations.
east -h to see all commands:
Usage: east [options] [command]Commands:init initialize migration systemcreate <basename> create new migration based on templatemigrate [options] run all or selected migrationsrollback [options] rollback all or selected migrationslist [status] list migration with selected status , `new` by default*Options:-h, --help output usage information-V, --version output the version number--adapter <name> which db adapter to use--config <path> config file to use--timeout <timeout> timeout
east <command> -h to see detail command help.
All options described above can be set via command line or at
located at current directory, e.g.:
"dir": "./dbmigration""template": "./lib/node/utils/customMigrationTemplate.js"
.eastrc also can be a regular nodejs script (instead of json file):
var path = require'path';moduleexports =dir: pathjoin__dirname 'dbmigration'template: './lib/node/utils/customMigrationTemplate.js';
east create doSomething
produces something like this
New migration `1_doSomething` created at migrations/1_doSomething.js
created file will contain
client is connect to current db and he determined by adapter (see adapters section)
done is function which should be called at the end of migration (if any
error occured you can pass it as first argument)
migration also can be synchronous - declare only
rollback function is optional and may be omitted
Migration file is normal node.js module and you can migrate any database e.g.
// include your database wrapper which you already use in appvar db = require'./db';dbconnectif err doneerr;dbthingsinsert_id: 1 name: 'apple' color: 'red' done;;;dbconnectif err doneerr;dbthingsremove_id: 1 done;;;
or you can use special adapter for database (see adapters section)
let's create one more migration
east create doSomethingElse
then executes both of them
it sequentially executes all new migrations and produces
target migrations:1_doSomething2_doSomethingElsemigrate `1_doSomething`migration donemigrate `2_doSomethingElse`migration done
selected migrations can be executed by passing their names (or numbers or basenames or paths) as argument
east migrate 1_doSomething 2
in our case this command will skip all of them
skip `1_doSomething` because it`s already executedskip `2_doSomethingElse` because it`s already executednothing to migrate
you can pass
--force option to execute already executed migrations.
This is useful while you develop and test your migration.
You also can export
tags array from migration and then migrate only
migrations with selected tag specified by
rollback has similar to
migrate command syntax but executes
function from migration file
target migrations:2_doSomethingElse1_doSomethingrollback `2_doSomethingElse`migration successfully rolled backrollback `1_doSomething`migration successfully rolled back
shows new migrations e.g.
target status could be specified as an argument e.g.
east list executed
adapter determines where executed migration names will be stored and what will be
rollback function as
Default adapter store executed migration names at file
.migrations which is
located at migrations directory and pass
into cloned repository run
You also can run tests from current repository against your adapter:
testdirectory with path and parameters for your adapter e.g.
"adapter": "../../east-mysql/lib/adapter""url": "mysql://user:password@localhost/east_test_db""createDbOnConnect": true
npm testat root of the cloned repository.