Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: deprecate legacy deployment config API (#6429)
Danny Xub1a890066c3a
diff --git a/backend/server/project.go b/backend/server/project.goindex 2de2e9d8c9..115198729d 100644--- a/backend/server/project.go+++ b/backend/server/project.go@@ -10,7 +10,6 @@ import ("strings""time"- "github.com/google/jsonapi""github.com/labstack/echo/v4""github.com/pkg/errors"@@ -22,114 +21,6 @@ import ()func (s *Server) registerProjectRoutes(g *echo.Group) {- g.PATCH("/project/:id/deployment", func(c echo.Context) error {- ctx := c.Request().Context()- projectID, err := strconv.Atoi(c.Param("id"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)- }-- deploymentConfigUpsert := &api.DeploymentConfigUpsert{}- if err := jsonapi.UnmarshalPayload(c.Request().Body, deploymentConfigUpsert); err != nil {- return echo.NewHTTPError(http.StatusBadRequest, "Malformed set deployment configuration request").SetInternal(err)- }-- project, err := s.store.GetProjectV2(ctx, &store.FindProjectMessage{UID: &projectID})- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch project ID: %v", projectID)).SetInternal(err)- }- if project == nil {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project not found with ID %d", projectID))- }-- apiDeploymentConfig, err := api.ValidateAndGetDeploymentSchedule(deploymentConfigUpsert.Payload)- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Failed to validate deployment configuration: %v", err))- }-- // Remove this when we migrate to V1 API.- //- // Convert to store message.- var schedule store.Schedule- for _, d := range apiDeploymentConfig.Deployments {- var labelSelector store.LabelSelector- for _, spec := range d.Spec.Selector.MatchExpressions {- operatorTp := store.InOperatorType- switch spec.Operator {- case api.InOperatorType:- operatorTp = store.InOperatorType- case api.ExistsOperatorType:- operatorTp = store.ExistsOperatorType- }- labelSelector.MatchExpressions = append(labelSelector.MatchExpressions, &store.LabelSelectorRequirement{- Key: spec.Key,- Operator: operatorTp,- Values: spec.Values,- })- }- schedule.Deployments = append(schedule.Deployments, &store.Deployment{- Name: d.Name,- Spec: &store.DeploymentSpec{- Selector: &labelSelector,- },- })- }- storeDeploymentConfig := &store.DeploymentConfigMessage{- Name: deploymentConfigUpsert.Name,- Schedule: &schedule,- }-- newStoreDeploymentConfig, err := s.store.UpsertDeploymentConfigV2(ctx, projectID, c.Get(getPrincipalIDContextKey()).(int), storeDeploymentConfig)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to set deployment configuration").SetInternal(err)- }- newAPIDeploymentConfig, err := newStoreDeploymentConfig.ToAPIDeploymentConfig()- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to convert deployment configuration").SetInternal(err)- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, newAPIDeploymentConfig); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal set deployment configuration response").SetInternal(err)- }- return nil- })-- g.GET("/project/:id/deployment", func(c echo.Context) error {- ctx := c.Request().Context()- projectID, err := strconv.Atoi(c.Param("id"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)- }-- project, err := s.store.GetProjectV2(ctx, &store.FindProjectMessage{UID: &projectID})- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch project ID: %v", projectID)).SetInternal(err)- }- if project == nil {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project not found with ID %d", projectID))- }- if project.Deleted {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project %d is deleted", projectID))- }-- // DeploymentConfig is never nil.- deploymentConfig, err := s.store.GetDeploymentConfigV2(ctx, projectID)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to get deployment configuration for project id: %d", projectID)).SetInternal(err)- }- apiDeploymentConfig, err := deploymentConfig.ToAPIDeploymentConfig()- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to convert deployment config to api deployment config").SetInternal(err)- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, apiDeploymentConfig); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal get deployment configuration response: %v", projectID)).SetInternal(err)- }- return nil- })-g.POST("/project/:projectID/sync-sheet", func(c echo.Context) error {// TODO(tianzhou): uncomment this after adding the test harness to using Enterprise version.// if !s.licenseService.IsFeatureEnabled(api.FeatureVCSSheetSync) {diff --git a/backend/tests/ghost_test.go b/backend/tests/ghost_test.goindex b180669c31..94e6ba8e25 100644--- a/backend/tests/ghost_test.go+++ b/backend/tests/ghost_test.go@@ -277,12 +277,12 @@ func TestGhostTenant(t *testing.T) {}// Create deployment configuration.- _, err = ctl.upsertDeploymentConfig(- api.DeploymentConfigUpsert{- ProjectID: projectUID,+ _, err = ctl.projectServiceClient.UpdateDeploymentConfig(ctx, &v1pb.UpdateDeploymentConfigRequest{+ Config: &v1pb.DeploymentConfig{+ Name: fmt.Sprintf("%s/deploymentConfig", project.Name),+ Schedule: deploySchedule,},- deploymentSchedule,- )+ })a.NoError(err)// Create issues that create databases.diff --git a/backend/tests/project.go b/backend/tests/project.goindex d9ad49bee8..ef407ceabc 100644--- a/backend/tests/project.go+++ b/backend/tests/project.go@@ -1,15 +1,9 @@package testsimport (- "bytes""context"- "encoding/json""fmt"- "github.com/google/jsonapi"- "github.com/pkg/errors"-- api "github.com/bytebase/bytebase/backend/legacyapi"v1pb "github.com/bytebase/bytebase/proto/generated-go/v1")@@ -25,28 +19,3 @@ func (ctl *controller) createProject(ctx context.Context) (*v1pb.Project, error)ProjectId: projectID,})}--// upsertDeploymentConfig upserts the deployment configuration for a project.-func (ctl *controller) upsertDeploymentConfig(deploymentConfigUpsert api.DeploymentConfigUpsert, deploymentSchedule api.DeploymentSchedule) (*api.DeploymentConfig, error) {- scheduleBuf, err := json.Marshal(&deploymentSchedule)- if err != nil {- return nil, errors.Wrap(err, "failed to marshal deployment schedule")- }- deploymentConfigUpsert.Payload = string(scheduleBuf)-- buf := new(bytes.Buffer)- if err := jsonapi.MarshalPayload(buf, &deploymentConfigUpsert); err != nil {- return nil, errors.Wrap(err, "failed to marshal deployment config upsert")- }-- body, err := ctl.patch(fmt.Sprintf("/project/%d/deployment", deploymentConfigUpsert.ProjectID), buf)- if err != nil {- return nil, err- }-- deploymentConfig := new(api.DeploymentConfig)- if err = jsonapi.UnmarshalPayload(body, deploymentConfig); err != nil {- return nil, errors.Wrap(err, "fail to unmarshal upsert deployment config response")- }- return deploymentConfig, nil-}diff --git a/backend/tests/tenant_test.go b/backend/tests/tenant_test.goindex a6d621be48..a5b37b8e61 100644--- a/backend/tests/tenant_test.go+++ b/backend/tests/tenant_test.go@@ -110,12 +110,12 @@ func TestTenant(t *testing.T) {}// Create deployment configuration.- _, err = ctl.upsertDeploymentConfig(- api.DeploymentConfigUpsert{- ProjectID: projectUID,+ _, err = ctl.projectServiceClient.UpdateDeploymentConfig(ctx, &v1pb.UpdateDeploymentConfigRequest{+ Config: &v1pb.DeploymentConfig{+ Name: fmt.Sprintf("%s/deploymentConfig", project.Name),+ Schedule: deploySchedule,},- deploymentSchedule,- )+ })a.NoError(err)// Create issues that create databases.@@ -406,12 +406,12 @@ func TestTenantVCS(t *testing.T) {}// Create deployment configuration.- _, err = ctl.upsertDeploymentConfig(- api.DeploymentConfigUpsert{- ProjectID: projectUID,+ _, err = ctl.projectServiceClient.UpdateDeploymentConfig(ctx, &v1pb.UpdateDeploymentConfigRequest{+ Config: &v1pb.DeploymentConfig{+ Name: fmt.Sprintf("%s/deploymentConfig", project.Name),+ Schedule: deploySchedule,},- deploymentSchedule,- )+ })a.NoError(err)// Create issues that create databases.@@ -562,12 +562,12 @@ func TestTenantDatabaseNameTemplate(t *testing.T) {a.NoError(err)// Create deployment configuration.- _, err = ctl.upsertDeploymentConfig(- api.DeploymentConfigUpsert{- ProjectID: projectUID,+ _, err = ctl.projectServiceClient.UpdateDeploymentConfig(ctx, &v1pb.UpdateDeploymentConfigRequest{+ Config: &v1pb.DeploymentConfig{+ Name: fmt.Sprintf("%s/deploymentConfig", project.Name),+ Schedule: deploySchedule,},- deploymentSchedule,- )+ })a.NoError(err)// Create issues that create databases.@@ -863,12 +863,12 @@ func TestTenantVCSDatabaseNameTemplate(t *testing.T) {}// Create deployment configuration.- _, err = ctl.upsertDeploymentConfig(- api.DeploymentConfigUpsert{- ProjectID: projectUID,+ _, err = ctl.projectServiceClient.UpdateDeploymentConfig(ctx, &v1pb.UpdateDeploymentConfigRequest{+ Config: &v1pb.DeploymentConfig{+ Name: fmt.Sprintf("%s/deploymentConfig", project.Name),+ Schedule: deploySchedule,},- deploymentSchedule,- )+ })a.NoError(err)// Create issues that create databases.@@ -1142,21 +1142,21 @@ func TestTenantVCSDatabaseNameTemplate_Empty(t *testing.T) {}// Create deployment configuration.- _, err = ctl.upsertDeploymentConfig(- api.DeploymentConfigUpsert{- ProjectID: projectUID,- },- api.DeploymentSchedule{- Deployments: []*api.Deployment{- {- Name: "Test stage",- Spec: &api.DeploymentSpec{- Selector: &api.LabelSelector{- MatchExpressions: []*api.LabelSelectorRequirement{- {- Key: api.EnvironmentLabelKey,- Operator: api.InOperatorType,- Values: []string{"test"},+ _, err = ctl.projectServiceClient.UpdateDeploymentConfig(ctx, &v1pb.UpdateDeploymentConfigRequest{+ Config: &v1pb.DeploymentConfig{+ Name: fmt.Sprintf("%s/deploymentConfig", project.Name),+ Schedule: &v1pb.Schedule{+ Deployments: []*v1pb.ScheduleDeployment{+ {+ Title: "Test stage",+ Spec: &v1pb.DeploymentSpec{+ LabelSelector: &v1pb.LabelSelector{+ MatchExpressions: []*v1pb.LabelSelectorRequirement{+ {+ Key: api.EnvironmentLabelKey,+ Operator: v1pb.OperatorType_OPERATOR_TYPE_IN,+ Values: []string{"test"},+ },},},},@@ -1164,7 +1164,7 @@ func TestTenantVCSDatabaseNameTemplate_Empty(t *testing.T) {},},},- )+ })a.NoError(err)// Create issues that create databases.@@ -1408,21 +1408,21 @@ func TestTenantVCS_YAML(t *testing.T) {}// Create deployment configuration.- _, err = ctl.upsertDeploymentConfig(- api.DeploymentConfigUpsert{- ProjectID: projectUID,- },- api.DeploymentSchedule{- Deployments: []*api.Deployment{- {- Name: "Test stage",- Spec: &api.DeploymentSpec{- Selector: &api.LabelSelector{- MatchExpressions: []*api.LabelSelectorRequirement{- {- Key: api.EnvironmentLabelKey,- Operator: api.InOperatorType,- Values: []string{"test"},+ _, err = ctl.projectServiceClient.UpdateDeploymentConfig(ctx, &v1pb.UpdateDeploymentConfigRequest{+ Config: &v1pb.DeploymentConfig{+ Name: fmt.Sprintf("%s/deploymentConfig", project.Name),+ Schedule: &v1pb.Schedule{+ Deployments: []*v1pb.ScheduleDeployment{+ {+ Title: "Test stage",+ Spec: &v1pb.DeploymentSpec{+ LabelSelector: &v1pb.LabelSelector{+ MatchExpressions: []*v1pb.LabelSelectorRequirement{+ {+ Key: api.EnvironmentLabelKey,+ Operator: v1pb.OperatorType_OPERATOR_TYPE_IN,+ Values: []string{"test"},+ },},},},@@ -1430,7 +1430,7 @@ func TestTenantVCS_YAML(t *testing.T) {},},},- )+ })a.NoError(err)// Create issues that create databases.diff --git a/backend/tests/tests.go b/backend/tests/tests.goindex 872263b22e..0b828097fe 100644--- a/backend/tests/tests.go+++ b/backend/tests/tests.go@@ -111,39 +111,39 @@ CREATE TABLE book4 (name TEXT NULL);`- deploymentSchedule = api.DeploymentSchedule{- Deployments: []*api.Deployment{+ deploySchedule = &v1pb.Schedule{+ Deployments: []*v1pb.ScheduleDeployment{{- Name: "Test stage",- Spec: &api.DeploymentSpec{- Selector: &api.LabelSelector{- MatchExpressions: []*api.LabelSelectorRequirement{+ Title: "Test stage",+ Spec: &v1pb.DeploymentSpec{+ LabelSelector: &v1pb.LabelSelector{+ MatchExpressions: []*v1pb.LabelSelectorRequirement{{Key: api.EnvironmentLabelKey,- Operator: api.InOperatorType,+ Operator: v1pb.OperatorType_OPERATOR_TYPE_IN,Values: []string{"test"},},{Key: api.TenantLabelKey,- Operator: api.ExistsOperatorType,+ Operator: v1pb.OperatorType_OPERATOR_TYPE_EXISTS,},},},},},{- Name: "Prod stage",- Spec: &api.DeploymentSpec{- Selector: &api.LabelSelector{- MatchExpressions: []*api.LabelSelectorRequirement{+ Title: "Prod stage",+ Spec: &v1pb.DeploymentSpec{+ LabelSelector: &v1pb.LabelSelector{+ MatchExpressions: []*v1pb.LabelSelectorRequirement{{Key: api.EnvironmentLabelKey,- Operator: api.InOperatorType,+ Operator: v1pb.OperatorType_OPERATOR_TYPE_IN,Values: []string{"prod"},},{Key: api.TenantLabelKey,- Operator: api.ExistsOperatorType,+ Operator: v1pb.OperatorType_OPERATOR_TYPE_EXISTS,},},},