Skip to content

Commit 5721266

Browse files
domdomeggclaude
andcommitted
Make template database error handling more specific
Check for exact constraint name (pg_database_datname_index) when handling duplicate database creation errors to avoid masking other 23505 errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5e2de5d commit 5721266

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

internal/database/testutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func ensureTemplateDB(ctx context.Context, adminConn *pgx.Conn) error {
3434
// Create template database
3535
_, err = adminConn.Exec(ctx, fmt.Sprintf("CREATE DATABASE %s", templateDBName))
3636
if err != nil {
37-
// Ignore duplicate error - another process created it concurrently
37+
// Ignore duplicate database name error - another process created it concurrently
3838
var pgErr *pgconn.PgError
39-
if errors.As(err, &pgErr) && pgErr.Code == "23505" {
39+
if errors.As(err, &pgErr) && pgErr.Code == "23505" && pgErr.ConstraintName == "pg_database_datname_index" {
4040
return nil
4141
}
4242
return fmt.Errorf("failed to create template database: %w", err)

0 commit comments

Comments
 (0)