Skip to content

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

chore: use boolean as identifier case payload (#6112)

rebelice866c8bc158eb
diff --git a/backend/plugin/advisor/config/sql-review.dev.yaml b/backend/plugin/advisor/config/sql-review.dev.yaml
index cf0c20fbee..cc462dcf68 100644
--- a/backend/plugin/advisor/config/sql-review.dev.yaml
+++ b/backend/plugin/advisor/config/sql-review.dev.yaml
@@ -93,7 +93,7 @@ ruleList:
- type: naming.identifier.case
level: WARNING
payload:
- case: "UPPER"
+ upper: true
- type: column.required
level: WARNING
payload:
diff --git a/backend/plugin/advisor/config/sql-review.prod.yaml b/backend/plugin/advisor/config/sql-review.prod.yaml
index 1401b85f2f..dcb2906b72 100644
--- a/backend/plugin/advisor/config/sql-review.prod.yaml
+++ b/backend/plugin/advisor/config/sql-review.prod.yaml
@@ -93,7 +93,7 @@ ruleList:
- type: naming.identifier.case
level: WARNING
payload:
- case: "UPPER"
+ upper: true
- type: column.required
level: WARNING
payload:
diff --git a/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go b/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go
index 13833fc702..35d3fcd719 100644
--- a/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go
+++ b/backend/plugin/advisor/oracle/advisor_naming_identifier_case.go
@@ -44,7 +44,7 @@ func (*NamingIdentifierCaseAdvisor) Check(ctx advisor.Context, statement string)
level: level,
title: string(ctx.Rule.Type),
currentSchema: ctx.CurrentSchema,
- namingCase: payload.Case,
+ upper: payload.Upper,
}
antlr.ParseTreeWalkerDefault.Walk(listener, tree)
@@ -60,7 +60,7 @@ type namingIdentifierCaseListener struct {
title string
currentSchema string
adviceList []advisor.Advice
- namingCase advisor.NamingCase
+ upper bool
}
func (l *namingIdentifierCaseListener) generateAdvice() ([]advisor.Advice, error) {
@@ -78,24 +78,23 @@ func (l *namingIdentifierCaseListener) generateAdvice() ([]advisor.Advice, error
// EnterId_expression is called when production id_expression is entered.
func (l *namingIdentifierCaseListener) EnterId_expression(ctx *parser.Id_expressionContext) {
identifier := normalizeIDExpression(ctx)
- switch l.namingCase {
- case advisor.NamingCaseLower:
- if identifier != strings.ToLower(identifier) {
+ if l.upper {
+ if identifier != strings.ToUpper(identifier) {
l.adviceList = append(l.adviceList, advisor.Advice{
Status: l.level,
Code: advisor.NamingCaseMismatch,
Title: l.title,
- Content: fmt.Sprintf("Identifier %q should be lower case", identifier),
+ Content: fmt.Sprintf("Identifier %q should be upper case", identifier),
Line: ctx.GetStart().GetLine(),
})
}
- case advisor.NamingCaseUpper:
- if identifier != strings.ToUpper(identifier) {
+ } else {
+ if identifier != strings.ToLower(identifier) {
l.adviceList = append(l.adviceList, advisor.Advice{
Status: l.level,
Code: advisor.NamingCaseMismatch,
Title: l.title,
- Content: fmt.Sprintf("Identifier %q should be upper case", identifier),
+ Content: fmt.Sprintf("Identifier %q should be lower case", identifier),
Line: ctx.GetStart().GetLine(),
})
}
diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.go
index 5fe6e1a14a..e3ab9011d1 100644
--- a/backend/plugin/advisor/sql_review.go
+++ b/backend/plugin/advisor/sql_review.go
@@ -316,20 +316,10 @@ type NumberTypeRulePayload struct {
Number int `json:"number"`
}
-// NamingCase is the naming case for naming rule.
-type NamingCase string
-
-const (
- // NamingCaseLower is the lower case for naming rule.
- NamingCaseLower NamingCase = "LOWER"
- // NamingCaseUpper is the upper case for naming rule.
- NamingCaseUpper NamingCase = "UPPER"
-)
-
// NamingCaseRulePayload is the payload for naming case rule.
type NamingCaseRulePayload struct {
- // Case is the naming case for naming rule.
- Case NamingCase `json:"case"`
+ // Upper is true means the case should be upper case, otherwise lower case.
+ Upper bool `json:"upper"`
}
// UnamrshalNamingRulePayloadAsRegexp will unmarshal payload to NamingRulePayload and compile it as regular expression.
@@ -466,12 +456,6 @@ func UnmarshalNamingCaseRulePayload(payload string) (*NamingCaseRulePayload, err
if err := json.Unmarshal([]byte(payload), &ncr); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal naming case rule payload %q", payload)
}
- switch ncr.Case {
- case NamingCaseLower:
- case NamingCaseUpper:
- default:
- return nil, errors.Errorf("invalid naming case %s", ncr.Case)
- }
return &ncr, nil
}
diff --git a/backend/plugin/advisor/utils_for_tests.go b/backend/plugin/advisor/utils_for_tests.go
index 6e9e3aba99..24e3118b66 100644
--- a/backend/plugin/advisor/utils_for_tests.go
+++ b/backend/plugin/advisor/utils_for_tests.go
@@ -472,7 +472,7 @@ func SetDefaultSQLReviewRulePayload(ruleTp SQLReviewRuleType) (string, error) {
})
case SchemaRuleIdentifierCase:
payload, err = json.Marshal(NamingCaseRulePayload{
- Case: NamingCaseUpper,
+ Upper: true,
})
default:
return "", errors.Errorf("unknown SQL review type for default payload: %s", ruleTp)
diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.json
index cc30ace838..e9d72bbcd5 100644
--- a/frontend/src/locales/sql-review/en-US.json
+++ b/frontend/src/locales/sql-review/en-US.json
@@ -176,8 +176,8 @@
"title": "Enforce identifier case",
"description": "",
"component": {
- "case": {
- "title": "Case"
+ "upper": {
+ "title": "Upper case"
}
}
},
diff --git a/frontend/src/locales/sql-review/es-ES.json b/frontend/src/locales/sql-review/es-ES.json
index faa1871742..d178206562 100644
--- a/frontend/src/locales/sql-review/es-ES.json
+++ b/frontend/src/locales/sql-review/es-ES.json
@@ -176,8 +176,8 @@
"title": "Hacer cumplir el caso del identificador",
"description": "",
"component": {
- "case": {
- "title": "Capitalización"
+ "upper": {
+ "title": "Capital"
}
}
},
diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.json
index 02c1b25616..a40ecb8088 100644
--- a/frontend/src/locales/sql-review/zh-CN.json
+++ b/frontend/src/locales/sql-review/zh-CN.json
@@ -177,8 +177,8 @@
"title": "强制字段名大小写",
"description": "",
"component": {
- "case": {
- "title": "大小写"
+ "upper": {
+ "title": "大写"
}
}
},
diff --git a/frontend/src/types/sql-review-schema.yaml b/frontend/src/types/sql-review-schema.yaml
index 6765116ca6..05b993356b 100644
--- a/frontend/src/types/sql-review-schema.yaml
+++ b/frontend/src/types/sql-review-schema.yaml
@@ -300,13 +300,10 @@ ruleList:
engineList:
- ORACLE
componentList:
- - key: case
+ - key: upper
payload:
- type: STRING
- default: UPPER
- enumList:
- - UPPER
- - LOWER
+ type: BOOLEAN
+ default: true
- type: column.required
category: COLUMN
engineList:
diff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.ts
index 7a28fb46d1..946e559485 100644
--- a/frontend/src/types/sqlReview.ts
+++ b/frontend/src/types/sqlReview.ts
@@ -179,7 +179,7 @@ interface NumberLimitPayload {
// The case rule payload.
// Used by the backend.
interface CasePayload {
- case: string;
+ upper: boolean;
}
// The SchemaPolicyRule stores the rule configuration by users.
@@ -457,15 +457,15 @@ export const convertPolicyRuleToRuleTemplate = (
],
};
case "naming.identifier.case":
- if (!stringComponent) {
+ if (!booleanComponent) {
throw new Error(`Invalid rule ${ruleTemplate.type}`);
}
return {
...res,
componentList: [
{
- ...stringComponent,
- payload: stringComponent.payload,
+ ...booleanComponent,
+ payload: booleanComponent.payload,
},
],
};
@@ -641,13 +641,13 @@ export const convertRuleTemplateToPolicyRule = (
},
};
case "naming.identifier.case":
- if (!stringPayload) {
+ if (!booleanPayload) {
throw new Error(`Invalid rule ${rule.type}`);
}
return {
...base,
payload: {
- case: stringPayload.value ?? stringPayload.default,
+ upper: booleanPayload.value ?? booleanPayload.default,
},
};
case "column.required":