Убран лишний код. Скорректированы docker и package файлы. Переработано взаимодействие с бд - упрощена логика.

This commit is contained in:
Первов Артем
2026-06-19 14:59:39 +03:00
parent f5ed7fa9be
commit a12d490513
31 changed files with 120 additions and 552 deletions

View File

@@ -1,7 +1,5 @@
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Pool, QueryResult, QueryResultRow } from 'pg';
import { getIntegerConfig } from '../common/config-number';
type DatabaseHealth = {
now: Date;
@@ -13,18 +11,11 @@ type DatabaseHealth = {
export class DbService implements OnModuleInit, OnModuleDestroy {
private pool!: Pool;
constructor(private readonly config: ConfigService) {}
/** Создает пул PostgreSQL и проверяет БД до начала обработки запросов. */
async onModuleInit(): Promise<void> {
const connectionString = this.config.get<string>('DATABASE_URL');
if (!connectionString) {
throw new Error('DATABASE_URL is required.');
}
this.pool = new Pool({
connectionString,
max: getIntegerConfig(this.config, 'PG_POOL_MAX', 20),
connectionString: process.env.DATABASE_URL,
max: Number(process.env.PG_POOL_MAX),
idleTimeoutMillis: 30_000,
connectionTimeoutMillis: 5_000,
statement_timeout: 60_000,