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: no deployment config other than the default one (#15440)
p0nya885f791fd01
diff --git a/backend/store/deploy.go b/backend/store/deploy.goindex 1c529cfcef..3ba2b945fd 100644--- a/backend/store/deploy.go+++ b/backend/store/deploy.go@@ -2,16 +2,8 @@ package storeimport ("context"- "database/sql"- "fmt"- "strings"-- "github.com/pkg/errors"- "google.golang.org/protobuf/encoding/protojson"storepb "github.com/bytebase/bytebase/proto/generated-go/store"-- "github.com/bytebase/bytebase/backend/common")// DeploymentConfigMessage is the message for deployment config.@@ -21,101 +13,8 @@ type DeploymentConfigMessage struct {}// GetDeploymentConfigV2 returns the deployment config.-func (s *Store) GetDeploymentConfigV2(ctx context.Context, projectID string) (*DeploymentConfigMessage, error) {- if v, ok := s.projectDeploymentCache.Get(projectID); ok {- return v, nil- }- where, args := []string{"TRUE"}, []any{}- where, args = append(where, fmt.Sprintf("project = $%d", len(args)+1)), append(args, projectID)-- deploymentConfig := DeploymentConfigMessage{- Config: &storepb.DeploymentConfig{},- }- var configB []byte-- tx, err := s.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})- if err != nil {- return nil, errors.Wrap(err, "failed to begin transaction")- }- defer tx.Rollback()-- if err := tx.QueryRowContext(ctx, `- SELECT- name,- config- FROM deployment_config- WHERE `+strings.Join(where, " AND "),- args...,- ).Scan(&deploymentConfig.Name, &configB); err != nil {- if err == sql.ErrNoRows {- // Return default deployment config.- return s.getDefaultDeploymentConfigV2(ctx)- }- return nil, errors.Wrapf(err, "failed to scan")- }-- if err := tx.Commit(); err != nil {- return nil, errors.Wrapf(err, "failed to commit transaction")- }-- if err := common.ProtojsonUnmarshaler.Unmarshal(configB, deploymentConfig.Config); err != nil {- return nil, errors.Wrapf(err, "failed to unmarshal")- }-- s.projectDeploymentCache.Add(projectID, &deploymentConfig)- return &deploymentConfig, nil-}--// UpsertDeploymentConfigV2 upserts the deployment config.-func (s *Store) UpsertDeploymentConfigV2(ctx context.Context, projectID string, upsert *DeploymentConfigMessage) (*DeploymentConfigMessage, error) {- configB, err := protojson.Marshal(upsert.Config)- if err != nil {- return nil, errors.Wrapf(err, "failed to marshal deployment config")- }-- query := `- INSERT INTO deployment_config (- project,- name,- config- )- VALUES ($1, $2, $3)- ON CONFLICT(project) DO UPDATE SET- name = excluded.name,- config = excluded.config- RETURNING name, config- `- deploymentConfig := DeploymentConfigMessage{- Config: &storepb.DeploymentConfig{},- }- var newConfigB []byte-- tx, err := s.db.BeginTx(ctx, nil)- if err != nil {- return nil, errors.Wrap(err, "failed to begin transaction")- }- defer tx.Rollback()-- if err := tx.QueryRowContext(ctx, query,- projectID,- upsert.Name,- configB,- ).Scan(&deploymentConfig.Name, &newConfigB); err != nil {- if err == sql.ErrNoRows {- return nil, common.FormatDBErrorEmptyRowWithQuery(query)- }- return nil, err- }- if err := tx.Commit(); err != nil {- return nil, errors.Wrapf(err, "failed to commit transaction")- }-- if err := common.ProtojsonUnmarshaler.Unmarshal(newConfigB, deploymentConfig.Config); err != nil {- return nil, errors.Wrapf(err, "failed to unmarshal")- }-- s.projectDeploymentCache.Add(projectID, &deploymentConfig)- return &deploymentConfig, nil+func (s *Store) GetDeploymentConfigV2(ctx context.Context, _ string) (*DeploymentConfigMessage, error) {+ return s.getDefaultDeploymentConfigV2(ctx)}func (s *Store) getDefaultDeploymentConfigV2(ctx context.Context) (*DeploymentConfigMessage, error) {@@ -124,11 +23,11 @@ func (s *Store) getDefaultDeploymentConfigV2(ctx context.Context) (*DeploymentCoreturn nil, err}var deployments []*storepb.ScheduleDeployment- for i, environment := range environmentList {+ for _, environment := range environmentList {deployments = append(deployments, &storepb.ScheduleDeployment{Title: environment.ResourceID,- // Use index rather than uuid to ensure consistent Id for the default deployment config.- Id: fmt.Sprintf("%d", i),+ // Use environment resource id rather than uuid to ensure consistent Id for the default deployment config.+ Id: environment.ResourceID,Spec: &storepb.DeploymentSpec{Selector: &storepb.LabelSelector{MatchExpressions: []*storepb.LabelSelectorRequirement{diff --git a/backend/store/store.go b/backend/store/store.goindex 32c9f4d615..210e0f1923 100644--- a/backend/store/store.go+++ b/backend/store/store.go@@ -18,24 +18,23 @@ type Store struct {db *DBprofile *config.Profile- userIDCache *lru.Cache[int, *UserMessage]- userEmailCache *lru.Cache[string, *UserMessage]- environmentCache *lru.Cache[string, *EnvironmentMessage]- instanceCache *lru.Cache[string, *InstanceMessage]- databaseCache *lru.Cache[string, *DatabaseMessage]- projectCache *lru.Cache[string, *ProjectMessage]- projectDeploymentCache *lru.Cache[string, *DeploymentConfigMessage]- policyCache *lru.Cache[string, *PolicyMessage]- issueCache *lru.Cache[int, *IssueMessage]- issueByPipelineCache *lru.Cache[int, *IssueMessage]- pipelineCache *lru.Cache[int, *PipelineMessage]- settingCache *lru.Cache[api.SettingName, *SettingMessage]- idpCache *lru.Cache[string, *IdentityProviderMessage]- risksCache *lru.Cache[int, []*RiskMessage] // Use 0 as the key.- databaseGroupCache *lru.Cache[string, *DatabaseGroupMessage]- rolesCache *lru.Cache[string, *RoleMessage]- groupCache *lru.Cache[string, *GroupMessage]- sheetCache *lru.Cache[int, *SheetMessage]+ userIDCache *lru.Cache[int, *UserMessage]+ userEmailCache *lru.Cache[string, *UserMessage]+ environmentCache *lru.Cache[string, *EnvironmentMessage]+ instanceCache *lru.Cache[string, *InstanceMessage]+ databaseCache *lru.Cache[string, *DatabaseMessage]+ projectCache *lru.Cache[string, *ProjectMessage]+ policyCache *lru.Cache[string, *PolicyMessage]+ issueCache *lru.Cache[int, *IssueMessage]+ issueByPipelineCache *lru.Cache[int, *IssueMessage]+ pipelineCache *lru.Cache[int, *PipelineMessage]+ settingCache *lru.Cache[api.SettingName, *SettingMessage]+ idpCache *lru.Cache[string, *IdentityProviderMessage]+ risksCache *lru.Cache[int, []*RiskMessage] // Use 0 as the key.+ databaseGroupCache *lru.Cache[string, *DatabaseGroupMessage]+ rolesCache *lru.Cache[string, *RoleMessage]+ groupCache *lru.Cache[string, *GroupMessage]+ sheetCache *lru.Cache[int, *SheetMessage]// Large objects.sheetStatementCache *lru.Cache[int, string]@@ -68,10 +67,6 @@ func New(db *DB, profile *config.Profile) (*Store, error) {if err != nil {return nil, err}- projectDeploymentCache, err := lru.New[string, *DeploymentConfigMessage](128)- if err != nil {- return nil, err- }policyCache, err := lru.New[string, *PolicyMessage](128)if err != nil {return nil, err@@ -130,26 +125,25 @@ func New(db *DB, profile *config.Profile) (*Store, error) {profile: profile,// Cache.- userIDCache: userIDCache,- userEmailCache: userEmailCache,- environmentCache: environmentCache,- instanceCache: instanceCache,- databaseCache: databaseCache,- projectCache: projectCache,- projectDeploymentCache: projectDeploymentCache,- policyCache: policyCache,- issueCache: issueCache,- issueByPipelineCache: issueByPipelineCache,- pipelineCache: pipelineCache,- settingCache: settingCache,- idpCache: idpCache,- risksCache: risksCache,- databaseGroupCache: databaseGroupCache,- rolesCache: rolesCache,- sheetCache: sheetCache,- sheetStatementCache: sheetStatementCache,- dbSchemaCache: dbSchemaCache,- groupCache: groupCache,+ userIDCache: userIDCache,+ userEmailCache: userEmailCache,+ environmentCache: environmentCache,+ instanceCache: instanceCache,+ databaseCache: databaseCache,+ projectCache: projectCache,+ policyCache: policyCache,+ issueCache: issueCache,+ issueByPipelineCache: issueByPipelineCache,+ pipelineCache: pipelineCache,+ settingCache: settingCache,+ idpCache: idpCache,+ risksCache: risksCache,+ databaseGroupCache: databaseGroupCache,+ rolesCache: rolesCache,+ sheetCache: sheetCache,+ sheetStatementCache: sheetStatementCache,+ dbSchemaCache: dbSchemaCache,+ groupCache: groupCache,}, nil}