Skip to content

Commit

Permalink
fix(dbmanager): use correct SQL to drop databases (#3640)
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
scottt authored Oct 9, 2024
1 parent acf296d commit 695d9a1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/dbmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 695d9a1

Please sign in to comment.