If someone can help me put the pieces of my puzzle...
# orm-help
m
If someone can help me put the pieces of my puzzle together - I would greatly appreciate it. The problem: I have CD set up to create containers to use in GCP Cloud Run. However, for my image to successfully create a container, it seems like Prisma has to be able to connect to the DB, which is hosted on Cloud SQL. However, I'm trying to connect a Cloud Run service to the DB - but the image can't create a container unless Prisma is connected to the DB... Clearly there's a lot of cloud mess to fix here, but this problem does seem unique to Prisma (as far as I can tell), so I thought I'd give it a shot asking here. One last piece of the puzzle - and maybe this actually helps. GCP points toward this repo in its primer on connecting Cloud Run to Cloud SQL. In it, they specify how to initialize a TCP connection pool for Cloud SQL. https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/HEAD/cloud-sql/mysql/mysql/connect-tcp.js
l
This might be one of the pieces you're looking for. I'm also using CloudSQL but running Prisma inside a Cloud Function. I also ran into issues connecting Prisma within the cloud but found that you need to use a socket connection when deployed:
DATABASE_URL=mysql://${DB_USER}:${DB_PASS}@${DB_HOST}/${DB_DATABASE}?socket=/cloudsql/${CLOUD_SQL_INSTANCE_CONNECTION_NAME}&connection_limit=50&pool_timeout=30
In order to develop locally though, you will need to have a
.env
with this inside, and another
.env.local
without the socket so that you can connect to CloudSQL locally. And when you do any kind of
prisma.schema
manipulation then you'll need to remove the socket part manually before you can migrate/push/pull.
m
Yikes! Lol. Thank you for the reply.
@Lloyd Richards Should the DB_HOST be the public IP address on the Cloud SQL instance?
l
Yep yep, you should both in the CloudSQL console
DB_HOST and CLOUD_SQL_INSTANCE_CONNECTION_NAME