diff --git a/src/config/database.config.ts b/src/config/database.config.ts index e45c8e71..7a104dba 100644 --- a/src/config/database.config.ts +++ b/src/config/database.config.ts @@ -4,14 +4,19 @@ import { ConfigService } from '@nestjs/config'; export const getDatabaseConfig = (configService: ConfigService): TypeOrmModuleOptions => ({ type: 'postgres', - host: configService.get('DB_HOST'), - port: configService.get('DB_PORT'), - username: configService.get('DB_USERNAME'), - password: configService.get('DB_PASSWORD'), - database: configService.get('DB_DATABASE'), + + url: configService.get('DATABASE_URL'), + entities: [`${__dirname}/../**/*.entity{.ts,.js}`], - synchronize: false, // NEVER true in production + synchronize: false, logging: configService.get('NODE_ENV') === 'development', migrations: [`${__dirname}/../migrations/*{.ts,.js}`], - migrationsRun: false, // Run migrations manually + migrationsRun: false, + + ssl: true, // 👈 important + extra: { + ssl: { + rejectUnauthorized: false, + }, + }, }); diff --git a/src/ormconfig.ts b/src/ormconfig.ts index f5bd3f56..30e1d7d9 100644 --- a/src/ormconfig.ts +++ b/src/ormconfig.ts @@ -10,17 +10,23 @@ const base = isProd ? 'dist' : 'src'; const options: DataSourceOptions & SeederOptions = { type: 'postgres', - host: process.env.DB_HOST || 'localhost', - port: parseInt(process.env.DB_PORT ?? '5432', 10), - username: process.env.DB_USERNAME || 'postgres', - password: process.env.DB_PASSWORD, - database: process.env.DB_DATABASE, + + url: process.env.DATABASE_URL, + entities: [`${base}/**/*.entity.${ext}`], migrations: [`${base}/database/migrations/*.${ext}`], synchronize: false, logging: !isProd, + seeds: [`${base}/database/seeds/**/*.${ext}`], factories: [`${base}/database/factories/**/*.${ext}`], + + ssl: true, + extra: { + ssl: { + rejectUnauthorized: false, + }, + }, }; -export default new DataSource(options); \ No newline at end of file +export default new DataSource(options);