I'm trying here to connect a Cloud SQL postgres database from a NestJS server (using prisma as an ORM).
This is the file I'm using to establish the database connection:
schema.prisma:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
And the DATABASE_URL env variable looks like this:
postgres://postgres:secret@DATABASE_PUBLIC_IP/postgres?socket=/cloudsql/PROJECT_ID:CONNECTION_NAME:production&schema=public&sslmode=prefer
Everything works fine on my local environment, but when I try to deploy it to the cloud it doesn't work...
My Dockerfile:
FROM node:14
RUN apt-get update && apt-get install -y postgresql-client
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
COPY prisma ./prisma/
EXPOSE 3000
RUN npm run prisma:generate
RUN npm run start:dev
The error I get: