import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';

const isTest = process.env.NODE_ENV === 'test';

@Module({
  imports: isTest
    ? []
    : [
        TypeOrmModule.forRootAsync({
          imports: [ConfigModule],
          useFactory: () => ({
            type: 'mysql',
            url: process.env.DATABASE_URL,
            autoLoadEntities: true,
            synchronize: false,
            migrationsRun: false,
            timezone: 'Z',
          }),
        }),
      ],
})
export class DatabaseModule {}
