Skip to content

Commit

Permalink
🐛 Use URL instead of regex for shadow-db name
Browse files Browse the repository at this point in the history
connectionString is a URL, so it should be treated as such. regex didn't
handle more complex cases (such as "-" in the name of database).

And while it is possible to tweak regex for greater compatibility, using
actual URL-object guarantees proper result in ALL cases.

#434
  • Loading branch information
indeyets committed Nov 7, 2024
1 parent 1840012 commit f17f17d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/migrator/src/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,11 @@ export class Migrator {
*/
async useShadowClient<T>(cb: (client: Client) => Promise<T>) {
const shadowDbName = `shadow_${Date.now()}_${randomInt(1_000_000)}`
const shadowConnectionString = this.client.connectionString().replace(/\w+$/, shadowDbName)

const shadowConnectionUrl = new URL(this.client.connectionString());
shadowConnectionUrl.pathname = shadowDbName;
const shadowConnectionString = shadowConnectionUrl.toString();

const shadowClient = createClient(shadowConnectionString, this.client.options)

try {
Expand Down

0 comments on commit f17f17d

Please sign in to comment.