- Updated SSL settings in database.module.ts and ormconfig.ts to use DATABASE_SSL environment variable for better control over SSL usage. - Clarified comments to indicate that SSL is only necessary for remote PostgreSQL instances, enhancing understanding for local development setups.
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';
|
|
import { Unique } from './validators/unique.validator';
|
|
|
|
/**
|
|
* Database module.
|
|
* Removed the second PostHog database connection.
|
|
* Only the main application database is configured.
|
|
*/
|
|
@Module({
|
|
imports: [
|
|
TypeOrmModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => ({
|
|
type: 'postgres',
|
|
host: configService.get('DATABASE_HOST'),
|
|
port: configService.get<number>('DATABASE_PORT'),
|
|
username: configService.get('DATABASE_USER'),
|
|
password: configService.get('DATABASE_PASSWORD'),
|
|
database: configService.get('DATABASE_NAME'),
|
|
namingStrategy: new SnakeNamingStrategy(),
|
|
entities: ['dist/**/*.entity.{ts,js}'],
|
|
migrations: ['dist/database/migrations/*.{ts,js}'],
|
|
migrationsTableName: 'typeorm_migrations',
|
|
autoLoadEntities: true,
|
|
// In production: false. In development: true for auto-schema sync.
|
|
synchronize: configService.get('ENVIRONMENT') === 'development',
|
|
connectTimeoutMS: 10_000,
|
|
maxQueryExecutionTime: 30_000,
|
|
poolSize: 50,
|
|
extra: {
|
|
poolSize: 50,
|
|
connectionTimeoutMillis: 5000,
|
|
query_timeout: 30_000,
|
|
statement_timeout: 30_000,
|
|
},
|
|
// SSL is only needed for remote/managed PostgreSQL (e.g. AWS RDS).
|
|
// Self-hosted Docker setups use an internal network — no SSL required.
|
|
ssl: configService.get('DATABASE_SSL') === 'true'
|
|
? { rejectUnauthorized: false }
|
|
: false,
|
|
}),
|
|
}),
|
|
],
|
|
providers: [Unique],
|
|
})
|
|
export class DatabaseModule {}
|