From 794c569a4a26d9c91b243c7f945befc739e976c6 Mon Sep 17 00:00:00 2001 From: Vitaliy Zaytsev Date: Sun, 5 Jul 2020 11:19:06 +0600 Subject: [PATCH] support migrations files with ts file extension --- src/core/migrator.js | 2 +- test/db/migrate.test.js | 19 ++++++++++++++++++- .../ts/20200705000000-createTypescript.ts | 13 +++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/support/assets/migrations/ts/20200705000000-createTypescript.ts diff --git a/src/core/migrator.js b/src/core/migrator.js index bb9bc00f3..53eaaa1c1 100644 --- a/src/core/migrator.js +++ b/src/core/migrator.js @@ -45,7 +45,7 @@ export async function getMigrator(type, args) { migrations: { params: [sequelize.getQueryInterface(), Sequelize], path: helpers.path.getPath(type), - pattern: /\.c?js$/, + pattern: /\.(cjs|js|ts)$/, }, }); diff --git a/test/db/migrate.test.js b/test/db/migrate.test.js index 2304cb902..05b0be418 100644 --- a/test/db/migrate.test.js +++ b/test/db/migrate.test.js @@ -27,7 +27,7 @@ const _ = require('lodash'); const config = _.assign({}, helpers.getTestConfig(), options.config); let configContent = JSON.stringify(config); - if (!migrationFile.match(/\.cjs$/)) { + if (!migrationFile.match(/\.(cjs|ts)$/)) { migrationFile = migrationFile + '.js'; } if (flag.match(/config\.js$/)) { @@ -152,6 +152,23 @@ const _ = require('lodash'); }); }); + describe('migrations with ts extension', () => { + it('correctly migrates', function (done) { + const self = this; + prepare( + () => { + helpers.readTables(self.sequelize, (tables) => { + expect(tables.sort()).to.contain('Typescript'); + done(); + }); + }, + { + migrationFile: 'ts/*createTypescript.ts', + } + ); + }); + }); + describe('custom meta table name', () => { it('correctly uses the defined table name', function (done) { const self = this; diff --git a/test/support/assets/migrations/ts/20200705000000-createTypescript.ts b/test/support/assets/migrations/ts/20200705000000-createTypescript.ts new file mode 100644 index 000000000..26f4c051f --- /dev/null +++ b/test/support/assets/migrations/ts/20200705000000-createTypescript.ts @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, DataTypes) => { + await queryInterface.createTable('Typescript', { + title: DataTypes.STRING, + body: DataTypes.TEXT, + }); + }, + down: async (queryInterface) => { + await queryInterface.dropTable('Typescript'); + }, +};