I tried this command in different possible ways but the basic structure of my command was.
yarn typeorm migration:generate -n=consent-record -d=\"./src/db/CliDataSource.ts\"
this is my typeorm command in the package.json for yarn berry
"typeorm": "ts-node -P ./tsconfig.typeorm.json $(yarn bin typeorm) -d ./src/db/CliDataSource.ts",
I also tried installing typeorm locally as an npm. and also tried with npx. but they all give the following error. "Not enough non-option arguments: got 0, need at least 1" this error clearly doesn't mention what is missing.
my CliDataSource goes like this.
export const CliDataSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5436,
username: '****',
password: '******',
database: 'consent',
synchronize: false,
logging: false,
entities,
migrations,
migrationsRun: true,
subscribers: [],
});

I am using typeorm "^0.3.6"
Latest updates to the typeorm has removed -n flag which we used to rename migrations. how it works now is that we need to provide the migration file path. that will store the migration in that specified file. so the updated operations were
my typeorm alias inside package.json.
"typeorm": "ts-node -P ./tsconfig.typeorm.json $(yarn bin typeorm) -d ./src/db/CliDataSource.ts",
CLI Command
yarn typeorm migration:generate ./src/db/migrations/consent-record
The official documentation seems outdated. hope it will be updated soon.
Special thanks to Jacob Copini @woov
I had a similar issue but solved it initially using a util file like this
// contents of migration.ts
import { exec } from 'child_process';
const command = `npm run typeorm migration:create ./src/migrations/${process.argv[process.argv.length - 1]}`;
(() => exec(command, (error, stdout, stderr) => {
if (error !== null) {
console.error(stderr);
}
console.log(stdout);
}))();
In the package.json:
"migration:create": "ts-node migration.ts"
And to use, type the following:
npm run migration:create unique-key-username
But here's how it should be done after the latest changes in TypeORM:
// new syntax for TypeORM ormconfig.ts
const { DataSource } = require("typeorm");
require('dotenv').config();
for (const envName of Object.keys(process.env)) {
process.env[envName] = process.env[envName].replace(/\\n/g, '\n');
}
const connectionSource = new DataSource({
type: 'mysql',
host: process.env.DB_HOST,
port: +process.env.DB_PORT,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
entities: [__dirname + '/entities/**/*.{js,ts}'],
migrations: [__dirname + '/dist/src/migrations/*.js'],
});
module.exports = {
connectionSource,
}
// package.json
"typeorm": "ts-node node_modules/typeorm/cli.js",
"migration:create": "ts-node migration.ts -d ./ormconfig.ts",
"migration:run": "typeorm migration:run -d ./ormconfig.ts",
"migration:revert": "typeorm migration:revert -d ./ormconfig.ts",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With