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(review): switch every standard rule on for a new workspace
rebelicee063a25b500e
diff --git a/backend/api/v1/org_policy_service.go b/backend/api/v1/org_policy_service.goindex 6cb42e2e89..98e62e6bc9 100644--- a/backend/api/v1/org_policy_service.go+++ b/backend/api/v1/org_policy_service.go@@ -370,9 +370,10 @@ func (*OrgPolicyService) getDefaultRolloutPolicy(parent string) (*store.PolicyMe}// getDefaultReviewRulePolicy returns the review rule policy that stands in for-// a missing workspace row: every rule on, the default the store applies when-// neither the project nor the workspace has a policy. A project without its-// own policy follows the workspace's, so it has no stand-in and gets nil.+// a missing workspace row, which workspaces created before the default row+// lack: every rule on, the default the store applies when neither the project+// nor the workspace has a policy. A project without its own policy follows the+// workspace's, so it has no stand-in and gets nil.func getDefaultReviewRulePolicy(parent string) (*store.PolicyMessage, error) {resourceType, resource, err := common.GetPolicyResourceTypeAndResource(parent)if err != nil {diff --git a/backend/store/policy.go b/backend/store/policy.goindex 2aff186dc2..b9bd331f05 100644--- a/backend/store/policy.go+++ b/backend/store/policy.go@@ -462,9 +462,10 @@ func (s *Store) getQueryDataPolicy(ctx context.Context, workspaceID string, resoreturn p, nil}-// GetDefaultReviewRulePolicy returns the review rule policy in force when-// neither the project nor the workspace has one: every standard rule on. A-// rule added to ReviewRuleType is added here in the same release.+// GetDefaultReviewRulePolicy returns the review rule policy a new workspace+// starts with, and the one in force when neither the project nor the+// workspace has one: every standard rule on. A rule added to ReviewRuleType+// is added here in the same release.func GetDefaultReviewRulePolicy() *storepb.ReviewRulePolicy {return &storepb.ReviewRulePolicy{Rules: []storepb.ReviewRuleType{storepb.ReviewRuleType_SYNTAX,diff --git a/backend/store/workspace.go b/backend/store/workspace.goindex 9d903fa407..2a1fbb6245 100644--- a/backend/store/workspace.go+++ b/backend/store/workspace.go@@ -191,6 +191,20 @@ func (s *Store) CreateWorkspace(ctx context.Context, create *WorkspaceMessage, areturn nil, errors.Wrap(err, "failed to create workspace IAM policy")}+ // Every standard SQL review rule starts on. The workspace SQL Review page+ // updates this row, so it exists from the start.+ reviewRulePayload, err := protojson.Marshal(GetDefaultReviewRulePolicy())+ if err != nil {+ return nil, errors.Wrap(err, "failed to marshal review rule policy")+ }+ if _, err := tx.ExecContext(ctx,+ `INSERT INTO policy (workspace, resource_type, resource, type, payload, inherit_from_parent, enforce)+ VALUES ($1, 'WORKSPACE', 'workspaces/' || $1, 'REVIEW_RULE', $2, FALSE, TRUE)`,+ create.ResourceID, string(reviewRulePayload),+ ); err != nil {+ return nil, errors.Wrap(err, "failed to create workspace review rule policy")+ }+// Create default project — used by schema sync to hold unassigned databases.if _, err := tx.ExecContext(ctx,`INSERT INTO project (resource_id, workspace, name, setting) VALUES ($1, $2, 'Default', '{}')`,diff --git a/backend/store/workspace_test.go b/backend/store/workspace_test.goindex 6af90d3994..2641dafba2 100644--- a/backend/store/workspace_test.go+++ b/backend/store/workspace_test.go@@ -73,6 +73,40 @@ func TestCreateWorkspaceInitializesDefaults(t *testing.T) {require.NotNil(t, project)}+// TestCreateWorkspaceSwitchesEveryReviewRuleOn pins that a new workspace has+// its own review rule policy row, which the workspace SQL Review page updates+// rather than creates, and that each workspace gets exactly one.+func TestCreateWorkspaceSwitchesEveryReviewRuleOn(t *testing.T) {+ t.Parallel()+ ctx := context.Background()+ _, stores, _ := testcontainer.NewMetadataDB(t)++ workspaceIDs := []string{"review-rules-a", "review-rules-b"}+ for _, workspaceID := range workspaceIDs {+ _, err := stores.CreateWorkspace(ctx, &store.WorkspaceMessage{ResourceID: workspaceID}, "[email protected]")+ require.NoError(t, err)+ }++ for _, workspaceID := range workspaceIDs {+ resourceType := storepb.Policy_WORKSPACE+ policyType := storepb.Policy_REVIEW_RULE+ policies, err := stores.ListPolicies(ctx, &store.FindPolicyMessage{+ Workspace: workspaceID,+ ResourceType: &resourceType,+ Resource: new(common.FormatWorkspace(workspaceID)),+ Type: &policyType,+ ShowAll: true,+ })+ require.NoError(t, err)+ require.Len(t, policies, 1)+ require.True(t, policies[0].Enforce)+ require.False(t, policies[0].InheritFromParent)+ rules := &storepb.ReviewRulePolicy{}+ require.NoError(t, common.ProtojsonUnmarshaler.Unmarshal([]byte(policies[0].Payload), rules))+ require.Equal(t, store.GetDefaultReviewRulePolicy().Rules, rules.Rules)+ }+}+func TestListWorkspacesByEmailEvaluatesBindingConditions(t *testing.T) {t.Parallel()ctx := context.Background()