From ab2036f289aea40b81b626b1a1090d9bf786509e Mon Sep 17 00:00:00 2001 From: izzy Date: Thu, 29 Jan 2026 16:10:52 +0000 Subject: [PATCH] chore: add db switch back but with comments Signed-off-by: izzy --- server/src/utils/database-backups.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/utils/database-backups.ts b/server/src/utils/database-backups.ts index 4b568a5642..55459f714a 100644 --- a/server/src/utils/database-backups.ts +++ b/server/src/utils/database-backups.ts @@ -230,10 +230,14 @@ const SQL_RESET_SCHEMA = (username: string) => ` async function* sql(inputStream: Readable, databaseUsername: string, isPgClusterDump: boolean) { yield SQL_DROP_CONNECTIONS; - - if (!isPgClusterDump) { - yield SQL_RESET_SCHEMA(databaseUsername); - } + yield isPgClusterDump + ? // it is likely the dump contains SQL to try to drop the currently active + // database to ensure we have a fresh slate; if the `postgres` database exists + // then prefer to switch before continuing otherwise this will just silently fail + String.raw` + \c postgres + ` + : SQL_RESET_SCHEMA(databaseUsername); for await (const chunk of inputStream) { yield chunk;