proximity sequelize migrations
Generates migrations in JS from sequelize models
This package provide two tools:
-
makemigration
- tool for creating new migrations for schema based migrations -
makedatamigration
- tool for creating new migration template for data based migrations
Install
npm install proximity_sequelize_migrations
Usage
- Init sequelize, with sequelize-cli, using
sequelize init
- manually create a _current.json and _current_bak.json in the migrations directory, with the following structure
- {
- "tables": {
- },
- "revision": (0 for _current)/(-1 for _current_bak) -}
- Create your models
- Create initial migration - run:
node ./node_modules/proximity_sequelize_migrations/bin/makemigration --name <migration name>
- Change models and run it again, model difference will be saved to the next migration
To preview new migration, without any changes, you can run:
node ./node_modules/sequelize-auto-migrations/bin/makemigration --preview
makemigration
tool creates _current.json
and _current_bak.json
files in migrations
dir, which are used to track changes. Do not remove!
To create and then execute migration immediately, use:
makemigration --name <name> -x
Executing migrations
- There is simple command to perform all created migrations (from selected revision):
node ./node_modules/sequelize-auto-migrations/bin/runmigration
- To select a revision, use
--rev <x>
- If migration fails, you can continue, use
--pos <x>
- To prevent execution next migrations, use
--one
For more information, use makemigration --help
, runmigration --help
TODO:
- Migration action sorting procedure need some fixes. When many foreign keys in tables, there is a bug with action order. Now, please check it manually (
--preview
option) - Need to check (and maybe fix) field types:
BLOB
,RANGE
,ARRAY
,GEOMETRY
,GEOGRAPHY
- Version control needs work, specifically the revision system
- Fix db initialisation bug