sqlmigrate
Helps automating MySQL migrations written in plain .sql
scripts.
Note: The CLI utility API has changed in v2.
Usage
Library
;
CLI
sqlmigrate
script will attempt to read the config file from the current
working directory named .sqlmigrate
:
// .sqlmigrate examplemoduleexports = migrationsDir: 'src/db/migrations' dbConfig: database: processenvDB_NAME host: processenvDB_HOST port: processenvDB_PORT user: processenvDB_USER password: processenvDB_PASS ;
If driver
property is specified in the config file, it can be used to select
the database client. For example, this is how mysql2 can be used:
moduleexports = migrationsDir: 'src/db/migrations' driver: 'mysql2' dbConfig: ...
Installation
$ npm install sqlmigrate$ export PATH="$(PWD)/node_modules/.bin:$(PATH)" # or $ npm install -g sqlmigrate
CLI help
$ sqlmigrate --help Usage: sqlmigrate [command] [args...] Migration will be performed when no command is specified. The default command accepts the following optional args: --config=file config file to use, default is .sqlmigrate --max=n max number of migrations to perform --any-order do not fail
Initize config
$ sqlmigrate init [--config=/path/to/file]
Creating a migration script
$ sqlmigrate create --name='new-migration' [--config=/path/to/file]
Execute migrations
$ sqlmigrate [--config=/path/to/file]
Execute first two migrations
$ sqlmigrate --max=2
Perform the migrations, ignoring the order of currently executed migrations
$ sqlmigrate --any-order