Hi, I am relatively new to prisma. So far it is a ...
# orm-help
m
Hi, I am relatively new to prisma. So far it is a good experience. Couple of questions: 1.) Is there any best practise how to check for a K8S readiness check if the client can access the DB ? 2.) can the client create the DB if the DB etc doesn't exists instead of doing a manual prisma migrate or is the best the mount the SQL to postgres ( as I am using postgres ) ? Thx in advance
n
Hey Michael šŸ‘‹ great to hear you have a good experience with Prisma so far!
1.) Is there any best practise how to check for a K8S readiness check if the client can access the DB ?
I'm not super familiar with Kubernetes unfortunately, can you maybe elaborate a bit on your question? Are you wondering if a
PrismaClient
instance has an open DB connection or what exactly are you trying to find out?
2.) can the client create the DB if the DB etc doesn't exists instead of doing a manual prisma migrateĀ or is the best the mount the SQL to postgres ( as I am using postgres ) ?
PrismaClient
currently is mostly used to perform data manipulation queries, but not to create/migrate the actual DB and its schema. So yeah, you probably need to either run raw SQL commands or run the
prisma migrate
CLI commands programmatically in Node.js. Does that help? šŸ™‚
k
regarding 1. im currently using the aws ec2 health check which i believe is similar to the k8s readiness check. To ensure that there is a healthy connection to the database for my Express Apollo Server, I use the onHealthCheck middleware.
Copy code
server.applyMiddleware({
  app,
  cors: {
    origin: [
    'values here',
    ],
  },
  onHealthCheck: () => {
    return new Promise(async (resolve, reject) => {
      const result = await prisma.$queryRaw`SELECT 1+1 as serverCheck`;

      if (result[0].serverCheck === 2) {
        resolve();
      } else {
        reject();
      }
    });
  },
});
This will then respond to requests from /.well-known/apollo/server-health with either 200 or 500 response code. Not sure if the above helps at all for what you are looking for.