Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: archive checker for instance (#1473)
qsliu72a5cc433dab
diff --git a/server/instance.go b/server/instance.goindex c07e04f9c8..6c3b5ceafe 100644--- a/server/instance.go+++ b/server/instance.go@@ -5,6 +5,7 @@ import ("fmt""net/http""strconv"+ "strings""github.com/google/jsonapi""github.com/labstack/echo/v4"@@ -149,6 +150,24 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {return err}}+ // Ensure all databases belong to this instance are under the default project before instance is archived.+ if v := instancePatch.RowStatus; v != nil && *v == api.Archived.String() {+ databases, err := s.store.FindDatabase(ctx, &api.DatabaseFind{InstanceID: &id})+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError,+ fmt.Errorf("Failed to find databases in the instance %d", id)).SetInternal(err)+ }+ var databaseNameList []string+ for _, database := range databases {+ if database.ProjectID != api.DefaultProjectID {+ databaseNameList = append(databaseNameList, database.Name)+ }+ }+ if len(databaseNameList) > 0 {+ return echo.NewHTTPError(http.StatusBadRequest,+ fmt.Sprintf("You should transfer these databases to the default project before archiving the instance: %s.", strings.Join(databaseNameList, ", ")))+ }+ }instancePatched, err = s.store.PatchInstance(ctx, instancePatch)if err != nil {if common.ErrorCode(err) == common.NotFound {