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

Commit 203f1b9

Browse files
committed
Add fallback to match previous behavior
1 parent 1dd07de commit 203f1b9

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

bin/makemigration.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if (options.help)
2929
let alias = (option.alias) ? ` (-${option.alias})` : '\t';
3030
console.log(`\t --${option.name}${alias} \t${option.description}`);
3131
});
32-
process.exit(0);
32+
process.exit(0);
3333
}
3434

3535
// Windows support
@@ -38,7 +38,7 @@ if(!process.env.PWD){
3838
}
3939

4040
const {
41-
migrationsDir,
41+
migrationsDir,
4242
modelsDir
4343
} = pathConfig(options);
4444

@@ -56,28 +56,29 @@ if (!fs.existsSync(migrationsDir)) {
5656
const currentState = {
5757
tables: {}
5858
};
59-
59+
6060
// load last state
6161
let previousState = {
6262
revision: 0,
6363
version: 1,
6464
tables: {}
6565
};
66-
66+
6767
try {
6868
previousState = JSON.parse(fs.readFileSync(path.join(migrationsDir, '_current.json') ));
6969
} catch (e) { }
7070

7171
//console.log(path.join(migrationsDir, '_current.json'), JSON.parse(fs.readFileSync(path.join(migrationsDir, '_current.json') )))
72-
let sequelize = require(modelsDir).default;
72+
let modelsDirMod = require(modelsDir);
73+
let sequelize = modelsDirMod.sequelize || modelsDirMod.default;
7374

7475
let models = sequelize.models;
7576

7677
currentState.tables = migrate.reverseModels(sequelize, models);
77-
78+
7879
let actions = migrate.parseDifference(previousState.tables, currentState.tables);
7980

80-
// sort actions
81+
// sort actions
8182
migrate.sortActions(actions);
8283

8384
let migration = migrate.getMigration(actions);
@@ -110,7 +111,7 @@ currentState.revision = previousState.revision + 1;
110111
fs.writeFileSync(path.join(migrationsDir, '_current.json'), JSON.stringify(currentState, null, 4) );
111112

112113
// write migration to file
113-
let info = migrate.writeMigration(currentState.revision,
114+
let info = migrate.writeMigration(currentState.revision,
114115
migration,
115116
migrationsDir,
116117
(options.name) ? options.name : 'noname',

bin/runmigration.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if(!process.env.PWD){
2626
}
2727

2828
let {
29-
migrationsDir,
29+
migrationsDir,
3030
modelsDir
3131
} = pathConfig(options);
3232

@@ -50,7 +50,8 @@ if (options.help)
5050
process.exit(0);
5151
}
5252

53-
const sequelize = require(modelsDir).default;
53+
let modelsDirMod = require(modelsDir);
54+
let sequelize = modelsDirMod.sequelize || modelsDirMod.default;
5455
const queryInterface = sequelize.getQueryInterface();
5556

5657
// execute all migration from
@@ -76,8 +77,8 @@ let migrationFiles = fs.readdirSync(migrationsDir)
7677
let rev = parseInt( path.basename(file).split('-',2)[1]);
7778
return (rev >= fromRevision);
7879
});
79-
80-
console.log("Migrations to execute:");
80+
81+
console.log("Migrations to execute:");
8182
migrationFiles.forEach((file) => {
8283
console.log("\t"+file);
8384
});
@@ -86,13 +87,13 @@ if (options.list)
8687
process.exit(0);
8788

8889

89-
Async.eachSeries(migrationFiles,
90+
Async.eachSeries(migrationFiles,
9091
function (file, cb) {
9192
console.log("Execute migration from file: "+file);
9293
migrate.executeMigration(queryInterface, path.join(migrationsDir, file), fromPos, (err) => {
9394
if (stop)
9495
return cb("Stopped");
95-
96+
9697
cb(err);
9798
});
9899
// set pos to 0 for next migration

0 commit comments

Comments
 (0)