adapter-pg: connectToShadowDb connects to the main database when built from a connection string

Open Beginner friendly
#31,196 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@cestercian is already working on this.

Since Nov 24, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, postgresql, typescript
Domain
databases

Research direction

Start in packages/adapter-pg/src/pg.ts at PrismaPgAdapterFactory.connectToShadowDb() and follow how this.config is stored when the adapter is built from a connection string. Read pg/lib/connection-parameters.js to confirm the connection string overrides database. Change the shadow pool's config so the temporary database name wins, then add a unit test in the adapter-pg test suite asserting new pg.Client(pool.options).connectionParameters.database equals the temporary database name; done means that test passes for both string-built and object-built configs.

Written by the indexing model from the issue text.

Description

PrismaPgAdapterFactory.connectToShadowDb() in packages/adapter-pg/src/pg.ts creates a temporary database, prisma_migrate_shadow_db_<uuid>, and then opens a pool to it with:

const client = new pg.Pool({ ...this.config, database })

When the adapter was built from a connection string, this.config is { connectionString: 'postgresql://user:pass@host/maindb' }. pg merges a connection string over the other config fields when it connects (Object.assign({}, config, parse(config.connectionString)) in pg/lib/connection-parameters.js), so the database named in the URL wins over database. The "shadow" pool therefore connects to maindb, not to the temporary database.

Anything that then runs on the shadow connection, which migrate uses as a scratch database it can reset and replay migrations into, would run on the main database instead. The temporary database is created and dropped but never used.

connectToShadowDb is part of the driver adapter interface used for migrations with driver adapters. Nothing in this repository calls it today, so the reach depends on which tools use the adapter for migrations. Found during review of prisma/orm#29521; that pull request does not touch this code.

Fix: build the shadow pool's config so the temporary database wins, for example by parsing the connection string and replacing its database before creating the pool, and add a unit test that checks the effective database pg would connect to (new pg.Client(pool.options).connectionParameters.database).

Dominant language
TypeScript
Stars
47.8k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
227

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prisma/orm

All issues in prisma/orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.