fix(db): close Prisma side pool on shutdown
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = "../node_modules/.prisma/client"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
|
||||
@@ -40,6 +40,7 @@ export class PrismaService
|
||||
implements OnModuleInit, OnModuleDestroy
|
||||
{
|
||||
private readonly logger = new Logger(PrismaService.name);
|
||||
private readonly pool: Pool;
|
||||
|
||||
constructor(private configService: ConfigService) {
|
||||
const databaseUrl = configService.get<string>('DATABASE_URL');
|
||||
@@ -62,6 +63,8 @@ export class PrismaService
|
||||
],
|
||||
});
|
||||
|
||||
this.pool = pool;
|
||||
|
||||
// Log database queries in development mode
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
this.$on('query' as never, (e: QueryEvent) => {
|
||||
@@ -101,6 +104,7 @@ export class PrismaService
|
||||
async onModuleDestroy() {
|
||||
try {
|
||||
await this.$disconnect();
|
||||
await this.pool.end();
|
||||
this.logger.log('Successfully disconnected from database');
|
||||
} catch (error) {
|
||||
this.logger.error('Error disconnecting from database', error);
|
||||
|
||||
Reference in New Issue
Block a user