Skip to content

Commit f5fdf53

Browse files
authored
feat: support migrations files with ts file extension (#915)
1 parent 9d5882a commit f5fdf53

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/core/migrator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function getMigrator(type, args) {
4545
migrations: {
4646
params: [sequelize.getQueryInterface(), Sequelize],
4747
path: helpers.path.getPath(type),
48-
pattern: /\.c?js$/,
48+
pattern: /\.(cjs|js|ts)$/,
4949
},
5050
});
5151

test/db/migrate.test.js

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

30-
if (!migrationFile.match(/\.cjs$/)) {
30+
if (!migrationFile.match(/\.(cjs|ts)$/)) {
3131
migrationFile = migrationFile + '.js';
3232
}
3333
if (flag.match(/config\.js$/)) {
@@ -152,6 +152,23 @@ const _ = require('lodash');
152152
});
153153
});
154154

155+
describe('migrations with ts extension', () => {
156+
it('correctly migrates', function (done) {
157+
const self = this;
158+
prepare(
159+
() => {
160+
helpers.readTables(self.sequelize, (tables) => {
161+
expect(tables.sort()).to.contain('Typescript');
162+
done();
163+
});
164+
},
165+
{
166+
migrationFile: 'ts/*createTypescript.ts',
167+
}
168+
);
169+
});
170+
});
171+
155172
describe('custom meta table name', () => {
156173
it('correctly uses the defined table name', function (done) {
157174
const self = this;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
module.exports = {
4+
up: async (queryInterface, DataTypes) => {
5+
await queryInterface.createTable('Typescript', {
6+
title: DataTypes.STRING,
7+
body: DataTypes.TEXT,
8+
});
9+
},
10+
down: async (queryInterface) => {
11+
await queryInterface.dropTable('Typescript');
12+
},
13+
};

0 commit comments

Comments
 (0)