Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: only allow setting database parameter for Postgres (#3719)

Danny Xu3834cdf50760
diff --git a/server/component/dbfactory/dbfactory.go b/server/component/dbfactory/dbfactory.go
index c431d3f051..7f73774f22 100644
--- a/server/component/dbfactory/dbfactory.go
+++ b/server/component/dbfactory/dbfactory.go
@@ -41,6 +41,9 @@ func (d *DBFactory) GetAdminDatabaseDriver(ctx context.Context, instance *api.In
dbBinDir = d.pgBinDir
}
+ if databaseName == "" {
+ databaseName = instance.Database
+ }
driver, err := getDatabaseDriver(
ctx,
instance.Engine,
diff --git a/server/instance.go b/server/instance.go
index 81c10190ab..65a915ec53 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -441,6 +441,9 @@ func (s *Server) createInstance(ctx context.Context, create *api.InstanceCreate)
if err := s.disallowBytebaseStore(create.Engine, create.Host, create.Port); err != nil {
return nil, echo.NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}
+ if create.Engine != db.Postgres && create.Database != "" {
+ return nil, echo.NewHTTPError(http.StatusBadRequest, "database parameter is only allowed for Postgres")
+ }
instance, err := s.store.CreateInstance(ctx, create)
if err != nil {
@@ -483,16 +486,22 @@ func (s *Server) updateInstance(ctx context.Context, patch *api.InstancePatch) (
return nil, echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", patch.ID))
}
- host, port := instance.Host, instance.Port
+ host, port, database := instance.Host, instance.Port, instance.Database
if patch.Host != nil {
host = *patch.Host
}
if patch.Port != nil {
port = *patch.Port
}
+ if patch.Database != nil {
+ database = *patch.Database
+ }
if err := s.disallowBytebaseStore(instance.Engine, host, port); err != nil {
return nil, echo.NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}
+ if instance.Engine != db.Postgres && database != "" {
+ return nil, echo.NewHTTPError(http.StatusBadRequest, "database parameter is only allowed for Postgres")
+ }
var instancePatched *api.Instance
if patch.RowStatus != nil || patch.Name != nil || patch.ExternalLink != nil || patch.Host != nil || patch.Port != nil || patch.Database != nil {