Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremija/node-sqlmigrate
Helps automating MySQL migrations written in plain .sql scripts
https://github.com/jeremija/node-sqlmigrate
Last synced: 9 days ago
JSON representation
Helps automating MySQL migrations written in plain .sql scripts
- Host: GitHub
- URL: https://github.com/jeremija/node-sqlmigrate
- Owner: jeremija
- License: mit
- Created: 2016-02-12T15:42:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-06T21:01:56.000Z (over 5 years ago)
- Last Synced: 2024-08-09T13:25:56.469Z (3 months ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 0
- Watchers: 4
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqlmigrate
[![Build Status](https://travis-ci.org/jeremija/node-sqlmigrate.svg?branch=master)](https://travis-ci.org/jeremija/node-sqlmigrate)
Helps automating MySQL migrations written in plain `.sql` scripts.
**Note:** The CLI utility API has changed in v2.
# Usage
## Library
```javascript
require('sqlmigrate').create({
migrationsDir: 'db/migrations',
dbConfig: {
database: 'sqlmigrate_test',
host: '127.0.0.1',
port: 3306,
user: 'travis',
password: ''
}
})
.migrate();
```## CLI
`sqlmigrate` script will attempt to read the config file from the current
working directory named `.sqlmigrate`:```javascript
// .sqlmigrate example
module.exports = {
migrationsDir: 'src/db/migrations',
dbConfig: {
database: process.env.DB_NAME,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_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][mysql2] can be used:```javascript
module.exports = {
migrationsDir: 'src/db/migrations',
driver: 'mysql2',
dbConfig: {...}
}
```### Installation
```bash
$ npm install sqlmigrate
$ export PATH="$(PWD)/node_modules/.bin:$(PATH)"# or
$ npm install -g sqlmigrate
```### CLI help
```bash
$ sqlmigrate --helpUsage: 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 if there are new migrations
created before the last executed migrationCommands:
create [--name=string] creates a migration
help prints this help
init initialize config file
```### Initize config
```bash
$ sqlmigrate init [--config=/path/to/file]
```### Creating a migration script
```bash
$ sqlmigrate create --name='new-migration' [--config=/path/to/file]
```### Execute migrations
```bash
$ sqlmigrate [--config=/path/to/file]
```### Execute first two migrations
```bash
$ sqlmigrate --max=2
```### Perform the migrations, ignoring the order of currently executed migrations
```bash
$ sqlmigrate --any-order
```# License
[MIT](LICENSE)
[mysql2]: https://www.npmjs.com/package/mysql2