Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit a4a5fb5

Browse files
author
Michael Maslov
committed
add runmigration and makemigration to cli
1 parent d030e72 commit a4a5fb5

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ This package provide two tools:
1313
* Create your models
1414
* Create initial migration - run:
1515

16-
`node ./node_modules/sequelize-auto-migrations/bin/makemigration --name <migration name>`
16+
`makemigration --name <migration name>`
1717
* Change models and run it again, model difference will be saved to the next migration
1818

1919
To preview new migration, without any changes, you can run:
2020

21-
`node ./node_modules/sequelize-auto-migrations/bin/makemigration --preview`
21+
`makemigration --preview`
2222

2323
`makemigration` tool creates `_current.json` file in `migrations` dir, that is used to calculate difference to the next migration. Do not remove it!
2424

@@ -28,7 +28,7 @@ To create and then execute migration, use:
2828
## Executing migrations
2929
* There is simple command to perform all created migrations (from selected revision):
3030

31-
`node ./node_modules/sequelize-auto-migrations/bin/runmigration`
31+
`runmigration`
3232
* To select a revision, use `--rev <x>`
3333
* If migration fails, you can continue, use `--pos <x>`
3434
* To prevent execution next migrations, use `--one`

bin/makemigration.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/node
1+
#!/usr/bin/env node
22

33
const commandLineArgs = require('command-line-args');
44
const beautify = require('js-beautify').js_beautify;
@@ -32,6 +32,7 @@ if (options.help)
3232
process.exit(0);
3333
}
3434

35+
// Windows support
3536
if(!process.env.PWD){
3637
process.env.PWD = process.cwd()
3738
}
@@ -41,6 +42,16 @@ const {
4142
modelsDir
4243
} = pathConfig(options);
4344

45+
if (!fs.existsSync(modelsDir)) {
46+
console.log("Can't find models directory. Use `sequelize init` to create it")
47+
return
48+
}
49+
50+
if (!fs.existsSync(migrationsDir)) {
51+
console.log("Can't find migrations directory. Use `sequelize init` to create it")
52+
return
53+
}
54+
4455
// current state
4556
const currentState = {
4657
tables: {}

bin/runmigration.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/node
1+
#!/usr/bin/env node
22

33
const path = require("path");
44
const commandLineArgs = require('command-line-args');
@@ -20,6 +20,7 @@ const optionDefinitions = [
2020

2121
const options = commandLineArgs(optionDefinitions);
2222

23+
// Windows support
2324
if(!process.env.PWD){
2425
process.env.PWD = process.cwd()
2526
}
@@ -29,6 +30,16 @@ let {
2930
modelsDir
3031
} = pathConfig(options);
3132

33+
if (!fs.existsSync(modelsDir)) {
34+
console.log("Can't find models directory. Use `sequelize init` to create it")
35+
return
36+
}
37+
38+
if (!fs.existsSync(migrationsDir)) {
39+
console.log("Can't find migrations directory. Use `sequelize init` to create it")
40+
return
41+
}
42+
3243
if (options.help)
3344
{
3445
console.log("Simple sequelize migration execution tool\n\nUsage:");
@@ -39,7 +50,6 @@ if (options.help)
3950
process.exit(0);
4051
}
4152

42-
const Sequelize = require("sequelize");
4353
const sequelize = require(modelsDir).sequelize;
4454
const queryInterface = sequelize.getQueryInterface();
4555

0 commit comments

Comments
 (0)