-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: display the socket path during migration #24222
base: main
Are you sure you want to change the base?
feat: display the socket path during migration #24222
Conversation
That sounds pretty useful. Can you share an (of course anonymized) example of what such a connection string effectively looks like? (It seems that for PostgreSQL the "socket" is actually supplied via What "underlying prisma client connection messaging" do you mean? Most probably it comes from the Prisma engines (query and schema engine) with their codebases at https://github.com/prisma/prisma-engines. |
@janpio Here's an anonymized output from me running the CLI after my changes are applied.
The "underlying prisma client connection messaging" I meant is the error messaging that occurs if a database connection cannot be established. If we ever have problems with Prisma connecting to the database from Google Cloud Run we see error messages like "unable to connect to database at |
@@ -210,7 +210,9 @@ export function getDbLocation(credentials: DatabaseCredentials): string | undefi | |||
return credentials.uri! | |||
} | |||
|
|||
if (credentials.host && credentials.port) { | |||
if (credentials.socket) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also include the host
query parameter for PostgreSQL: https://www.prisma.io/docs/orm/overview/databases/postgresql#connecting-via-sockets Not sure how/if this is accessible here as credentials.host
seems to be the parsed hostname though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll handle the socket path supplied as host for PostgreSQL here. I think given that it's a unix socket I'll look for a host value that appears to be a unix-style path pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All set
So |
Yep, that's right. I'm happy to make the same code changes to |
Not necessary, but the right thing for consistency - as you raised yourself about the error message,, that would otherwise be misleading. |
5e6dc9b
to
ee93ebd
Compare
CodSpeed Performance ReportMerging #24222 will improve performances by 21.08%Comparing Summary
Benchmarks breakdown
|
In this update, I've modified the migrate tool to display the socket path if it configured in the database connection. The problem that this solves is, for organizations like mine that use Google's Cloud SQL, our connection strings always include
localhost:3306
and that actually does not indicate the true target database. Using Googlecloud-sql-proxy
, a unix socket is created to facilitate encrypted traffic to the database with Google IAM integration. This socket is named after the database you are connected to (e.g.orgname:us-west2:db-instance-name
). In our adoption of Prisma, we've actually had accidents occur where someone runs a migration against a cloud environment thinking they are doing it locally since the socket name is not advertised.An assumption I made in this PR is that any time a socket is supplied in the URL, it is the key indicator of the target database and completely takes over for
host:port
as the displayed identifier.I would have liked to update the underlying prisma client connection messaging as well because database errors uninformatively indicate a connection failure to
localhost:3306
and omit the socket name which is more important when debugging connectivity issues. I wasn't able to easily track down where this code lives and I was afraid of the widespread use of this. Truthfully, I'm way more worried about incorrectly applying migrations or performing database resets then debugging the Prisma client at runtime.