From a8b8c8afea4b1aab0032d3dfe5257d1f0e817ffb Mon Sep 17 00:00:00 2001 From: Patrick Derks Date: Mon, 17 Feb 2025 10:07:24 +0100 Subject: [PATCH] fix: unknown database error This happens if the database returns Error 1049 / 42000 when the database is not predefined. --- internal/util/db.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/util/db.go b/internal/util/db.go index 79f5ffa..54a3aa8 100644 --- a/internal/util/db.go +++ b/internal/util/db.go @@ -6,7 +6,7 @@ import ( "fmt" "net/url" - _ "github.com/go-sql-driver/mysql" + "github.com/go-sql-driver/mysql" v1 "github.com/shopware/shopware-operator/api/v1" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -88,5 +88,16 @@ func TestSQLConnection(ctx context.Context, database *v1.DatabaseSpec, host stri } //nolint:errcheck defer db.Close() - return db.PingContext(ctx) + err = db.PingContext(ctx) + + if mysqlErr, ok := err.(*mysql.MySQLError); ok { + // Error 1049 (42000): Unknown database + if mysqlErr.Number == 1049 { + return nil + } + } else { + return err + } + + return nil }