Skip to content

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

fix: add missing rule type mappings in review config migration (#18366)

Danny Xub5593ce8e14f
diff --git a/backend/api/v1/review_config_service.go b/backend/api/v1/review_config_service.go
index 009e960874..dd9e33e1d3 100644
--- a/backend/api/v1/review_config_service.go
+++ b/backend/api/v1/review_config_service.go
@@ -295,6 +295,9 @@ func validateSQLReviewRules(rules []*v1pb.SQLReviewRule) error {
if rule.Level == v1pb.SQLReviewRule_LEVEL_UNSPECIFIED {
return errors.Errorf("invalid rule level: LEVEL_UNSPECIFIED is not allowed for rule %q", rule.Type)
}
+ if rule.Type == v1pb.SQLReviewRule_TYPE_UNSPECIFIED {
+ return errors.Errorf("invalid rule type: TYPE_UNSPECIFIED is not allowed")
+ }
ruleType := storepb.SQLReviewRule_Type(rule.Type)
// TODO(rebelice): add other SQL review rule validation.
switch ruleType {
diff --git a/backend/api/v1/review_config_service_test.go b/backend/api/v1/review_config_service_test.go
index 59679545a7..68238171fb 100644
--- a/backend/api/v1/review_config_service_test.go
+++ b/backend/api/v1/review_config_service_test.go
@@ -58,6 +58,19 @@ func TestValidateSQLReviewRules(t *testing.T) {
wantErr: true,
errMsg: "invalid rule level: LEVEL_UNSPECIFIED is not allowed for rule \"TABLE_REQUIRE_PK\"",
},
+ {
+ name: "invalid TYPE_UNSPECIFIED",
+ rules: []*v1pb.SQLReviewRule{
+ {
+ Type: v1pb.SQLReviewRule_TYPE_UNSPECIFIED,
+ Level: v1pb.SQLReviewRule_ERROR,
+ Engine: v1pb.Engine_POSTGRES,
+ Payload: "",
+ },
+ },
+ wantErr: true,
+ errMsg: "invalid rule type: TYPE_UNSPECIFIED is not allowed",
+ },
{
name: "multiple rules with one invalid",
rules: []*v1pb.SQLReviewRule{
diff --git a/backend/migrator/migration/3.13/0017##update_review_config_rule_type.sql b/backend/migrator/migration/3.13/0017##update_review_config_rule_type.sql
index a0fbf6858d..b576018a4b 100644
--- a/backend/migrator/migration/3.13/0017##update_review_config_rule_type.sql
+++ b/backend/migrator/migration/3.13/0017##update_review_config_rule_type.sql
@@ -19,12 +19,19 @@ BEGIN
WHEN 'naming.index.fk' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_INDEX_FK'::text))
WHEN 'naming.index.idx' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_INDEX_IDX'::text))
WHEN 'naming.auto-increment-column' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_COLUMN_AUTO_INCREMENT'::text))
+ WHEN 'naming.column.auto-increment' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_COLUMN_AUTO_INCREMENT'::text))
+ WHEN 'naming.fully-qualified' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_FULLY_QUALIFIED'::text))
WHEN 'naming.table-no-keyword' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_TABLE_NO_KEYWORD'::text))
+ WHEN 'naming.table.no-keyword' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_TABLE_NO_KEYWORD'::text))
WHEN 'naming.identifier-no-keyword' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_IDENTIFIER_NO_KEYWORD'::text))
+ WHEN 'naming.identifier.no-keyword' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_IDENTIFIER_NO_KEYWORD'::text))
WHEN 'naming.identifier-case' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_IDENTIFIER_CASE'::text))
+ WHEN 'naming.identifier.case' THEN jsonb_set(rule, '{type}', to_jsonb('NAMING_IDENTIFIER_CASE'::text))
WHEN 'statement.select.no-select-all' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_SELECT_NO_SELECT_ALL'::text))
WHEN 'statement.where.require-select' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_REQUIRE_SELECT'::text))
+ WHEN 'statement.where.require.select' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_REQUIRE_SELECT'::text))
WHEN 'statement.where.require-update-delete' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_REQUIRE_UPDATE_DELETE'::text))
+ WHEN 'statement.where.require.update-delete' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_REQUIRE_UPDATE_DELETE'::text))
WHEN 'statement.where.no-leading-wildcard-like' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_NO_LEADING_WILDCARD_LIKE'::text))
WHEN 'statement.disallow-on-del-cascade' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_DISALLOW_ON_DEL_CASCADE'::text))
WHEN 'statement.disallow-rm-tbl-cascade' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_DISALLOW_RM_TBL_CASCADE'::text))
@@ -47,9 +54,13 @@ BEGIN
WHEN 'statement.disallow-using-filesort' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_DISALLOW_USING_FILESORT'::text))
WHEN 'statement.disallow-using-temporary' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_DISALLOW_USING_TEMPORARY'::text))
WHEN 'statement.where-no-equal-null' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_NO_EQUAL_NULL'::text))
+ WHEN 'statement.where.no-equal-null' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_NO_EQUAL_NULL'::text))
WHEN 'statement.where-disallow-functions-and-calculations' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_DISALLOW_FUNCTIONS_AND_CALCULATIONS'::text))
+ WHEN 'statement.where.disallow-functions-and-calculations' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_DISALLOW_FUNCTIONS_AND_CALCULATIONS'::text))
WHEN 'statement.query-minimum-plan-level' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_QUERY_MINIMUM_PLAN_LEVEL'::text))
+ WHEN 'statement.query.minimum-plan-level' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_QUERY_MINIMUM_PLAN_LEVEL'::text))
WHEN 'statement.where-maximum-logical-operator-count' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_MAXIMUM_LOGICAL_OPERATOR_COUNT'::text))
+ WHEN 'statement.where.maximum-logical-operator-count' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_WHERE_MAXIMUM_LOGICAL_OPERATOR_COUNT'::text))
WHEN 'statement.maximum-limit-value' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_MAXIMUM_LIMIT_VALUE'::text))
WHEN 'statement.maximum-join-table-count' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_MAXIMUM_JOIN_TABLE_COUNT'::text))
WHEN 'statement.maximum-statements-in-transaction' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_MAXIMUM_STATEMENTS_IN_TRANSACTION'::text))
@@ -65,6 +76,7 @@ BEGIN
WHEN 'statement.object-owner-check' THEN jsonb_set(rule, '{type}', to_jsonb('STATEMENT_OBJECT_OWNER_CHECK'::text))
WHEN 'table.require-pk' THEN jsonb_set(rule, '{type}', to_jsonb('TABLE_REQUIRE_PK'::text))
WHEN 'table.no-fk' THEN jsonb_set(rule, '{type}', to_jsonb('TABLE_NO_FOREIGN_KEY'::text))
+ WHEN 'table.no-foreign-key' THEN jsonb_set(rule, '{type}', to_jsonb('TABLE_NO_FOREIGN_KEY'::text))
WHEN 'table.drop-naming-convention' THEN jsonb_set(rule, '{type}', to_jsonb('TABLE_DROP_NAMING_CONVENTION'::text))
WHEN 'table.comment' THEN jsonb_set(rule, '{type}', to_jsonb('TABLE_COMMENT'::text))
WHEN 'table.disallow-partition' THEN jsonb_set(rule, '{type}', to_jsonb('TABLE_DISALLOW_PARTITION'::text))
@@ -94,6 +106,7 @@ BEGIN
WHEN 'column.auto-increment-initial-value' THEN jsonb_set(rule, '{type}', to_jsonb('COLUMN_AUTO_INCREMENT_INITIAL_VALUE'::text))
WHEN 'column.auto-increment-must-unsigned' THEN jsonb_set(rule, '{type}', to_jsonb('COLUMN_AUTO_INCREMENT_MUST_UNSIGNED'::text))
WHEN 'column.current-time-column-count-limit' THEN jsonb_set(rule, '{type}', to_jsonb('COLUMN_CURRENT_TIME_COUNT_LIMIT'::text))
+ WHEN 'column.current-time-count-limit' THEN jsonb_set(rule, '{type}', to_jsonb('COLUMN_CURRENT_TIME_COUNT_LIMIT'::text))
WHEN 'column.require-default' THEN jsonb_set(rule, '{type}', to_jsonb('COLUMN_REQUIRE_DEFAULT'::text))
WHEN 'column.default-disallow-volatile' THEN jsonb_set(rule, '{type}', to_jsonb('COLUMN_DEFAULT_DISALLOW_VOLATILE'::text))
WHEN 'column.add-not-null-require-default' THEN jsonb_set(rule, '{type}', to_jsonb('COLUMN_ADD_NOT_NULL_REQUIRE_DEFAULT'::text))
@@ -111,13 +124,21 @@ BEGIN
WHEN 'index.type-allow-list' THEN jsonb_set(rule, '{type}', to_jsonb('INDEX_TYPE_ALLOW_LIST'::text))
WHEN 'index.not-redundant' THEN jsonb_set(rule, '{type}', to_jsonb('INDEX_NOT_REDUNDANT'::text))
WHEN 'system.charset-allowlist' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_CHARSET_ALLOWLIST'::text))
+ WHEN 'system.charset.allowlist' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_CHARSET_ALLOWLIST'::text))
WHEN 'system.collation-allowlist' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_COLLATION_ALLOWLIST'::text))
+ WHEN 'system.collation.allowlist' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_COLLATION_ALLOWLIST'::text))
WHEN 'system.comment-length' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_COMMENT_LENGTH'::text))
+ WHEN 'system.comment.length' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_COMMENT_LENGTH'::text))
WHEN 'system.procedure-disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_PROCEDURE_DISALLOW_CREATE'::text))
+ WHEN 'system.procedure.disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_PROCEDURE_DISALLOW_CREATE'::text))
WHEN 'system.event-disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_EVENT_DISALLOW_CREATE'::text))
+ WHEN 'system.event.disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_EVENT_DISALLOW_CREATE'::text))
WHEN 'system.view-disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_VIEW_DISALLOW_CREATE'::text))
+ WHEN 'system.view.disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_VIEW_DISALLOW_CREATE'::text))
WHEN 'system.function-disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_FUNCTION_DISALLOW_CREATE'::text))
+ WHEN 'system.function.disallow-create' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_FUNCTION_DISALLOW_CREATE'::text))
WHEN 'system.function-disallowed-list' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_FUNCTION_DISALLOWED_LIST'::text))
+ WHEN 'system.function.disallowed-list' THEN jsonb_set(rule, '{type}', to_jsonb('SYSTEM_FUNCTION_DISALLOWED_LIST'::text))
WHEN 'advice.online-migration' THEN jsonb_set(rule, '{type}', to_jsonb('ADVICE_ONLINE_MIGRATION'::text))
WHEN 'builtin.prior-backup-check' THEN jsonb_set(rule, '{type}', to_jsonb('BUILTIN_PRIOR_BACKUP_CHECK'::text))
WHEN 'engine.mysql.use-innodb' THEN jsonb_set(rule, '{type}', to_jsonb('ENGINE_MYSQL_USE_INNODB'::text))