migrate-mysql
v0.4.0
Published
Simple migrations for MySQL, inspired by Thom Wright, Nick Craven, and Stack Overflow.
Downloads
40
Maintainers
Readme
Migrate MySQL
Simple migrations for MySQL, inspired by Thom Wright, Nick Craven, and Stack Overflow.
Migrations are defined in sequential SQL files, for example:
migrations
├ 1_create-table.sql
├ 2_alter-table.sql
└ 3_add-index.sql
You can integrate this into your project by:
- Installing
mysql-migrate
as a dependency
npm i mysql-migrate --save-dev
- Adding a migration command to your package.json
"scripts": {
"db:migrate": "npx mysql-migrate"
}
How it works
- Checks for DB credentials
- Checks for DB connectivity
- Checks for existing migrations table. If this does not exist, it creates one
- Runs select * from migrations to get a list of already run migrations.
- Pulls the local migrations from /migrations
- Compares the results from step #4 & #5, pruning already run migrations from the local migrations list to build a list of migrations to be performed
- For each migration in said list...
- Run the migration against the database
- Adds a record with the given filename and time performed to migrations
- Migrations complete, end script.
Design decisions
- No down migrations
- Numeric migration ordering
Contributors
This package was built by Jim Bisenius.