Skip to content

Commit

Permalink
fix: unknown database error
Browse files Browse the repository at this point in the history
This happens if the database returns Error 1049 / 42000 when the
database is not predefined.
  • Loading branch information
TrayserCassa committed Feb 17, 2025
1 parent a52aeff commit a8b8c8a
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 a8b8c8a

Please sign in to comment.