RobinCK / typeorm-fixtures

:pill: Fixtures loader for typeorm 🇺🇦
https://robinck.github.io/typeorm-fixtures/
MIT License
563 stars 45 forks source link

[Question] Load TypeORM confiugration when it is created by a factory #166

Open SirMishaa opened 3 years ago

SirMishaa commented 3 years ago

Hello !

For some reason, I'm using a factory to create the configuration for TypeORM Is it possible to upload this file? So that I can launch my fixture ?

// database.module.ts
import { Logger, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => {
        configService.get<boolean>('synchronizeMigration') &&
          new Logger(DatabaseModule.name).warn(
            'The synchronization of models are activated, be careful',
          );
        return {
          type: 'postgres',
          host: configService.get<string>('database.host'),
          port: configService.get<number>('database.port'),
          username: configService.get<string>('database.user'),
          password: configService.get<string>('database.password'),
          database: configService.get<string>('database.databaseName'),
          entities: [__dirname + '../../../**/*.entity.{js,ts}'],
          synchronize: configService.get<boolean>('synchronizeMigration'),
        };
      },
      inject: [ConfigService],
    }),
  ],
})
export class DatabaseModule {}

Kind regards

lowgos commented 2 years ago

I've got the same problem. The TypeORM configuration in NestJS isn't loaded from a config file but from the master module through a factory.

Is the typeorm-fixture CLI you're providing supporting such a use case ?