Skip to content

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

refactor: rename schema review to SQL review (#2135)

Danny Xu5799c2317808
diff --git a/api/policy.go b/api/policy.go
index dacb49d423..a908204e26 100644
--- a/api/policy.go
+++ b/api/policy.go
@@ -24,8 +24,8 @@ const (
PolicyTypePipelineApproval PolicyType = "bb.policy.pipeline-approval"
// PolicyTypeBackupPlan is the backup plan policy type.
PolicyTypeBackupPlan PolicyType = "bb.policy.backup-plan"
- // PolicyTypeSchemaReview is the schema review policy type.
- PolicyTypeSchemaReview PolicyType = "bb.policy.schema-review"
+ // PolicyTypeSQLReview is the sql review policy type.
+ PolicyTypeSQLReview PolicyType = "bb.policy.sql-review"
// PipelineApprovalValueManualNever means the pipeline will automatically be approved without user intervention.
PipelineApprovalValueManualNever PipelineApprovalValue = "MANUAL_APPROVAL_NEVER"
@@ -45,7 +45,7 @@ var (
PolicyTypes = map[PolicyType]bool{
PolicyTypePipelineApproval: true,
PolicyTypeBackupPlan: true,
- PolicyTypeSchemaReview: true,
+ PolicyTypeSQLReview: true,
}
)
@@ -160,11 +160,11 @@ func UnmarshalBackupPlanPolicy(payload string) (*BackupPlanPolicy, error) {
return &bp, nil
}
-// UnmarshalSQLReviewPolicy will unmarshal payload to schema review policy.
+// UnmarshalSQLReviewPolicy will unmarshal payload to SQL review policy.
func UnmarshalSQLReviewPolicy(payload string) (*advisor.SQLReviewPolicy, error) {
var sr advisor.SQLReviewPolicy
if err := json.Unmarshal([]byte(payload), &sr); err != nil {
- return nil, fmt.Errorf("failed to unmarshal schema review policy %q: %q", payload, err)
+ return nil, fmt.Errorf("failed to unmarshal SQL review policy %q: %q", payload, err)
}
return &sr, nil
}
@@ -195,13 +195,13 @@ func ValidatePolicy(pType PolicyType, payload string) error {
if bp.Schedule != BackupPlanPolicyScheduleUnset && bp.Schedule != BackupPlanPolicyScheduleDaily && bp.Schedule != BackupPlanPolicyScheduleWeekly {
return fmt.Errorf("invalid backup plan policy schedule: %q", bp.Schedule)
}
- case PolicyTypeSchemaReview:
+ case PolicyTypeSQLReview:
sr, err := UnmarshalSQLReviewPolicy(payload)
if err != nil {
return err
}
if err := sr.Validate(); err != nil {
- return fmt.Errorf("invalid schema review policy: %w", err)
+ return fmt.Errorf("invalid SQL review policy: %w", err)
}
}
return nil
@@ -219,8 +219,8 @@ func GetDefaultPolicy(pType PolicyType) (string, error) {
return BackupPlanPolicy{
Schedule: BackupPlanPolicyScheduleUnset,
}.String()
- case PolicyTypeSchemaReview:
- // TODO(ed): we may need to define the default schema review policy payload in the PR of policy data migration.
+ case PolicyTypeSQLReview:
+ // TODO(ed): we may need to define the default SQL review policy payload in the PR of policy data migration.
return "{}", nil
}
return "", nil
diff --git a/api/task_check_run.go b/api/task_check_run.go
index ef746f5945..774f966782 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -89,7 +89,7 @@ type TaskCheckDatabaseStatementAdvisePayload struct {
Charset string `json:"charset,omitempty"`
Collation string `json:"collation,omitempty"`
- // Schema review special fields.
+ // SQL review special fields.
PolicyID int `json:"policyID,omitempty"`
}
@@ -212,7 +212,7 @@ func IsSyntaxCheckSupported(dbType db.Type, _ common.ReleaseMode) bool {
return false
}
-// IsSQLReviewSupported checks the engine type if schema review supports it.
+// IsSQLReviewSupported checks the engine type if SQL review supports it.
func IsSQLReviewSupported(dbType db.Type, _ common.ReleaseMode) bool {
if dbType == db.Postgres || dbType == db.MySQL || dbType == db.TiDB {
advisorDB, err := advisorDB.ConvertToAdvisorDBType(string(dbType))
diff --git a/docs/openapi/docs.go b/docs/openapi/docs.go
index 32127661da..acc22f9a34 100644
--- a/docs/openapi/docs.go
+++ b/docs/openapi/docs.go
@@ -27,7 +27,7 @@ const docTemplate = `{
"paths": {
"/sql/advise": {
"get": {
- "description": "Parse and check the SQL statement according to the schema review policy.",
+ "description": "Parse and check the SQL statement according to the SQL review policy.",
"consumes": [
"*/*"
],
@@ -35,7 +35,7 @@ const docTemplate = `{
"application/json"
],
"tags": [
- "Schema Review"
+ "SQL review"
],
"summary": "Check the SQL statement.",
"parameters": [
diff --git a/docs/openapi/swagger.yaml b/docs/openapi/swagger.yaml
index ea88bc4fbc..a3a4268866 100644
--- a/docs/openapi/swagger.yaml
+++ b/docs/openapi/swagger.yaml
@@ -34,61 +34,62 @@ paths:
/sql/advise:
get:
consumes:
- - '*/*'
- description: Parse and check the SQL statement according to the schema review
+ - "*/*"
+ description: Parse and check the SQL statement according to the SQL review
policy.
parameters:
- - description: The environment name. Case sensitive.
- in: query
- name: environment
- required: true
- type: string
- - description: The SQL statement.
- in: query
- name: statement
- required: true
- type: string
- - description: The database type. Required if the port, host and database name
- is not specified.
- enum:
- - MYSQL
- - POSTGRES
- - TIDB
- in: query
- name: databaseType
- type: string
- - description: The instance host.
- in: query
- name: host
- type: string
- - description: The instance port.
- in: query
- name: port
- type: string
- - description: The database name in the instance.
- in: query
- name: databaseName
- type: string
+ - description: The environment name. Case sensitive.
+ in: query
+ name: environment
+ required: true
+ type: string
+ - description: The SQL statement.
+ in: query
+ name: statement
+ required: true
+ type: string
+ - description:
+ The database type. Required if the port, host and database name
+ is not specified.
+ enum:
+ - MYSQL
+ - POSTGRES
+ - TIDB
+ in: query
+ name: databaseType
+ type: string
+ - description: The instance host.
+ in: query
+ name: host
+ type: string
+ - description: The instance port.
+ in: query
+ name: port
+ type: string
+ - description: The database name in the instance.
+ in: query
+ name: databaseName
+ type: string
produces:
- - application/json
+ - application/json
responses:
"200":
description: OK
schema:
items:
- $ref: '#/definitions/advisor.Advice'
+ $ref: "#/definitions/advisor.Advice"
type: array
"400":
description: Bad Request
schema:
- $ref: '#/definitions/echo.HTTPError'
+ $ref: "#/definitions/echo.HTTPError"
"500":
description: Internal Server Error
schema:
- $ref: '#/definitions/echo.HTTPError'
+ $ref: "#/definitions/echo.HTTPError"
summary: Check the SQL statement.
tags:
- - Schema Review
+ - SQL review
schemes:
-- http
+ - http
swagger: "2.0"
diff --git a/docs/sqlservice/docs.go b/docs/sqlservice/docs.go
index 7a939a8d45..d195b493d5 100644
--- a/docs/sqlservice/docs.go
+++ b/docs/sqlservice/docs.go
@@ -27,7 +27,7 @@ const docTemplate = `{
"paths": {
"/sql/advise": {
"get": {
- "description": "Parse and check the SQL statement according to the schema review rules.",
+ "description": "Parse and check the SQL statement according to the SQL review rules.",
"consumes": [
"*/*"
],
@@ -35,7 +35,7 @@ const docTemplate = `{
"application/json"
],
"tags": [
- "Schema Review"
+ "SQL review"
],
"summary": "Check the SQL statement.",
"parameters": [
diff --git a/docs/sqlservice/swagger.yaml b/docs/sqlservice/swagger.yaml
index bacf1057b1..8a9c10fe50 100644
--- a/docs/sqlservice/swagger.yaml
+++ b/docs/sqlservice/swagger.yaml
@@ -34,56 +34,57 @@ paths:
/sql/advise:
get:
consumes:
- - '*/*'
- description: Parse and check the SQL statement according to the schema review
+ - "*/*"
+ description: Parse and check the SQL statement according to the SQL review
rules.
parameters:
- - description: The SQL statement.
- in: query
- name: statement
- required: true
- type: string
- - description: The database type.
- enum:
- - MYSQL
- - POSTGRES
- - TIDB
- in: query
- name: databaseType
- required: true
- type: string
- - description: The SQL check template id. Required if the config is not specified.
- enum:
- - bb.sql-review.prod
- - bb.sql-review.dev
- in: query
- name: template
- type: string
- - description: The SQL check config override string in YAML format. Check https://github.com/bytebase/bytebase/tree/main/plugin/advisor/config/sql-review.override.yaml
- for example. Required if the template is not specified.
- in: query
- name: override
- type: string
+ - description: The SQL statement.
+ in: query
+ name: statement
+ required: true
+ type: string
+ - description: The database type.
+ enum:
+ - MYSQL
+ - POSTGRES
+ - TIDB
+ in: query
+ name: databaseType
+ required: true
+ type: string
+ - description: The SQL check template id. Required if the config is not specified.
+ enum:
+ - bb.sql-review.prod
+ - bb.sql-review.dev
+ in: query
+ name: template
+ type: string
+ - description:
+ The SQL check config override string in YAML format. Check https://github.com/bytebase/bytebase/tree/main/plugin/advisor/config/sql-review.override.yaml
+ for example. Required if the template is not specified.
+ in: query
+ name: override
+ type: string
produces:
- - application/json
+ - application/json
responses:
"200":
description: OK
schema:
items:
- $ref: '#/definitions/advisor.Advice'
+ $ref: "#/definitions/advisor.Advice"
type: array
"400":
description: Bad Request
schema:
- $ref: '#/definitions/echo.HTTPError'
+ $ref: "#/definitions/echo.HTTPError"
"500":
description: Internal Server Error
schema:
- $ref: '#/definitions/echo.HTTPError'
+ $ref: "#/definitions/echo.HTTPError"
summary: Check the SQL statement.
tags:
- - Schema Review
+ - SQL review
schemes:
-- http
+ - http
swagger: "2.0"
diff --git a/frontend/src/components/Issue/TaskCheckRunPanel.vue b/frontend/src/components/Issue/TaskCheckRunPanel.vue
index 1e42d83aba..1b488d9adc 100644
--- a/frontend/src/components/Issue/TaskCheckRunPanel.vue
+++ b/frontend/src/components/Issue/TaskCheckRunPanel.vue
@@ -140,7 +140,7 @@ export default defineComponent({
case SQLReviewPolicyErrorCode.EMPTY_POLICY:
title = checkResult.title;
break;
- // SchemaReviewPolicyErrorCode
+ // SchemaSQLPolicyErrorCode
case SQLReviewPolicyErrorCode.STATEMENT_NO_WHERE:
case SQLReviewPolicyErrorCode.STATEMENT_NO_SELECT_ALL:
case SQLReviewPolicyErrorCode.STATEMENT_LEADING_WILDCARD_LIKE:
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index 140cd740ad..be266ca274 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -108,7 +108,7 @@ const useExecuteSQL = () => {
const sqlResultSet = await sqlEditorStore.executeQuery({
statement: selectStatement,
});
- // TODO(steven): use BBModel instead of notify to show the advice from schema review.
+ // TODO(steven): use BBModel instead of notify to show the advice from SQL review.
let adviceStatus = "SUCCESS";
let adviceNotifyMessage = "";
for (const advice of sqlResultSet.adviceList) {
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index a998140d49..b0c6ff078f 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1326,8 +1326,8 @@
"desc": "Backup policy will auto-backup your database based on the schedule."
},
"bb-feature-sql-review": {
- "title": "Schema review policy",
- "desc": "Customize the schema review policy for different environments. @:{'subscription.trial'}."
+ "title": "SQL review policy",
+ "desc": "Customize the SQL review policy for different environments. @:{'subscription.trial'}."
},
"bb-feature-rbac": {
"title": "Role management",
@@ -1376,7 +1376,7 @@
"disaster-recovery-advanced": "Advanced",
"disaster-recovery-advanced-tooltip": "Database backup / restore + Point-in-Time-Recovery (PITR)",
"archiving": "Archiving",
- "sql-check": "SQL check / Schema review",
+ "sql-check": "SQL check / SQL review",
"sql-check-basic": "Basic",
"sql-check-basic-tooltip": "Syntax check, connection check",
"sql-check-advanced": "Advanced",
@@ -1485,7 +1485,7 @@
"environments-select": "Select environments",
"no-linked-environments": "No linked environment",
"no-available-environment": "No available environment",
- "no-available-environment-desc": "No available environment. One environment can only link one schema review policy.",
+ "no-available-environment-desc": "No available environment. One environment can only link one SQL review policy.",
"choose-template": "Choose template"
},
"configure-rule": {
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index c512ee82e0..7391f1195a 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -169,7 +169,7 @@ export const useRouterStore = defineStore("router", {
{
// /setting/sql-review/:sqlReviewPolicyId
- // Total 2 elements, 2nd element is the schema review id
+ // Total 2 elements, 2nd element is the SQL review id
const sqlReviewComponents = currentRoute.path.match(
"/setting/sql-review/([0-9a-zA-Z_-]+)"
) || ["/", undefined];
diff --git a/frontend/src/types/policy.ts b/frontend/src/types/policy.ts
index e6b4213b99..883b7d6372 100644
--- a/frontend/src/types/policy.ts
+++ b/frontend/src/types/policy.ts
@@ -31,7 +31,7 @@ export type BackupPlanPolicyPayload = {
export const DefaultSchedulePolicy: BackupPlanPolicySchedule = "UNSET";
-// SQLReviewPolicyPayload is the payload for schema review policy in the backend.
+// SQLReviewPolicyPayload is the payload for SQL review policy in the backend.
export type SQLReviewPolicyPayload = {
name: string;
ruleList: {
diff --git a/metric/collector/policy_count.go b/metric/collector/policy_count.go
index d0458ba7d6..4abb812c61 100644
--- a/metric/collector/policy_count.go
+++ b/metric/collector/policy_count.go
@@ -54,9 +54,9 @@ func (c *policyCountCollector) Collect(ctx context.Context) ([]*metric.Metric, e
}
value = string(payload.Schedule)
key = fmt.Sprintf("%s_%s_%s", policy.Type, policy.Environment.Name, value)
- case api.PolicyTypeSchemaReview:
+ case api.PolicyTypeSQLReview:
key = fmt.Sprintf("%s_%s", policy.Type, policy.Environment.Name)
- // schema review policy don't need to set the value.
+ // SQL review policy don't need to set the value.
value = ""
}
diff --git a/plugin/advisor/advisor.go b/plugin/advisor/advisor.go
index d82586b525..f74f1d2cd4 100644
--- a/plugin/advisor/advisor.go
+++ b/plugin/advisor/advisor.go
@@ -180,7 +180,7 @@ type Context struct {
Charset string
Collation string
- // Schema review rule special fields.
+ // SQL review rule special fields.
Rule *SQLReviewRule
Database *catalog.Database
}
@@ -243,7 +243,7 @@ func IsSyntaxCheckSupported(dbType db.Type) bool {
return false
}
-// IsSQLReviewSupported checks the engine type if schema review supports it.
+// IsSQLReviewSupported checks the engine type if SQL review supports it.
func IsSQLReviewSupported(dbType db.Type) bool {
switch dbType {
case db.MySQL, db.TiDB, db.Postgres:
diff --git a/plugin/advisor/mysql/advisor_column_no_null_test.go b/plugin/advisor/mysql/advisor_column_no_null_test.go
index 425b849f72..b4ff7af3cb 100644
--- a/plugin/advisor/mysql/advisor_column_no_null_test.go
+++ b/plugin/advisor/mysql/advisor_column_no_null_test.go
@@ -104,7 +104,7 @@ func TestColumnNoNull(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleColumnNotNull,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_column_required_test.go b/plugin/advisor/mysql/advisor_column_required_test.go
index ea989bd7c9..ba1e2d5be3 100644
--- a/plugin/advisor/mysql/advisor_column_required_test.go
+++ b/plugin/advisor/mysql/advisor_column_required_test.go
@@ -226,7 +226,7 @@ func TestColumnRequirement(t *testing.T) {
},
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &ColumnRequirementAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &ColumnRequirementAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleRequiredColumn,
Level: advisor.SchemaRuleLevelWarning,
Payload: string(payload),
diff --git a/plugin/advisor/mysql/advisor_database_drop_empty_db_test.go b/plugin/advisor/mysql/advisor_database_drop_empty_db_test.go
index 882de6d8a1..e154a93c27 100644
--- a/plugin/advisor/mysql/advisor_database_drop_empty_db_test.go
+++ b/plugin/advisor/mysql/advisor_database_drop_empty_db_test.go
@@ -32,7 +32,7 @@ func TestMySQLDatabaseAllowDropIfEmpty(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &DatabaseAllowDropIfEmptyAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &DatabaseAllowDropIfEmptyAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleDropEmptyDatabase,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_migration_compatibility_test.go b/plugin/advisor/mysql/advisor_migration_compatibility_test.go
index 2ddbe2f488..5c1fd7bfc9 100644
--- a/plugin/advisor/mysql/advisor_migration_compatibility_test.go
+++ b/plugin/advisor/mysql/advisor_migration_compatibility_test.go
@@ -84,7 +84,7 @@ func TestBasic(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
@@ -258,7 +258,7 @@ func TestAlterTable(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
@@ -324,7 +324,7 @@ func TestAlterTableChangeColumnType(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_naming_column_test.go b/plugin/advisor/mysql/advisor_naming_column_test.go
index a593f3c898..7110c58427 100644
--- a/plugin/advisor/mysql/advisor_naming_column_test.go
+++ b/plugin/advisor/mysql/advisor_naming_column_test.go
@@ -168,7 +168,7 @@ func TestNamingColumnConvention(t *testing.T) {
MaxLength: 64,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingColumnConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingColumnConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleColumnNaming,
Level: advisor.SchemaRuleLevelWarning,
Payload: string(payload),
diff --git a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
index 8fee442bab..e33f32b26e 100644
--- a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
@@ -81,7 +81,7 @@ func TestNamingFKConvention(t *testing.T) {
MaxLength: 64,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingFKConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingFKConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleFKNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/mysql/advisor_naming_index_convention_test.go b/plugin/advisor/mysql/advisor_naming_index_convention_test.go
index 5a8ed59814..60cabec18b 100644
--- a/plugin/advisor/mysql/advisor_naming_index_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_index_convention_test.go
@@ -133,7 +133,7 @@ func TestNamingIndexConvention(t *testing.T) {
MaxLength: 64,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingIndexConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingIndexConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleIDXNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/mysql/advisor_naming_table_test.go b/plugin/advisor/mysql/advisor_naming_table_test.go
index 609595b5ea..c808ff99ed 100644
--- a/plugin/advisor/mysql/advisor_naming_table_test.go
+++ b/plugin/advisor/mysql/advisor_naming_table_test.go
@@ -113,7 +113,7 @@ func TestMySQLNamingTableConvention(t *testing.T) {
MaxLength: 64,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingTableConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingTableConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleTableNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
index f6db0ea3b3..6f8608f716 100644
--- a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
@@ -155,7 +155,7 @@ func TestNamingUKConvention(t *testing.T) {
MaxLength: 64,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingUKConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingUKConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleUKNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
index 82030d5270..84ad758673 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
@@ -65,7 +65,7 @@ func TestNoLeadingWildcardLike(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &NoLeadingWildcardLikeAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NoLeadingWildcardLikeAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleStatementNoLeadingWildcardLike,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go b/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
index ba04ca8dfc..1a8b206559 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
@@ -43,7 +43,7 @@ func TestNoSelectAll(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &NoSelectAllAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NoSelectAllAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleStatementNoSelectAll,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_stmt_where_required_test.go b/plugin/advisor/mysql/advisor_stmt_where_required_test.go
index 24ad2e09c5..2e36238f90 100644
--- a/plugin/advisor/mysql/advisor_stmt_where_required_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_where_required_test.go
@@ -87,7 +87,7 @@ func TestWhereRequirement(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &WhereRequirementAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &WhereRequirementAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleStatementRequireWhere,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_table_drop_naming_convention_test.go b/plugin/advisor/mysql/advisor_table_drop_naming_convention_test.go
index 065bb4e16e..7ce752f11a 100644
--- a/plugin/advisor/mysql/advisor_table_drop_naming_convention_test.go
+++ b/plugin/advisor/mysql/advisor_table_drop_naming_convention_test.go
@@ -49,7 +49,7 @@ func TestMySQLTableDropNamingConvention(t *testing.T) {
Format: "_delete$",
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &TableDropNamingConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &TableDropNamingConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleTableDropNamingConvention,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/mysql/advisor_table_no_fk_test.go b/plugin/advisor/mysql/advisor_table_no_fk_test.go
index 3573640e83..1cb87a87ad 100644
--- a/plugin/advisor/mysql/advisor_table_no_fk_test.go
+++ b/plugin/advisor/mysql/advisor_table_no_fk_test.go
@@ -32,7 +32,7 @@ func TestTableNoFK(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &TableNoFKAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &TableNoFKAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleTableNoFK,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_table_require_pk_test.go b/plugin/advisor/mysql/advisor_table_require_pk_test.go
index f4b306f1f5..a0c568c333 100644
--- a/plugin/advisor/mysql/advisor_table_require_pk_test.go
+++ b/plugin/advisor/mysql/advisor_table_require_pk_test.go
@@ -212,7 +212,7 @@ func TestRequirePK(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &TableRequirePKAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &TableRequirePKAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleTableRequirePK,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/mysql/advisor_use_innodb_test.go b/plugin/advisor/mysql/advisor_use_innodb_test.go
index 0e9a058bd9..12958b1514 100644
--- a/plugin/advisor/mysql/advisor_use_innodb_test.go
+++ b/plugin/advisor/mysql/advisor_use_innodb_test.go
@@ -86,7 +86,7 @@ func TestUseInnoDB(t *testing.T) {
},
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &UseInnoDBAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &UseInnoDBAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleMySQLEngine,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/pg/advisor_column_no_null_test.go b/plugin/advisor/pg/advisor_column_no_null_test.go
index ba3a9b593a..bc9eb45bec 100644
--- a/plugin/advisor/pg/advisor_column_no_null_test.go
+++ b/plugin/advisor/pg/advisor_column_no_null_test.go
@@ -115,7 +115,7 @@ func TestColumnNoNULL(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleColumnNotNull,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
diff --git a/plugin/advisor/pg/advisor_column_required_test.go b/plugin/advisor/pg/advisor_column_required_test.go
index fd0fd6164c..7ae060ace2 100644
--- a/plugin/advisor/pg/advisor_column_required_test.go
+++ b/plugin/advisor/pg/advisor_column_required_test.go
@@ -70,7 +70,7 @@ func TestColumnRequirement(t *testing.T) {
},
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &ColumnRequirementAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &ColumnRequirementAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleRequiredColumn,
Level: advisor.SchemaRuleLevelWarning,
Payload: string(payload),
diff --git a/plugin/advisor/pg/advisor_migration_compatibility_test.go b/plugin/advisor/pg/advisor_migration_compatibility_test.go
index 369cf848f6..08f0f8df1a 100644
--- a/plugin/advisor/pg/advisor_migration_compatibility_test.go
+++ b/plugin/advisor/pg/advisor_migration_compatibility_test.go
@@ -82,7 +82,7 @@ func TestBasic(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
@@ -213,7 +213,7 @@ func TestAlterTable(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
@@ -235,7 +235,7 @@ func TestAlterTableChangeColumnType(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
diff --git a/plugin/advisor/pg/advisor_naming_column_test.go b/plugin/advisor/pg/advisor_naming_column_test.go
index 53dbd047e0..9f6a85c59e 100644
--- a/plugin/advisor/pg/advisor_naming_column_test.go
+++ b/plugin/advisor/pg/advisor_naming_column_test.go
@@ -97,7 +97,7 @@ func TestNamingColumnConvention(t *testing.T) {
Format: "^[a-z]+(_[a-z]+)*$",
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingColumnConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingColumnConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleColumnNaming,
Level: advisor.SchemaRuleLevelWarning,
Payload: string(payload),
diff --git a/plugin/advisor/pg/advisor_naming_foreign_key_convention_test.go b/plugin/advisor/pg/advisor_naming_foreign_key_convention_test.go
index e54f264cff..2ae10abeb8 100644
--- a/plugin/advisor/pg/advisor_naming_foreign_key_convention_test.go
+++ b/plugin/advisor/pg/advisor_naming_foreign_key_convention_test.go
@@ -126,7 +126,7 @@ func TestNamingFKConvention(t *testing.T) {
MaxLength: maxLength,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingFKConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingFKConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleFKNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/pg/advisor_naming_index_convention_test.go b/plugin/advisor/pg/advisor_naming_index_convention_test.go
index a6748f3017..ab7224333d 100644
--- a/plugin/advisor/pg/advisor_naming_index_convention_test.go
+++ b/plugin/advisor/pg/advisor_naming_index_convention_test.go
@@ -89,7 +89,7 @@ func TestNamingIndexConvention(t *testing.T) {
MaxLength: 32,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingIndexConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingIndexConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleIDXNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/pg/advisor_naming_primary_key_convention_test.go b/plugin/advisor/pg/advisor_naming_primary_key_convention_test.go
index bac81b9798..2d08a71887 100644
--- a/plugin/advisor/pg/advisor_naming_primary_key_convention_test.go
+++ b/plugin/advisor/pg/advisor_naming_primary_key_convention_test.go
@@ -185,7 +185,7 @@ func TestNamingPKConvention(t *testing.T) {
MaxLength: maxLength,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingPKConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingPKConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRulePKNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/pg/advisor_naming_table_test.go b/plugin/advisor/pg/advisor_naming_table_test.go
index 8d68b9a465..17cab8e4db 100644
--- a/plugin/advisor/pg/advisor_naming_table_test.go
+++ b/plugin/advisor/pg/advisor_naming_table_test.go
@@ -100,7 +100,7 @@ func TestPostgreSQLNamingTableConvention(t *testing.T) {
Format: "^[a-z]+(_[a-z]+)*$",
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingTableConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingTableConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleTableNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/pg/advisor_naming_unique_key_convention_test.go b/plugin/advisor/pg/advisor_naming_unique_key_convention_test.go
index 957913512b..d880ef0e59 100644
--- a/plugin/advisor/pg/advisor_naming_unique_key_convention_test.go
+++ b/plugin/advisor/pg/advisor_naming_unique_key_convention_test.go
@@ -225,7 +225,7 @@ func TestNamingUKConvention(t *testing.T) {
MaxLength: maxLength,
})
require.NoError(t, err)
- advisor.RunSchemaReviewRuleTests(t, tests, &NamingUKConventionAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NamingUKConventionAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleUKNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
diff --git a/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like_test.go b/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like_test.go
index dc8c2e7e95..2cb2844d15 100644
--- a/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like_test.go
+++ b/plugin/advisor/pg/advisor_stmt_no_leading_wildcard_like_test.go
@@ -65,7 +65,7 @@ func TestNoLeadingWildcardLike(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &NoLeadingWildcardLikeAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NoLeadingWildcardLikeAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleStatementNoLeadingWildcardLike,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/pg/advisor_stmt_no_select_all_test.go b/plugin/advisor/pg/advisor_stmt_no_select_all_test.go
index c6ce40d22e..a56d29629d 100644
--- a/plugin/advisor/pg/advisor_stmt_no_select_all_test.go
+++ b/plugin/advisor/pg/advisor_stmt_no_select_all_test.go
@@ -43,7 +43,7 @@ func TestNoSelectAll(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &NoSelectAllAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &NoSelectAllAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleStatementNoSelectAll,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/pg/advisor_stmt_where_required_test.go b/plugin/advisor/pg/advisor_stmt_where_required_test.go
index 8cab4dc9e9..7e86ffbfc9 100644
--- a/plugin/advisor/pg/advisor_stmt_where_required_test.go
+++ b/plugin/advisor/pg/advisor_stmt_where_required_test.go
@@ -87,7 +87,7 @@ func TestWhereRequirement(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &WhereRequirementAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &WhereRequirementAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleStatementRequireWhere,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
diff --git a/plugin/advisor/pg/advisor_table_require_pk_test.go b/plugin/advisor/pg/advisor_table_require_pk_test.go
index 454c465140..eb28b2d7bd 100644
--- a/plugin/advisor/pg/advisor_table_require_pk_test.go
+++ b/plugin/advisor/pg/advisor_table_require_pk_test.go
@@ -99,7 +99,7 @@ func TestRequirePK(t *testing.T) {
},
}
- advisor.RunSchemaReviewRuleTests(t, tests, &TableRequirePKAdvisor{}, &advisor.SQLReviewRule{
+ advisor.RunSQLReviewRuleTests(t, tests, &TableRequirePKAdvisor{}, &advisor.SQLReviewRule{
Type: advisor.SchemaRuleTableRequirePK,
Level: advisor.SchemaRuleLevelError,
Payload: "",
diff --git a/plugin/advisor/sql_review.go b/plugin/advisor/sql_review.go
index 1563a2dcc7..4102ff2df8 100644
--- a/plugin/advisor/sql_review.go
+++ b/plugin/advisor/sql_review.go
@@ -11,13 +11,13 @@ import (
"github.com/bytebase/bytebase/plugin/advisor/db"
)
-// How to add a schema review rule:
+// How to add a SQL review rule:
// 1. Implement an advisor.(plugin/advisor/mysql or plugin/advisor/pg)
// 2. Register this advisor in map[db.Type][AdvisorType].(plugin/advisor.go)
// 3. Add advisor error code if needed(plugin/advisor/code.go).
// 4. Map SQLReviewRuleType to advisor.Type in getAdvisorTypeByRule(current file).
-// SQLReviewRuleLevel is the error level for schema review rule.
+// SQLReviewRuleLevel is the error level for SQL review rule.
type SQLReviewRuleLevel string
// SQLReviewRuleType is the type of schema rule.
@@ -113,7 +113,7 @@ var (
}
)
-// SQLReviewPolicy is the policy configuration for schema review.
+// SQLReviewPolicy is the policy configuration for SQL review.
type SQLReviewPolicy struct {
Name string `json:"name"`
RuleList []*SQLReviewRule `json:"ruleList"`
@@ -132,7 +132,7 @@ func (policy *SQLReviewPolicy) Validate() error {
return nil
}
-// SQLReviewRule is the rule for schema review policy.
+// SQLReviewRule is the rule for SQL review policy.
type SQLReviewRule struct {
Type SQLReviewRuleType `json:"type"`
Level SQLReviewRuleLevel `json:"level"`
@@ -141,9 +141,9 @@ type SQLReviewRule struct {
Payload string `json:"payload"`
}
-// Validate validates the schema review rule.
+// Validate validates the SQL review rule.
func (rule *SQLReviewRule) Validate() error {
- // TODO(rebelice): add other schema review rule validation.
+ // TODO(rebelice): add other SQL review rule validation.
switch rule.Type {
case SchemaRuleTableNaming, SchemaRuleColumnNaming:
if _, _, err := UnamrshalNamingRulePayloadAsRegexp(rule.Payload); err != nil {
@@ -253,7 +253,7 @@ func UnmarshalRequiredColumnRulePayload(payload string) (*RequiredColumnRulePayl
return &rcr, nil
}
-// SQLReviewCheckContext is the context for schema review check.
+// SQLReviewCheckContext is the context for SQL review check.
type SQLReviewCheckContext struct {
Charset string
Collation string
@@ -261,8 +261,8 @@ type SQLReviewCheckContext struct {
Catalog catalog.Catalog
}
-// SchemaReviewCheck checks the statements with schema review rules.
-func SchemaReviewCheck(statements string, ruleList []*SQLReviewRule, checkContext SQLReviewCheckContext) ([]Advice, error) {
+// SQLReviewCheck checks the statements with sql review rules.
+func SQLReviewCheck(statements string, ruleList []*SQLReviewRule, checkContext SQLReviewCheckContext) ([]Advice, error) {
var result []Advice
database, err := checkContext.Catalog.GetDatabase(context.Background())
if err != nil {
@@ -422,5 +422,5 @@ func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine db.Type) (Type, err
return MySQLDatabaseAllowDropIfEmpty, nil
}
}
- return Fake, fmt.Errorf("unknown schema review rule type %v for %v", ruleType, engine)
+ return Fake, fmt.Errorf("unknown SQL review rule type %v for %v", ruleType, engine)
}
diff --git a/plugin/advisor/utils_for_tests.go b/plugin/advisor/utils_for_tests.go
index d866b8c6de..acb53ac117 100644
--- a/plugin/advisor/utils_for_tests.go
+++ b/plugin/advisor/utils_for_tests.go
@@ -106,8 +106,8 @@ type TestCase struct {
Want []Advice
}
-// RunSchemaReviewRuleTests helps to test the schema review rule.
-func RunSchemaReviewRuleTests(
+// RunSQLReviewRuleTests helps to test the SQL review rule.
+func RunSQLReviewRuleTests(
t *testing.T,
tests []TestCase,
adv Advisor,
diff --git a/server/openapi.go b/server/openapi.go
index bb44ce5ec6..d152171c3a 100644
--- a/server/openapi.go
+++ b/server/openapi.go
@@ -33,9 +33,9 @@ func (s *Server) registerOpenAPIRoutes(g *echo.Group) {
// sqlCheckController godoc
// @Summary Check the SQL statement.
-// @Description Parse and check the SQL statement according to the schema review policy.
+// @Description Parse and check the SQL statement according to the SQL review policy.
// @Accept */*
-// @Tags Schema Review
+// @Tags SQL review
// @Produce json
// @Param environment query string true "The environment name. Case sensitive."
// @Param statement query string true "The SQL statement."
diff --git a/server/policy.go b/server/policy.go
index 26867a4fbe..be8d96b3dd 100644
--- a/server/policy.go
+++ b/server/policy.go
@@ -37,7 +37,7 @@ func (s *Server) hasAccessToUpsertPolicy(policyUpsert *api.PolicyUpsert) error {
if !s.feature(api.FeatureBackupPolicy) {
return fmt.Errorf(api.FeatureBackupPolicy.AccessErrorMessage())
}
- case api.PolicyTypeSchemaReview:
+ case api.PolicyTypeSQLReview:
if !s.feature(api.FeatureSQLReviewPolicy) {
return fmt.Errorf(api.FeatureSQLReviewPolicy.AccessErrorMessage())
}
diff --git a/server/sql.go b/server/sql.go
index b7ed1c54a3..cfb6b9531d 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -211,7 +211,7 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {
store.NewCatalog(&db.ID, s.store, instance.Engine),
)
if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to check schema review policy").SetInternal(err)
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to check SQL review policy").SetInternal(err)
}
if adviceLevel == advisor.Error {
@@ -657,14 +657,14 @@ func (s *Server) sqlCheck(
catalog catalog.Catalog,
) (advisor.Status, []advisor.Advice, error) {
var adviceList []advisor.Advice
- policy, err := s.store.GetNormalSchemaReviewPolicy(ctx, &api.PolicyFind{EnvironmentID: &environmentID})
+ policy, err := s.store.GetNormalSQLReviewPolicy(ctx, &api.PolicyFind{EnvironmentID: &environmentID})
if err != nil {
if e, ok := err.(*common.Error); ok && e.Code == common.NotFound {
adviceList = []advisor.Advice{
{
Status: advisor.Warn,
Code: advisor.NotFound,
- Title: "Schema review policy is not configured or disabled",
+ Title: "SQL review policy is not configured or disabled",
Content: "",
},
}
@@ -673,7 +673,7 @@ func (s *Server) sqlCheck(
return advisor.Error, nil, err
}
- res, err := advisor.SchemaReviewCheck(statement, policy.RuleList, advisor.SQLReviewCheckContext{
+ res, err := advisor.SQLReviewCheck(statement, policy.RuleList, advisor.SQLReviewCheckContext{
Charset: dbCharacterSet,
Collation: dbCollation,
DbType: dbType,
diff --git a/server/task.go b/server/task.go
index a007bac956..ea89ab9ef2 100644
--- a/server/task.go
+++ b/server/task.go
@@ -644,11 +644,11 @@ func (s *Server) changeTaskStatusWithPatch(ctx context.Context, task *api.Task,
}
func (s *Server) triggerDatabaseStatementAdviseTask(ctx context.Context, statement string, task *api.Task) error {
- policyID, err := s.store.GetSchemaReviewPolicyIDByEnvID(ctx, task.Instance.EnvironmentID)
+ policyID, err := s.store.GetSQLReviewPolicyIDByEnvID(ctx, task.Instance.EnvironmentID)
if err != nil {
- // It's OK if we failed to find the schema review policy, just emit an error log
- log.Error("Failed to found schema review policy id for task",
+ // It's OK if we failed to find the SQL review policy, just emit an error log
+ log.Error("Failed to found SQL review policy id for task",
zap.Int("task_id", task.ID),
zap.String("task_name", task.Name),
zap.Int("environment_id", task.Instance.EnvironmentID),
diff --git a/server/task_check_executor_statement_advisor_composite.go b/server/task_check_executor_statement_advisor_composite.go
index a2dd34871e..a4eaa78627 100644
--- a/server/task_check_executor_statement_advisor_composite.go
+++ b/server/task_check_executor_statement_advisor_composite.go
@@ -11,10 +11,10 @@ import (
"github.com/bytebase/bytebase/store"
)
-// Schema review policy consists of a list of schema review rules.
+// SQL review policy consists of a list of SQL review rules.
// There is such a logical mapping in Bytebase backend:
-// 1. One schema review policy maps a TaskCheckRun.
-// 2. Each schema review rule type maps an advisor.Type.
+// 1. One SQL review policy maps a TaskCheckRun.
+// 2. Each SQL review rule type maps an advisor.Type.
// 3. Each [db.Type][AdvisorType] maps an advisor.
// NewTaskCheckStatementAdvisorCompositeExecutor creates a task check statement advisor composite executor.
@@ -40,7 +40,7 @@ func (*TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context, serv
return nil, common.Errorf(common.Invalid, "invalid check statement advise payload: %w", err)
}
- policy, err := server.store.GetNormalSchemaReviewPolicy(ctx, &api.PolicyFind{ID: &payload.PolicyID})
+ policy, err := server.store.GetNormalSQLReviewPolicy(ctx, &api.PolicyFind{ID: &payload.PolicyID})
if err != nil {
if e, ok := err.(*common.Error); ok && e.Code == common.NotFound {
return []api.TaskCheckResult{
@@ -48,12 +48,12 @@ func (*TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context, serv
Status: api.TaskCheckStatusWarn,
Namespace: api.AdvisorNamespace,
Code: advisor.NotFound.Int(),
- Title: "Empty schema review policy or disabled",
+ Title: "Empty SQL review policy or disabled",
Content: "",
},
}, nil
}
- return nil, common.Errorf(common.Internal, "failed to get schema review policy: %w", err)
+ return nil, common.Errorf(common.Internal, "failed to get SQL review policy: %w", err)
}
task, err := server.store.GetTaskByID(ctx, taskCheckRun.TaskID)
@@ -68,7 +68,7 @@ func (*TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context, serv
return nil, err
}
- adviceList, err := advisor.SchemaReviewCheck(payload.Statement, policy.RuleList, advisor.SQLReviewCheckContext{
+ adviceList, err := advisor.SQLReviewCheck(payload.Statement, policy.RuleList, advisor.SQLReviewCheckContext{
Charset: payload.Charset,
Collation: payload.Collation,
DbType: dbType,
diff --git a/server/task_check_scheduler.go b/server/task_check_scheduler.go
index 0e213e3165..75e6cffdd3 100644
--- a/server/task_check_scheduler.go
+++ b/server/task_check_scheduler.go
@@ -334,9 +334,9 @@ func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *ap
}
if s.server.feature(api.FeatureSQLReviewPolicy) && api.IsSQLReviewSupported(database.Instance.Engine, s.server.profile.Mode) {
- policyID, err := s.server.store.GetSchemaReviewPolicyIDByEnvID(ctx, task.Instance.EnvironmentID)
+ policyID, err := s.server.store.GetSQLReviewPolicyIDByEnvID(ctx, task.Instance.EnvironmentID)
if err != nil {
- return nil, fmt.Errorf("failed to get schema review policy ID for task: %v, in environment: %v, err: %w", task.Name, task.Instance.EnvironmentID, err)
+ return nil, fmt.Errorf("failed to get SQL review policy ID for task: %v, in environment: %v, err: %w", task.Name, task.Instance.EnvironmentID, err)
}
payload, err := json.Marshal(api.TaskCheckDatabaseStatementAdvisePayload{
Statement: statement,
diff --git a/sql-server/advise.go b/sql-server/advise.go
index dddd3679d7..924863501c 100644
--- a/sql-server/advise.go
+++ b/sql-server/advise.go
@@ -31,9 +31,9 @@ func (s *Server) registerAdvisorRoutes(g *echo.Group) {
// sqlCheckController godoc
// @Summary Check the SQL statement.
-// @Description Parse and check the SQL statement according to the schema review rules.
+// @Description Parse and check the SQL statement according to the SQL review rules.
// @Accept */*
-// @Tags Schema Review
+// @Tags SQL review
// @Produce json
// @Param statement query string true "The SQL statement."
// @Param databaseType query string true "The database type." Enums(MYSQL, POSTGRES, TIDB)
@@ -106,7 +106,7 @@ func sqlCheck(
) ([]advisor.Advice, error) {
var adviceList []advisor.Advice
- res, err := advisor.SchemaReviewCheck(statement, ruleList, advisor.SQLReviewCheckContext{
+ res, err := advisor.SQLReviewCheck(statement, ruleList, advisor.SQLReviewCheckContext{
Charset: dbCharacterSet,
Collation: dbCollation,
DbType: dbType,
diff --git a/store/demo/schema-migration-history/10001__data.sql b/store/demo/schema-migration-history/10001__data.sql
index f64ab4f3b9..adf89b4294 100644
--- a/store/demo/schema-migration-history/10001__data.sql
+++ b/store/demo/schema-migration-history/10001__data.sql
@@ -133,15 +133,15 @@ INSERT INTO "public"."task_check_run" ("id", "creator_id", "created_ts", "update
(101, 1, 1657272890, 1, 1657272892, 103, 'DONE', 'bb.task-check.database.connect', 0, '', '{"resultList": [{"title": "OK", "status": "SUCCESS", "content": "Successfully connected \"employee\""}]}', '{}'),
(102, 1, 1657272890, 1, 1657272892, 103, 'DONE', 'bb.task-check.instance.migration-schema', 0, '', '{"resultList": [{"title": "OK", "status": "SUCCESS", "content": "Instance \"DEMO\" has setup migration schema"}]}', '{}'),
(103, 1, 1657272890, 1, 1657272891, 103, 'DONE', 'bb.task-check.database.statement.syntax', 0, '', '{"resultList": [{"title": "Syntax OK", "status": "SUCCESS", "content": "OK"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "/* Establish baseline using current schema */"}'),
-(104, 1, 1657272890, 1, 1657272891, 103, 'DONE', 'bb.task-check.database.statement.advise', 0, '', '{"resultList": [{"code": 401, "title": "Empty schema review policy or disabled", "status": "WARN"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "/* Establish baseline using current schema */"}'),
+(104, 1, 1657272890, 1, 1657272891, 103, 'DONE', 'bb.task-check.database.statement.advise', 0, '', '{"resultList": [{"code": 401, "title": "Empty SQL review policy or disabled", "status": "WARN"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "/* Establish baseline using current schema */"}'),
(105, 1, 1657272927, 1, 1657272929, 104, 'DONE', 'bb.task-check.database.connect', 0, '', '{"resultList": [{"title": "OK", "status": "SUCCESS", "content": "Successfully connected \"employee\""}]}', '{}'),
(106, 1, 1657272927, 1, 1657272929, 104, 'DONE', 'bb.task-check.instance.migration-schema', 0, '', '{"resultList": [{"title": "OK", "status": "SUCCESS", "content": "Instance \"DEMO\" has setup migration schema"}]}', '{}'),
(107, 1, 1657272927, 1, 1657272928, 104, 'DONE', 'bb.task-check.database.statement.syntax', 0, '', '{"resultList": [{"title": "Syntax OK", "status": "SUCCESS", "content": "OK"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "Alter table\n employee\nadd\n column (\n EduBackgrounds varchar(50) not null,\n Email varchar(40) not null,\n PhoneNo varchar(15) not null,\n Credentials_type char(4) not null,\n Credentials_No varchar(10) not null,\n Manager varchar(14),\n Emergency_name varchar(16) not null,\n Emergency_phoneNo varchar(15) not null,\n Address varchar(60) not null\n )"}'),
-(108, 1, 1657272927, 1, 1657272928, 104, 'DONE', 'bb.task-check.database.statement.advise', 0, '', '{"resultList": [{"code": 401, "title": "Empty schema review policy or disabled", "status": "WARN"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "Alter table\n employee\nadd\n column (\n EduBackgrounds varchar(50) not null,\n Email varchar(40) not null,\n PhoneNo varchar(15) not null,\n Credentials_type char(4) not null,\n Credentials_No varchar(10) not null,\n Manager varchar(14),\n Emergency_name varchar(16) not null,\n Emergency_phoneNo varchar(15) not null,\n Address varchar(60) not null\n )"}'),
+(108, 1, 1657272927, 1, 1657272928, 104, 'DONE', 'bb.task-check.database.statement.advise', 0, '', '{"resultList": [{"code": 401, "title": "Empty SQL review policy or disabled", "status": "WARN"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "Alter table\n employee\nadd\n column (\n EduBackgrounds varchar(50) not null,\n Email varchar(40) not null,\n PhoneNo varchar(15) not null,\n Credentials_type char(4) not null,\n Credentials_No varchar(10) not null,\n Manager varchar(14),\n Emergency_name varchar(16) not null,\n Emergency_phoneNo varchar(15) not null,\n Address varchar(60) not null\n )"}'),
(109, 1, 1657273475, 1, 1657273477, 105, 'DONE', 'bb.task-check.database.connect', 0, '', '{"resultList": [{"title": "OK", "status": "SUCCESS", "content": "Successfully connected \"employee\""}]}', '{}'),
(110, 1, 1657273475, 1, 1657273477, 105, 'DONE', 'bb.task-check.instance.migration-schema', 0, '', '{"resultList": [{"title": "OK", "status": "SUCCESS", "content": "Instance \"DEMO\" has setup migration schema"}]}', '{}'),
(111, 1, 1657273475, 1, 1657273476, 105, 'DONE', 'bb.task-check.database.statement.syntax', 0, '', '{"resultList": [{"title": "Syntax OK", "status": "SUCCESS", "content": "OK"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "alter table\n employee drop column Address;"}'),
-(112, 1, 1657273475, 1, 1657273476, 105, 'DONE', 'bb.task-check.database.statement.advise', 0, '', '{"resultList": [{"code": 401, "title": "Empty schema review policy or disabled", "status": "WARN"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "alter table\n employee drop column Address;"}');
+(112, 1, 1657273475, 1, 1657273476, 105, 'DONE', 'bb.task-check.database.statement.advise', 0, '', '{"resultList": [{"code": 401, "title": "Empty SQL review policy or disabled", "status": "WARN"}]}', '{"dbType": "MYSQL", "charset": "utf8mb4", "collation": "utf8mb4_general_ci", "statement": "alter table\n employee drop column Address;"}');
INSERT INTO "public"."issue" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "project_id", "pipeline_id", "name", "status", "type", "description", "assignee_id", "payload") VALUES
(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 1, 101, 'Hello world!', 'OPEN', 'bb.issue.general', 'Welcome to Bytebase, this is the issue interface where developers and DBAs collaborate on database schema management issues such as:
diff --git a/store/policy.go b/store/policy.go
index 62a5377b85..96f3d1ad77 100644
--- a/store/policy.go
+++ b/store/policy.go
@@ -82,8 +82,8 @@ func (s *Store) GetPolicy(ctx context.Context, find *api.PolicyFind) (*api.Polic
// DeletePolicy deletes an existing ARCHIVED policy by PolicyDelete.
func (s *Store) DeletePolicy(ctx context.Context, delete *api.PolicyDelete) error {
// Validate policy.
- // Currently we only support PolicyTypeSchemaReview type policy to delete by id
- if delete.Type != api.PolicyTypeSchemaReview {
+ // Currently we only support PolicyTypeSQLReview type policy to delete by id
+ if delete.Type != api.PolicyTypeSQLReview {
return &common.Error{Code: common.Invalid, Err: fmt.Errorf("invalid policy type")}
}
@@ -177,30 +177,30 @@ func (s *Store) GetPipelineApprovalPolicy(ctx context.Context, environmentID int
return api.UnmarshalPipelineApprovalPolicy(policy.Payload)
}
-// GetNormalSchemaReviewPolicy will get the normal schema review policy for an environment.
-func (s *Store) GetNormalSchemaReviewPolicy(ctx context.Context, find *api.PolicyFind) (*advisor.SQLReviewPolicy, error) {
+// GetNormalSQLReviewPolicy will get the normal SQL review policy for an environment.
+func (s *Store) GetNormalSQLReviewPolicy(ctx context.Context, find *api.PolicyFind) (*advisor.SQLReviewPolicy, error) {
if find.ID != nil && *find.ID == api.DefaultPolicyID {
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("schema review policy not found with ID %d", *find.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("SQL review policy not found with ID %d", *find.ID)}
}
- pType := api.PolicyTypeSchemaReview
+ pType := api.PolicyTypeSQLReview
find.Type = &pType
policy, err := s.getPolicyRaw(ctx, find)
if err != nil {
return nil, err
}
if policy.RowStatus == api.Archived {
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("schema review policy ID: %d for environment %d is archived", policy.ID, policy.EnvironmentID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("SQL review policy ID: %d for environment %d is archived", policy.ID, policy.EnvironmentID)}
}
if policy.ID == api.DefaultPolicyID {
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("schema review policy ID: %d for environment %d not found", policy.ID, policy.EnvironmentID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("SQL review policy ID: %d for environment %d not found", policy.ID, policy.EnvironmentID)}
}
return api.UnmarshalSQLReviewPolicy(policy.Payload)
}
-// GetSchemaReviewPolicyIDByEnvID will get the schema review policy ID for an environment.
-func (s *Store) GetSchemaReviewPolicyIDByEnvID(ctx context.Context, environmentID int) (int, error) {
- pType := api.PolicyTypeSchemaReview
+// GetSQLReviewPolicyIDByEnvID will get the SQL review policy ID for an environment.
+func (s *Store) GetSQLReviewPolicyIDByEnvID(ctx context.Context, environmentID int) (int, error) {
+ pType := api.PolicyTypeSQLReview
policy, err := s.getPolicyRaw(ctx, &api.PolicyFind{
EnvironmentID: &environmentID,
Type: &pType,
diff --git a/tests/sql_review_test.go b/tests/sql_review_test.go
index e74d05d29d..084e325760 100644
--- a/tests/sql_review_test.go
+++ b/tests/sql_review_test.go
@@ -27,13 +27,13 @@ import (
)
var (
- schemaReviewAccessErr = fmt.Sprintf(`http response error code %d body "{\"message\":\"%s\"}\n"`, http.StatusForbidden, api.FeatureSQLReviewPolicy.AccessErrorMessage())
- noSchemaReviewPolicy = []api.TaskCheckResult{
+ sqlReviewAccessErr = fmt.Sprintf(`http response error code %d body "{\"message\":\"%s\"}\n"`, http.StatusForbidden, api.FeatureSQLReviewPolicy.AccessErrorMessage())
+ noSQLReviewPolicy = []api.TaskCheckResult{
{
Status: api.TaskCheckStatusWarn,
Namespace: api.AdvisorNamespace,
Code: advisor.NotFound.Int(),
- Title: "Empty schema review policy or disabled",
+ Title: "Empty SQL review policy or disabled",
Content: "",
},
}
@@ -243,22 +243,22 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {
prodEnvironment, err := findEnvironment(environments, "Prod")
a.NoError(err)
- policyPayload, err := prodTemplateSchemaReviewPolicy()
+ policyPayload, err := prodTemplateSQLReviewPolicy()
a.NoError(err)
err = ctl.upsertPolicy(api.PolicyUpsert{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
Payload: &policyPayload,
})
- a.EqualError(err, schemaReviewAccessErr)
+ a.EqualError(err, sqlReviewAccessErr)
err = ctl.setLicense()
a.NoError(err)
err = ctl.upsertPolicy(api.PolicyUpsert{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
Payload: &policyPayload,
})
a.NoError(err)
@@ -298,32 +298,32 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {
a.Equal(instance.ID, database.Instance.ID)
for _, t := range tests {
- result := createIssueAndReturnSchemaReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, t.statement)
+ result := createIssueAndReturnSQLReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, t.statement)
a.Equal(t.result, result)
}
- // disable the schema review policy
+ // disable the SQL review policy
disable := string(api.Archived)
err = ctl.upsertPolicy(api.PolicyUpsert{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
Payload: &policyPayload,
RowStatus: &disable,
})
a.NoError(err)
- result := createIssueAndReturnSchemaReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
- a.Equal(noSchemaReviewPolicy, result)
+ result := createIssueAndReturnSQLReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
+ a.Equal(noSQLReviewPolicy, result)
- // delete the schema review policy
+ // delete the SQL review policy
err = ctl.deletePolicy(api.PolicyDelete{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
})
a.NoError(err)
- result = createIssueAndReturnSchemaReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
- a.Equal(noSchemaReviewPolicy, result)
+ result = createIssueAndReturnSQLReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
+ a.Equal(noSQLReviewPolicy, result)
}
func TestSQLReviewForMySQL(t *testing.T) {
@@ -584,22 +584,22 @@ func TestSQLReviewForMySQL(t *testing.T) {
prodEnvironment, err := findEnvironment(environments, "Prod")
a.NoError(err)
- policyPayload, err := prodTemplateSchemaReviewPolicy()
+ policyPayload, err := prodTemplateSQLReviewPolicy()
a.NoError(err)
err = ctl.upsertPolicy(api.PolicyUpsert{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
Payload: &policyPayload,
})
- a.EqualError(err, schemaReviewAccessErr)
+ a.EqualError(err, sqlReviewAccessErr)
err = ctl.setLicense()
a.NoError(err)
err = ctl.upsertPolicy(api.PolicyUpsert{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
Payload: &policyPayload,
})
a.NoError(err)
@@ -639,35 +639,35 @@ func TestSQLReviewForMySQL(t *testing.T) {
a.Equal(instance.ID, database.Instance.ID)
for _, t := range tests {
- result := createIssueAndReturnSchemaReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, t.statement)
+ result := createIssueAndReturnSQLReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, t.statement)
a.Equal(t.result, result)
}
- // disable the schema review policy
+ // disable the SQL review policy
disable := string(api.Archived)
err = ctl.upsertPolicy(api.PolicyUpsert{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
Payload: &policyPayload,
RowStatus: &disable,
})
a.NoError(err)
- result := createIssueAndReturnSchemaReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
- a.Equal(noSchemaReviewPolicy, result)
+ result := createIssueAndReturnSQLReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
+ a.Equal(noSQLReviewPolicy, result)
- // delete the schema review policy
+ // delete the SQL review policy
err = ctl.deletePolicy(api.PolicyDelete{
EnvironmentID: prodEnvironment.ID,
- Type: api.PolicyTypeSchemaReview,
+ Type: api.PolicyTypeSQLReview,
})
a.NoError(err)
- result = createIssueAndReturnSchemaReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
- a.Equal(noSchemaReviewPolicy, result)
+ result = createIssueAndReturnSQLReviewResult(a, ctl, database.ID, project.ID, project.Creator.ID, statements[0])
+ a.Equal(noSQLReviewPolicy, result)
}
-func createIssueAndReturnSchemaReviewResult(a *require.Assertions, ctl *controller, databaseID int, projectID int, assigneeID int, statement string) []api.TaskCheckResult {
+func createIssueAndReturnSQLReviewResult(a *require.Assertions, ctl *controller, databaseID int, projectID int, assigneeID int, statement string) []api.TaskCheckResult {
createContext, err := json.Marshal(&api.UpdateSchemaContext{
MigrationType: db.Migrate,
DetailList: []*api.UpdateSchemaDetail{
@@ -689,7 +689,7 @@ func createIssueAndReturnSchemaReviewResult(a *require.Assertions, ctl *controll
})
a.NoError(err)
- result, err := ctl.getSchemaReviewResult(issue.ID)
+ result, err := ctl.GetSQLReviewResult(issue.ID)
a.NoError(err)
return result
diff --git a/tests/tests.go b/tests/tests.go
index 732b747c22..94c906312f 100644
--- a/tests/tests.go
+++ b/tests/tests.go
@@ -1377,9 +1377,9 @@ func (ctl *controller) deletePolicy(policyDelete api.PolicyDelete) error {
return nil
}
-// schemaReviewTaskCheckRunFinished will return schema review task check result for next task.
-// If the schema review task check is not done, return nil, false, nil.
-func (*controller) schemaReviewTaskCheckRunFinished(issue *api.Issue) ([]api.TaskCheckResult, bool, error) {
+// sqlReviewTaskCheckRunFinished will return SQL review task check result for next task.
+// If the SQL review task check is not done, return nil, false, nil.
+func (*controller) sqlReviewTaskCheckRunFinished(issue *api.Issue) ([]api.TaskCheckResult, bool, error) {
var result []api.TaskCheckResult
var latestTs int64
for _, stage := range issue.Pipeline.StageList {
@@ -1410,8 +1410,8 @@ func (*controller) schemaReviewTaskCheckRunFinished(issue *api.Issue) ([]api.Tas
return nil, true, nil
}
-// getSchemaReviewResult will wait for next task schema review task check to finish and return the task check result.
-func (ctl *controller) getSchemaReviewResult(id int) ([]api.TaskCheckResult, error) {
+// GetSQLReviewResult will wait for next task SQL review task check to finish and return the task check result.
+func (ctl *controller) GetSQLReviewResult(id int) ([]api.TaskCheckResult, error) {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
@@ -1430,9 +1430,9 @@ func (ctl *controller) getSchemaReviewResult(id int) ([]api.TaskCheckResult, err
return nil, fmt.Errorf("the status of issue %v is not pending approval", id)
}
- result, yes, err := ctl.schemaReviewTaskCheckRunFinished(issue)
+ result, yes, err := ctl.sqlReviewTaskCheckRunFinished(issue)
if err != nil {
- return nil, fmt.Errorf("failed to get schema review result for issue %v: %w", id, err)
+ return nil, fmt.Errorf("failed to get SQL review result for issue %v: %w", id, err)
}
if yes {
return result, nil
@@ -1441,8 +1441,8 @@ func (ctl *controller) getSchemaReviewResult(id int) ([]api.TaskCheckResult, err
return nil, nil
}
-// setDefaultSchemaReviewRulePayload sets the default payload for this rule.
-func setDefaultSchemaReviewRulePayload(ruleTp advisor.SQLReviewRuleType) (string, error) {
+// setDefaultSQLReviewRulePayload sets the default payload for this rule.
+func setDefaultSQLReviewRulePayload(ruleTp advisor.SQLReviewRuleType) (string, error) {
var payload []byte
var err error
switch ruleTp {
@@ -1491,7 +1491,7 @@ func setDefaultSchemaReviewRulePayload(ruleTp advisor.SQLReviewRuleType) (string
},
})
default:
- return "", fmt.Errorf("unknown schema review type for default payload: %s", ruleTp)
+ return "", fmt.Errorf("unknown SQL review type for default payload: %s", ruleTp)
}
if err != nil {
@@ -1500,8 +1500,8 @@ func setDefaultSchemaReviewRulePayload(ruleTp advisor.SQLReviewRuleType) (string
return string(payload), nil
}
-// prodTemplateSchemaReviewPolicy returns the default schema review policy.
-func prodTemplateSchemaReviewPolicy() (string, error) {
+// prodTemplateSQLReviewPolicy returns the default SQL review policy.
+func prodTemplateSQLReviewPolicy() (string, error) {
policy := advisor.SQLReviewPolicy{
Name: "Prod",
RuleList: []*advisor.SQLReviewRule{
@@ -1573,7 +1573,7 @@ func prodTemplateSchemaReviewPolicy() (string, error) {
}
for _, rule := range policy.RuleList {
- payload, err := setDefaultSchemaReviewRulePayload(rule.Type)
+ payload, err := setDefaultSQLReviewRulePayload(rule.Type)
if err != nil {
return "", err
}