diff --git a/packages/generators/generators/lib/plops/migration.js b/packages/generators/generators/lib/plops/migration.js index 8a6fdebee1..edd65589d4 100644 --- a/packages/generators/generators/lib/plops/migration.js +++ b/packages/generators/generators/lib/plops/migration.js @@ -14,6 +14,13 @@ const validateInput = (input) => { return regex.test(input) || "Please use only letters and number, '-' or '_' and no spaces"; }; +const getFormattedDate = (date = new Date()) => { + return new Date(date.getTime() - date.getTimezoneOffset() * 60000) + .toISOString() + .split(".")[0] + .replace(/[-T:]/g, "_"); +}; + module.exports = (plop) => { // Migration generator plop.setGenerator('migration', { @@ -29,7 +36,7 @@ module.exports = (plop) => { actions(answers) { const currentDir = process.cwd(); const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; - const timestamp = moment().format('YYYY_MM_DD_HH_mm_ss'); + const timestamp = getFormattedDate(); return [ { diff --git a/packages/generators/generators/lib/templates/ts/migration.ts.hbs b/packages/generators/generators/lib/templates/ts/migration.ts.hbs index f81e53de02..9a6fa236f6 100644 --- a/packages/generators/generators/lib/templates/ts/migration.ts.hbs +++ b/packages/generators/generators/lib/templates/ts/migration.ts.hbs @@ -1,4 +1,4 @@ -import { Knex } from 'knex'; +import type { Knex } from 'knex'; /** * Migration `{{ id }}` diff --git a/packages/generators/generators/package.json b/packages/generators/generators/package.json index e131468384..cf5546667a 100644 --- a/packages/generators/generators/package.json +++ b/packages/generators/generators/package.json @@ -36,8 +36,7 @@ "fs-extra": "10.0.0", "node-plop": "0.26.3", "plop": "2.7.6", - "pluralize": "8.0.0", - "moment": "^2.29.4" + "pluralize": "8.0.0" }, "engines": { "node": ">=14.19.1 <=18.x.x",