node.jspostgresqltypeorm

How can I specify the migrations directory for typeorm CLI?


After the new typeorm release I am having some troubles to work with migrations.

Some time ago I was using this code and it worked -

entities: ['./src/modules/**/infra/typeorm/entities/*.ts'],
migrations: ['./src/shared/infra/typeorm/migrations/*.ts'],
cli: {
  migrationsDir: './src/shared/infra/typeorm/migrations'
}

But now I can't specify the CLI property. To create a new migration, I have to specify the entire migration path -

npm run typeorm migration:create ./src/database/migrations -n SomeTest

Is there another way to do that without specifying the entire path?


Solution

  • As Jun 2022, the docs is outdated -n MigrationName is no longer supported. You can do this instead:

    typescript esm: npx typeorm-ts-node-esm migration:create src/database/migration/MigrationFileName where MigrationFileName is the filename you want to create and src/database/migration/ is the path.

    typescript commonjs: npx typeorm-ts-node-commonjs migration:create

    P.S This might be late but this could save others. P.S I just discover this myself. If this doesn't work in the future, let me know, so I would know as well.