The cli options in the Typeorm config is not working

265 views Asked by At

I am learning about migrations in NestJs typeorm so when i specfied the cli property to typeormconfig file it says that the cli property dont exist.

import { TypeOrmModuleOptions  } from '@nestjs/typeorm';
import { join } from 'path';

const typeConfigDatabase: TypeOrmModuleOptions = {
  type: 'postgres',
  host: process.env.POSTGRES_HOST,
  port: Number(process.env.POSTGRES_PORT),
  username: process.env.POSTGRES_USER,
  password: process.env.POSTGRES_PASSWORD,
  database: process.env.POSTGRES_DB,
  entities: [join(__dirname, '**', '*.entity.{ts,js}')],
  synchronize: false,
  migrations: ['dist/src/db/migrations/*.js'],
  cli: {
    migrationsDir: 'src/db/migrations',
  },
};

I was expecting that on running the migration command the migration folder will be created but its not. The Error is :

Object literal may only specify known properties, and 'cli' does not exist in type '{ retryAttempts?: number; retryDelay?: number; toRetry?: (err: any) => boolean; autoLoadEntities?: boolean; keepConnectionAlive?: boolean; verboseRetryLog?: boolean; } &
1

There are 1 answers

0
Robin Thomas On BEST ANSWER

Since you are using typeorm version of 0.3 or higher, the cli.migrationsDir option do not exist anymore.

You'll have to use the new way to generate migrations: https://github.com/typeorm/typeorm/issues/8810


Basically, you need to have two options in typeorm config:

  1. migrationsTableName
  2. migrations

Then use the CLI to create the migration:

typeorm migration:create ./path-to-migrations-dir/PostRefactoring

Refer to https://typeorm.io/migrations#creating-a-new-migration for more details.