From f17f17d345b85b7a2833eb26472b8ddf0a7ae37b Mon Sep 17 00:00:00 2001 From: Alexey Zakhlestin Date: Thu, 7 Nov 2024 22:06:25 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Use=20URL=20instead=20of=20regex?= =?UTF-8?q?=20for=20shadow-db=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/migrator/src/migrator.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/migrator/src/migrator.ts b/packages/migrator/src/migrator.ts index 09fb585c..5e568270 100644 --- a/packages/migrator/src/migrator.ts +++ b/packages/migrator/src/migrator.ts @@ -728,7 +728,11 @@ export class Migrator { */ async useShadowClient(cb: (client: Client) => Promise) { 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 {