From e9ecbd2dd477c8cfff10b2b1b3db5107b427138a Mon Sep 17 00:00:00 2001 From: Scott Tsai Date: Tue, 8 Oct 2024 18:19:05 +0800 Subject: [PATCH] fix(dbmanager): use correct SQL to drop databases Previously the code used: ``` DROP DATABASE mydb IF EXISTS WITH (FORCE) ``` which is not standard SQL and does not work with PostgreSQL. This patch fixes to code to issue: ``` DROP DATABASE IF EXISTS mydb WITH (FORCE) ``` --- internal/dbmanager/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/dbmanager/client.go b/internal/dbmanager/client.go index c189da5552..18aec947cb 100644 --- a/internal/dbmanager/client.go +++ b/internal/dbmanager/client.go @@ -106,7 +106,7 @@ func (m *ManagedClient) CreateDatabase(ctx context.Context, req *CreateDatabaseR conn, err := pgx.Connect(ctx, uri.String()) if err != nil { - pool.Exec(ctx, fmt.Sprintf(`DROP DATABASE "%s" IF EXISTS WITH (FORCE)`, name)) + pool.Exec(ctx, fmt.Sprintf(`DROP DATABASE IF EXISTS "%s" WITH (FORCE)`, name)) return nil, fmt.Errorf("connect %s: %s", name, err) } defer conn.Close(ctx) @@ -123,7 +123,7 @@ func (m *ManagedClient) CreateDatabase(ctx context.Context, req *CreateDatabaseR } if migrationErr != nil { - pool.Exec(ctx, fmt.Sprintf(`DROP DATABASE "%s" IF EXISTS WITH (FORCE)`, name)) + pool.Exec(ctx, fmt.Sprintf(`DROP DATABASE IF EXISTS "%s" WITH (FORCE)`, name)) return nil, migrationErr }