terminus icon indicating copy to clipboard operation
terminus copied to clipboard

Support for Prisma ORM

Open TasinIshmam opened this issue 3 years ago β€’ 5 comments

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe it

Terminus is quite useful for checking the health of your database and it would be great if it would support Prisma ORM.

Describe the solution you'd like

Support for Prisma ORM, similar to TypeOrmHealthIndicator , SequelizeHealthIndicator and MongooseHealthIndicator.

Teachability, documentation, adoption, migration strategy

The terminus recipe in the NestJS docs would need to be updated with a PrismaHealthIndicator.

To the best of my understanding, the change to the documentation would be fairly minimal.

What is the motivation / use case for changing the behavior?

I work at Prisma and we have seen a lot of NestJS users adopting Prisma for the ORM layer in their application. So having better support for the ORM would be great for developers using NestJS with Prisma!

TasinIshmam avatar Oct 22 '21 08:10 TasinIshmam

It looks like it could be as easy as duplicating the typeorm one here and adapting it (removing things) https://github.com/nestjs/terminus/blob/master/lib/health-indicator/database/typeorm.health.ts#L110 With Prisma we could do prisma.$queryRawSELECT 1` for SQL databases, for MongoDB (in Preview) I'm not sure how it can be done, maybe that would need a feature request here

Jolg42 avatar Oct 22 '21 08:10 Jolg42

Thanks for the suggestion! I am open to review any PRs around this!

BrunnerLivio avatar Nov 16 '21 15:11 BrunnerLivio

@BrunnerLivio

I was actually looking into this, but it seems all the database connectors have a corresponding nestjs library (ex: TypeOrm has @nestjs/typeorm). From that sense, it's much more than a PR.

I'm happy to throw together a health indicator for this repo, but creating a new @nestjs/prisma module is an area I'm sure I'm missing a lot of context and frankly, necessary time to complete.

Thoughts?

jfairley avatar Jun 15 '22 15:06 jfairley

Btw, in case anyone comes here and just wants a simple health indicator, I have a Stackoverflow answer for it.

https://stackoverflow.com/a/71445270/317951

import { Injectable } from "@nestjs/common";
import { HealthCheckError, HealthIndicator, HealthIndicatorResult } from "@nestjs/terminus";
import { PrismaService } from "./prisma.service";

@Injectable()
export class PrismaHealthIndicator extends HealthIndicator {
  constructor(private readonly prismaService: PrismaService) {
    super();
  }

  async isHealthy(key: string): Promise<HealthIndicatorResult> {
    try {
      await this.prismaService.$queryRaw`SELECT 1`;
      return this.getStatus(key, true);
    } catch (e) {
      throw new HealthCheckError("Prisma check failed", e);
    }
  }
}

jfairley avatar Jun 15 '22 15:06 jfairley

@jfairley this is not working for me it shows the error " Prisma check failed"

shahmir2000 avatar Sep 16 '22 08:09 shahmir2000

@ThallesP has created an inital PR for this and we've merged it into our next-branch which targets Terminus v10. Prisma client seems to have dropped support for Node v12 hence why I'd need to drop it as well which I can't do with Terminus v9 (it's considered a breaking change). At the moment there are still some things to figure out though since Prisma seems to be quite tedious because of its bindings hence why the Pipeline is failing at the moment. Once that is figured out I'll try to release a beta release of v10 with the Prisma health indicator included

BrunnerLivio avatar Apr 24 '23 22:04 BrunnerLivio

This has been released with @nestjs/[email protected] (unstable). πŸŽ‰ If you wanna try it out, follow the instructions here

BrunnerLivio avatar Apr 25 '23 11:04 BrunnerLivio

@BrunnerLivio When should we expect for v10 to be out?

Scalahansolo avatar Jun 12 '23 23:06 Scalahansolo

It’s released πŸŽ‰

BrunnerLivio avatar Jun 17 '23 09:06 BrunnerLivio