fix(db): close Prisma side pool on shutdown

This commit is contained in:
2026-03-29 19:28:25 +08:00
parent fd2043ba7e
commit 8e3f1b5bd4
2 changed files with 5 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
generator client { generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
} }
datasource db { datasource db {

View File

@@ -40,6 +40,7 @@ export class PrismaService
implements OnModuleInit, OnModuleDestroy implements OnModuleInit, OnModuleDestroy
{ {
private readonly logger = new Logger(PrismaService.name); private readonly logger = new Logger(PrismaService.name);
private readonly pool: Pool;
constructor(private configService: ConfigService) { constructor(private configService: ConfigService) {
const databaseUrl = configService.get<string>('DATABASE_URL'); const databaseUrl = configService.get<string>('DATABASE_URL');
@@ -62,6 +63,8 @@ export class PrismaService
], ],
}); });
this.pool = pool;
// Log database queries in development mode // Log database queries in development mode
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
this.$on('query' as never, (e: QueryEvent) => { this.$on('query' as never, (e: QueryEvent) => {
@@ -101,6 +104,7 @@ export class PrismaService
async onModuleDestroy() { async onModuleDestroy() {
try { try {
await this.$disconnect(); await this.$disconnect();
await this.pool.end();
this.logger.log('Successfully disconnected from database'); this.logger.log('Successfully disconnected from database');
} catch (error) { } catch (error) {
this.logger.error('Error disconnecting from database', error); this.logger.error('Error disconnecting from database', error);