Skip to content

Commit

Permalink
Merge pull request #87 from shopware/fix-db-check
Browse files Browse the repository at this point in the history
fix: unknown database error
  • Loading branch information
TrayserCassa authored Feb 18, 2025
2 parents 9a7ac88 + edb0c56 commit 83a5f58
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/util/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 83a5f58

Please sign in to comment.