Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(schema system): empty schema review policy warning (#1321)

rebelice9faac1c9bdfa
diff --git a/common/error.go b/common/error.go
index 8d19905875..73abd05358 100644
--- a/common/error.go
+++ b/common/error.go
@@ -36,6 +36,9 @@ const (
// 301 task error
TaskTimingNotAllowed Code = 301
+ // 401 task check error
+ TaskCheckEmptySchemaReviewPolicy Code = 401
+
// 10001 advisor error code
CompatibilityDropDatabase Code = 10001
CompatibilityRenameTable Code = 10002
diff --git a/server/task_check_executor_statement_advisor_composite.go b/server/task_check_executor_statement_advisor_composite.go
index af78c52d53..c12f917031 100644
--- a/server/task_check_executor_statement_advisor_composite.go
+++ b/server/task_check_executor_statement_advisor_composite.go
@@ -50,8 +50,18 @@ func (exec *TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context,
return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))
}
- policy, err := server.store.GetSchemaReviewPolicyByID(ctx, payload.PolicyID)
+ policy, err := server.store.GetSchemaReviewPolicyNormalByID(ctx, payload.PolicyID)
if err != nil {
+ if e, ok := err.(*common.Error); ok && e.Code == common.NotFound {
+ return []api.TaskCheckResult{
+ {
+ Status: api.TaskCheckStatusWarn,
+ Code: common.TaskCheckEmptySchemaReviewPolicy,
+ Title: "Empty schema review policy",
+ Content: "",
+ },
+ }, nil
+ }
return nil, common.Errorf(common.Internal, fmt.Errorf("failed to get schema review policy: %w", err))
}
diff --git a/store/policy.go b/store/policy.go
index 8977239f9b..a8ffd9269d 100644
--- a/store/policy.go
+++ b/store/policy.go
@@ -189,16 +189,13 @@ func (s *Store) GetSchemaReviewPolicyIDByEnvID(ctx context.Context, environmentI
return policy.ID, nil
}
-// GetSchemaReviewPolicyByID will get the schema review policy for an environment.
-func (s *Store) GetSchemaReviewPolicyByID(ctx context.Context, id int) (*api.SchemaReviewPolicy, error) {
+// GetSchemaReviewPolicyNormalByID will get the schema review policy for an environment.
+// If policy.ID is DefaultPolicyID or policy is archived, return the default empty policy.
+func (s *Store) GetSchemaReviewPolicyNormalByID(ctx context.Context, id int) (*api.SchemaReviewPolicy, error) {
pType := api.PolicyTypeSchemaReview
if id == api.DefaultPolicyID {
- defaultPolicy, err := api.GetDefaultPolicy(pType)
- if err != nil {
- return nil, err
- }
- return api.UnmarshalSchemaReviewPolicy(defaultPolicy)
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("schema review policy not found with ID %d", id)}
}
policy, err := s.getPolicyRaw(ctx, &api.PolicyFind{
@@ -208,6 +205,9 @@ func (s *Store) GetSchemaReviewPolicyByID(ctx context.Context, id int) (*api.Sch
if err != nil {
return nil, err
}
+ if policy.RowStatus == api.Archived {
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("schema review policy with ID %d is archived", id)}
+ }
return api.UnmarshalSchemaReviewPolicy(policy.Payload)
}