Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/borsch/node-mysql-migration
node mysql migration util
https://github.com/borsch/node-mysql-migration
database-migrations migrations mysql nodejs npm-module
Last synced: 25 days ago
JSON representation
node mysql migration util
- Host: GitHub
- URL: https://github.com/borsch/node-mysql-migration
- Owner: borsch
- License: gpl-2.0
- Created: 2017-07-07T11:30:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-17T18:15:13.000Z (over 7 years ago)
- Last Synced: 2024-10-07T20:15:25.623Z (about 1 month ago)
- Topics: database-migrations, migrations, mysql, nodejs, npm-module
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/node-mysql-migration
- Size: 26.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-mysql-migration
This plugin is create to simplify migration of mysql database migration.
Using
Installing
`npm install node-mysql-migration` - to install util
Setup
```javascript
# my_db_migrations.js
var mysql = require('mysql');
var migration = require('node-mysql-migration');migration.migrate(mysql.createConnection({
host : 'host',
user : 'user',
password : 'password',
database : 'database'
}), __dirname + '/migrations');
````/migrations` - is a folder where all migrations scripts are located. There is no default value for it so you should specify it
File naming convention
migration script shoul have the following name template```
V(version name)__name_of_script_separated_with_lower_underline.sql#example
V1__init_tables.sql
V2__add_new_column.sql
```
inside migrations file you should wtire migrations script in plain SQLWARNING
for now migration support only one command in migration script.
If you migration script contains the following
```sql
ALTER TABLE `tbl_name`
ADD COLUMN `column_name` VARCHAR(250);
ALTER TABLE `tbl_name`
ADD COLUMN `column_name1` VARCHAR(250);
UPDATE `tbl_name` SET `column_name`="asd";
```then migration will fails.
to solve this split such migration into three separate migration
OR
customize your connection settings. use:```javascript
migration.migrate(mysql.createConnection({
host : 'host',
user : 'user',
password : 'password',
database : 'database',
multipleStatements: true // add this to allow multiple queries in single migration file
}), __dirname + '/migrations');
````official [`node-mysql` doc](https://github.com/mysqljs/mysql#multiple-statement-queries)
Commands
run `npm my_db_migrations.js clean` to clean the data base
run `npm my_db_migrations.js init` to init empty migration scheta table
run `npm my_db_migrations.js migrate` to apply new migrations to your data base if such exists