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: changing environment label value to environment resource IDs (#4208)
Danny Xu28a9daffd106
diff --git a/frontend/src/utils/label.ts b/frontend/src/utils/label.tsindex f95aa859e3..831ad89b67 100644--- a/frontend/src/utils/label.ts+++ b/frontend/src/utils/label.ts@@ -218,7 +218,7 @@ export const getLabelValuesFromDatabaseList = (): string[] => {if (key === "bb.environment") {const environmentList = useEnvironmentStore().getEnvironmentList();- return environmentList.map((env) => env.name);+ return environmentList.map((env) => env.resourceId);}const labelList = databaseList.flatMap((db) =>diff --git a/store/database.go b/store/database.goindex ef26eac759..cdaa25a113 100644--- a/store/database.go+++ b/store/database.go@@ -100,10 +100,6 @@ func (s *Store) GetDatabase(ctx context.Context, find *api.DatabaseFind) (*api.D// private functions.func (s *Store) composeDatabase(ctx context.Context, database *DatabaseMessage) (*api.Database, error) {- environment, err := s.GetEnvironmentV2(ctx, &FindEnvironmentMessage{ResourceID: &database.EnvironmentID})- if err != nil {- return nil, err- }instance, err := s.GetInstanceV2(ctx, &FindInstanceMessage{ResourceID: &database.InstanceID})if err != nil {return nil, err@@ -146,16 +142,6 @@ func (s *Store) composeDatabase(ctx context.Context, database *DatabaseMessage)Value: value,})}- // Since tenants are identified by labels in deployment config, we need an environment- // label to identify tenants from different environment in a schema update deployment.- // If we expose the environment label concept in the deployment config, it should look consistent in the label API.- // Each database instance is created under a particular environment.- // The value of bb.environment is identical to the name of the environment.- // TODO(d): change the envir- labelList = append(labelList, &api.DatabaseLabel{- Key: api.EnvironmentLabelKey,- Value: environment.Title,- })labels, err := json.Marshal(labelList)if err != nil {return nil, err@@ -577,6 +563,10 @@ func (*Store) listDatabaseImplV2(ctx context.Context, tx *Tx, find *FindDatabase}databaseMessage.Labels[keys[i].String] = values[i].String}+ // System default environment label.+ // The value of bb.environment is resource ID of the environment.+ databaseMessage.Labels[api.EnvironmentLabelKey] = databaseMessage.EnvironmentID+databaseMessages = append(databaseMessages, &databaseMessage)}diff --git a/store/deploy.go b/store/deploy.goindex 45c17f9c26..8f455dfcc9 100644--- a/store/deploy.go+++ b/store/deploy.go@@ -73,8 +73,7 @@ func (s *Store) getDefaultDeploymentConfig(ctx context.Context, projectID int) (Spec: &api.DeploymentSpec{Selector: &api.LabelSelector{MatchExpressions: []*api.LabelSelectorRequirement{- // TODO(d): use environment ID for the label.- {Key: "bb.environment", Operator: api.InOperatorType, Values: []string{environment.Title}},+ {Key: "bb.environment", Operator: api.InOperatorType, Values: []string{environment.ResourceID}},},},},diff --git a/tests/tenant_test.go b/tests/tenant_test.goindex 6adf17ce93..ea51ee7e68 100644--- a/tests/tenant_test.go+++ b/tests/tenant_test.go@@ -1160,7 +1160,7 @@ func TestTenantVCSDatabaseNameTemplate_Empty(t *testing.T) {{Key: api.EnvironmentLabelKey,Operator: api.InOperatorType,- Values: []string{"Test"},+ Values: []string{"test"},},},},@@ -1444,7 +1444,7 @@ func TestTenantVCS_YAML(t *testing.T) {{Key: api.EnvironmentLabelKey,Operator: api.InOperatorType,- Values: []string{"Test"},+ Values: []string{"test"},},},},diff --git a/tests/tests.go b/tests/tests.goindex af5fab74b5..3256a55ec7 100644--- a/tests/tests.go+++ b/tests/tests.go@@ -97,7 +97,7 @@ CREATE TABLE book3 ({Key: api.EnvironmentLabelKey,Operator: api.InOperatorType,- Values: []string{"Test"},+ Values: []string{"test"},},{Key: api.TenantLabelKey,@@ -115,7 +115,7 @@ CREATE TABLE book3 ({Key: api.EnvironmentLabelKey,Operator: api.InOperatorType,- Values: []string{"Prod"},+ Values: []string{"prod"},},{Key: api.TenantLabelKey,