Skip to content

Commit 08db590

Browse files
authored
feat: support a migration with a cjs extension (#905)
1 parent 1c34f48 commit 08db590

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/core/migrator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function getMigrator (type, args) {
4949
migrations: {
5050
params: [sequelize.getQueryInterface(), Sequelize],
5151
path: helpers.path.getPath(type),
52-
pattern: /\.js$/,
52+
pattern: /\.c?js$/,
5353
wrap: fun => {
5454
if (fun.length === 3) {
5555
return promisify(fun);

test/db/migrate.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const _ = require('lodash');
2626
const config = _.assign({}, helpers.getTestConfig(), options.config);
2727
let configContent = JSON.stringify(config);
2828

29-
migrationFile = migrationFile + '.js';
29+
if(!migrationFile.match(/\.cjs$/)){
30+
migrationFile = migrationFile + '.js';
31+
}
3032
if (flag.match(/config\.js$/)) {
3133
configPath = configPath + 'config.js';
3234
configContent = 'module.exports = ' + configContent;
@@ -128,6 +130,20 @@ const _ = require('lodash');
128130
});
129131
});
130132

133+
describe('migrations with cjs extension', () => {
134+
it('correctly migrates', function (done) {
135+
const self = this;
136+
prepare(() => {
137+
helpers.readTables(self.sequelize, tables => {
138+
expect(tables.sort()).to.contain('Comment');
139+
done();
140+
});
141+
}, {
142+
migrationFile: 'cjs/*createComment.cjs'
143+
});
144+
});
145+
});
146+
131147
describe('custom meta table name', () => {
132148
it('correctly uses the defined table name', function (done) {
133149
const self = this;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
var nodeify = require('nodeify');
4+
5+
module.exports = {
6+
up: function (migration, DataTypes, done) {
7+
nodeify(migration
8+
.createTable('Comment', {
9+
title: DataTypes.STRING,
10+
body: DataTypes.TEXT
11+
}), done);
12+
},
13+
14+
down: function (migration, DataTypes, done) {
15+
nodeify(migration.dropTable('Comment'), done);
16+
}
17+
};

0 commit comments

Comments
 (0)