MCPcopy
hub / github.com/prisma/prisma / getPpgInfo

Function getPpgInfo

packages/cli/src/utils/ppgInfo.ts:7–35  ·  view source on GitHub ↗
(connectionString: string)

Source from the content-addressed store, hash-verified

5 * Mimicking parts of the tracking logic in the Prisma VSCode extension.
6 */
7export async function getPpgInfo(connectionString: string) {
8 const url = new URL(connectionString)
9 const isLocalhost =
10 url.hostname === 'localhost' ||
11 url.hostname === '127.0.0.1' ||
12 url.hostname === '[::1]' ||
13 url.hostname === '[0:0:0:0:0:0:0:1]'
14
15 let type: 'remote' | 'local' | undefined
16 if (url.protocol === 'prisma+postgres:' && url.hostname === 'accelerate.prisma-data.net') {
17 type = 'remote'
18 } else if ((url.protocol === 'postgres:' || url.protocol === 'postgresql:') && url.hostname === 'db.prisma.io') {
19 type = 'remote'
20 } else if (url.protocol === 'prisma+postgres:' && isLocalhost) {
21 type = 'local'
22 } else if ((url.protocol === 'postgres:' || url.protocol === 'postgresql:') && isLocalhost) {
23 const servers = await ServerState.scan()
24 for (const server of servers) {
25 if (
26 server.status === 'running' &&
27 [server.databasePort, server.shadowDatabasePort].includes(parseInt(url.port ?? ''))
28 ) {
29 type = 'local'
30 }
31 }
32 }
33
34 return type ? { ppg: { type } } : {}
35}

Callers 2

parseMethod · 0.90
ppgInfo.test.tsFile · 0.90

Calls 1

includesMethod · 0.80

Tested by

no test coverage detected