Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SirMishaa opened this issue Apr 4, 2021 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@SirMishaa
Copy link

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

@SirMishaa SirMishaa added the bug Something isn't working label Apr 4, 2021
@SirMishaa SirMishaa changed the title [Ask] Load TypeORM confiugration when it is created by a factory [Question] Load TypeORM confiugration when it is created by a factory Apr 4, 2021
@lowgos
Copy link

lowgos commented Nov 24, 2021

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants