Skip to content

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

feat(sql-review): create objects with schema (#10824)

rebeliced56ab009c69e
diff --git a/backend/plugin/advisor/advisor.go b/backend/plugin/advisor/advisor.go
index a488594100..cc259225d3 100644
--- a/backend/plugin/advisor/advisor.go
+++ b/backend/plugin/advisor/advisor.go
@@ -355,6 +355,9 @@ const (
// PostgreSQLStatementDisallowCascade is an advisor type for PostgreSQL to disallow cascade.
PostgreSQLStatementDisallowCascade Type = "bb.plugin.advisor.postgresql.statement.disallow-cascade"
+ // PostgreSQLStatementCreateSpecifySchema is an advisor type for PostgreSQL to specify schema when creating.
+ PostgreSQLStatementCreateSpecifySchema Type = "bb.plugin.advisor.postgresql.statement.create-specify-schema"
+
// Oracle Advisor.
// OracleSyntax is an advisor type for Oracle syntax.
diff --git a/backend/plugin/advisor/code.go b/backend/plugin/advisor/code.go
index 6cf3ff9dc8..6db8b2448b 100644
--- a/backend/plugin/advisor/code.go
+++ b/backend/plugin/advisor/code.go
@@ -40,6 +40,7 @@ const (
StatementDisallowCascade Code = 213
StatementCheckSelectFullTableScanFailed Code = 214
StatementHasTableFullScan Code = 215
+ StatementCreateWithoutSchemaName Code = 216
// 301 ~ 399 naming error code
// 301 table naming advisor error code.
diff --git a/backend/plugin/advisor/config/sql-review.dev.yaml b/backend/plugin/advisor/config/sql-review.dev.yaml
index 1585744d89..0c8ece305d 100644
--- a/backend/plugin/advisor/config/sql-review.dev.yaml
+++ b/backend/plugin/advisor/config/sql-review.dev.yaml
@@ -59,6 +59,8 @@ ruleList:
level: WARNING
- type: statement.select-full-table-scan
level: WARNING
+ - type: statement.create-specify-schema
+ level: WARNING
- type: naming.table
level: WARNING
payload:
diff --git a/backend/plugin/advisor/config/sql-review.prod.yaml b/backend/plugin/advisor/config/sql-review.prod.yaml
index d48e952fce..ba3cdd2742 100644
--- a/backend/plugin/advisor/config/sql-review.prod.yaml
+++ b/backend/plugin/advisor/config/sql-review.prod.yaml
@@ -59,6 +59,8 @@ ruleList:
level: WARNING
- type: statement.select-full-table-scan
level: ERROR
+ - type: statement.create-specify-schema
+ level: WARNING
- type: naming.table
level: WARNING
payload:
diff --git a/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go b/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go
new file mode 100644
index 0000000000..1dbe6320f0
--- /dev/null
+++ b/backend/plugin/advisor/pg/advisor_statement_create_specify_schema.go
@@ -0,0 +1,123 @@
+package pg
+
+import (
+ "github.com/pkg/errors"
+
+ "github.com/bytebase/bytebase/backend/plugin/advisor"
+ "github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
+)
+
+var (
+ _ advisor.Advisor = (*StatementCreateSpecifySchema)(nil)
+ _ ast.Visitor = (*statementCreateSpecifySchemaChecker)(nil)
+)
+
+func init() {
+ advisor.Register(storepb.Engine_POSTGRES, advisor.PostgreSQLStatementCreateSpecifySchema, &StatementCreateSpecifySchema{})
+}
+
+type StatementCreateSpecifySchema struct {
+}
+
+func (*StatementCreateSpecifySchema) Check(ctx advisor.Context, _ string) ([]advisor.Advice, error) {
+ stmts, ok := ctx.AST.([]ast.Node)
+ if !ok {
+ return nil, errors.Errorf("failed to convert to Node")
+ }
+
+ level, err := advisor.NewStatusBySQLReviewRuleLevel(ctx.Rule.Level)
+ if err != nil {
+ return nil, err
+ }
+ checker := &statementCreateSpecifySchemaChecker{
+ level: level,
+ title: string(ctx.Rule.Type),
+ }
+
+ for _, stmt := range stmts {
+ ast.Walk(checker, stmt)
+ }
+
+ if len(checker.adviceList) == 0 {
+ checker.adviceList = append(checker.adviceList, advisor.Advice{
+ Status: advisor.Success,
+ Code: advisor.Ok,
+ Title: "OK",
+ Content: "",
+ })
+ }
+ return checker.adviceList, nil
+}
+
+type statementCreateSpecifySchemaChecker struct {
+ adviceList []advisor.Advice
+ level advisor.Status
+ title string
+}
+
+func (c *statementCreateSpecifySchemaChecker) Visit(node ast.Node) ast.Visitor {
+ switch n := node.(type) {
+ case *ast.CreateTableStmt:
+ if n.Name.Schema == "" {
+ c.adviceList = append(c.adviceList, advisor.Advice{
+ Status: c.level,
+ Code: advisor.StatementCreateWithoutSchemaName,
+ Title: c.title,
+ Content: "Table schema should be specified.",
+ Line: node.LastLine(),
+ })
+ }
+ case *ast.CreateExtensionStmt:
+ if n.Schema == "" {
+ c.adviceList = append(c.adviceList, advisor.Advice{
+ Status: c.level,
+ Code: advisor.StatementCreateWithoutSchemaName,
+ Title: c.title,
+ Content: "Extension schema should be specified.",
+ Line: node.LastLine(),
+ })
+ }
+ case *ast.CreateFunctionStmt:
+ if n.Function.Schema == "" {
+ c.adviceList = append(c.adviceList, advisor.Advice{
+ Status: c.level,
+ Code: advisor.StatementCreateWithoutSchemaName,
+ Title: c.title,
+ Content: "Function schema should be specified.",
+ Line: node.LastLine(),
+ })
+ }
+ case *ast.CreateIndexStmt:
+ if n.Index.Table.Schema == "" {
+ c.adviceList = append(c.adviceList, advisor.Advice{
+ Status: c.level,
+ Code: advisor.StatementCreateWithoutSchemaName,
+ Title: c.title,
+ Content: "Table schema for index should be specified.",
+ Line: node.LastLine(),
+ })
+ }
+ case *ast.CreateSequenceStmt:
+ if n.SequenceDef.SequenceName.Schema == "" {
+ c.adviceList = append(c.adviceList, advisor.Advice{
+ Status: c.level,
+ Code: advisor.StatementCreateWithoutSchemaName,
+ Title: c.title,
+ Content: "Sequence schema should be specified.",
+ Line: node.LastLine(),
+ })
+ }
+ case *ast.CreateTriggerStmt:
+ if n.Trigger.Table.Schema == "" {
+ c.adviceList = append(c.adviceList, advisor.Advice{
+ Status: c.level,
+ Code: advisor.StatementCreateWithoutSchemaName,
+ Title: c.title,
+ Content: "Table schema for trigger should be specified.",
+ Line: node.LastLine(),
+ })
+ }
+ }
+ return c
+}
diff --git a/backend/plugin/advisor/pg/pg_rules_test.go b/backend/plugin/advisor/pg/pg_rules_test.go
index 6559d186ff..8ab7197ec4 100644
--- a/backend/plugin/advisor/pg/pg_rules_test.go
+++ b/backend/plugin/advisor/pg/pg_rules_test.go
@@ -48,6 +48,7 @@ func TestPostgreSQLRules(t *testing.T) {
advisor.SchemaRuleCreateIndexConcurrently,
advisor.SchemaRuleStatementAddCheckNotValid,
advisor.SchemaRuleStatementDisallowAddNotNull,
+ advisor.SchemaRuleStatementCreateSpecifySchema,
}
for _, rule := range pgRules {
diff --git a/backend/plugin/advisor/pg/test/column_disallow_change_type.yaml b/backend/plugin/advisor/pg/test/column_disallow_change_type.yaml
index 8f5b7e5273..aa0c219357 100644
--- a/backend/plugin/advisor/pg/test/column_disallow_change_type.yaml
+++ b/backend/plugin/advisor/pg/test/column_disallow_change_type.yaml
@@ -5,6 +5,8 @@
title: column.disallow-change-type
content: The statement "ALTER TABLE tech_book ALTER COLUMN id SET DATA TYPE INTEGER" changes column type
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD COLUMN c1 int
want:
- status: SUCCESS
@@ -12,3 +14,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/column_maximum_character_length.yaml b/backend/plugin/advisor/pg/test/column_maximum_character_length.yaml
index 2e2b2da4c2..75703aa81f 100644
--- a/backend/plugin/advisor/pg/test/column_maximum_character_length.yaml
+++ b/backend/plugin/advisor/pg/test/column_maximum_character_length.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(name varchar(225));
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(name char(225));
want:
- status: WARN
@@ -19,6 +23,8 @@
title: column.maximum-character-length
content: The length of the CHAR column "name" in table "t" is bigger than 20, please use VARCHAR instead
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE public.tech_book ADD COLUMN name_2 char(225)
want:
- status: WARN
@@ -26,6 +32,8 @@
title: column.maximum-character-length
content: The length of the CHAR column "name_2" in table "public"."tech_book" is bigger than 20, please use VARCHAR instead
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ALTER COLUMN name SET DATA TYPE char(225)
want:
- status: WARN
@@ -33,3 +41,5 @@
title: column.maximum-character-length
content: The length of the CHAR column "name" in table "tech_book" is bigger than 20, please use VARCHAR instead
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/column_no_null.yaml b/backend/plugin/advisor/pg/test/column_no_null.yaml
index 26e34922fd..631499db15 100644
--- a/backend/plugin/advisor/pg/test/column_no_null.yaml
+++ b/backend/plugin/advisor/pg/test/column_no_null.yaml
@@ -9,11 +9,15 @@
title: column.no-null
content: Column "id" in "public"."book" cannot have NULL value
line: 2
+ column: 0
+ details: ""
- status: WARN
code: 402
title: column.no-null
content: Column "name" in "public"."book" cannot have NULL value
line: 3
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int, name varchar(255), PRIMARY KEY (id))
want:
- status: WARN
@@ -21,6 +25,8 @@
title: column.no-null
content: Column "name" in "public"."book" cannot have NULL value
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int PRIMARY KEY, name varchar(255))
want:
- status: WARN
@@ -28,6 +34,8 @@
title: column.no-null
content: Column "name" in "public"."book" cannot have NULL value
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int NOT NULL, name varchar(255))
want:
- status: WARN
@@ -35,6 +43,8 @@
title: column.no-null
content: Column "name" in "public"."book" cannot have NULL value
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int PRIMARY KEY, name varchar(255) NOT NULL)
want:
- status: SUCCESS
@@ -42,6 +52,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD COLUMN reader int
want:
- status: WARN
@@ -49,6 +61,8 @@
title: column.no-null
content: Column "reader" in "public"."tech_book" cannot have NULL value
line: 1
+ column: 0
+ details: ""
- statement: |-
ALTER TABLE tech_book DROP COLUMN id;
ALTER TABLE tech_book DROP COLUMN name;
@@ -59,6 +73,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ALTER COLUMN id SET NOT NULL
want:
- status: SUCCESS
@@ -66,6 +82,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ALTER COLUMN name DROP NOT NULL
want:
- status: WARN
@@ -73,6 +91,8 @@
title: column.no-null
content: Column "name" in "public"."tech_book" cannot have NULL value
line: 1
+ column: 0
+ details: ""
- statement: /* this is a comment */
want:
- status: SUCCESS
@@ -80,3 +100,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/column_require_default.yaml b/backend/plugin/advisor/pg/test/column_require_default.yaml
index 12c2c5c270..4038d0a07e 100644
--- a/backend/plugin/advisor/pg/test/column_require_default.yaml
+++ b/backend/plugin/advisor/pg/test/column_require_default.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(
a int,
@@ -16,6 +18,8 @@
title: column.require-default
content: Column "t"."a" in schema "public" doesn't have DEFAULT
line: 2
+ column: 0
+ details: ""
- statement: |-
ALTER TABLE tech_book ADD COLUMN a BLOB;
ALTER TABLE tech_book ADD COLUMN b timestamp;
@@ -25,8 +29,12 @@
title: column.require-default
content: Column "tech_book"."a" in schema "public" doesn't have DEFAULT
line: 1
+ column: 0
+ details: ""
- status: WARN
code: 420
title: column.require-default
content: Column "tech_book"."b" in schema "public" doesn't have DEFAULT
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/column_required.yaml b/backend/plugin/advisor/pg/test/column_required.yaml
index 18b47d743c..e3bd7b25ae 100644
--- a/backend/plugin/advisor/pg/test/column_required.yaml
+++ b/backend/plugin/advisor/pg/test/column_required.yaml
@@ -5,6 +5,8 @@
title: column.required
content: 'Table "book" requires columns: created_ts, creator_id, updated_ts, updater_id'
line: 1
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE book(
id int,
@@ -18,6 +20,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
ALTER TABLE tech_book ADD COLUMN creator_id int;
ALTER TABLE tech_book RENAME COLUMN creator_id TO creator;
@@ -27,6 +31,8 @@
title: column.required
content: 'Table "tech_book" requires columns: creator_id'
line: 2
+ column: 0
+ details: ""
- statement: |-
ALTER TABLE tech_book ADD COLUMN creator_id int;
ALTER TABLE tech_book DROP COLUMN creator_id;
@@ -36,3 +42,5 @@
title: column.required
content: 'Table "tech_book" requires columns: creator_id'
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/column_type_disallow_list.yaml b/backend/plugin/advisor/pg/test/column_type_disallow_list.yaml
index d07eada0c6..276c6b9d3b 100644
--- a/backend/plugin/advisor/pg/test/column_type_disallow_list.yaml
+++ b/backend/plugin/advisor/pg/test/column_type_disallow_list.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(a int, b JSON);
want:
- status: WARN
@@ -12,6 +14,8 @@
title: column.type-disallow-list
content: Disallow column type JSON but column "t"."b" is
line: 1
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(d char(5));
ALTER TABLE t add COLUMN a JSON;
@@ -21,3 +25,5 @@
title: column.type-disallow-list
content: Disallow column type JSON but column "t"."a" is
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/index_create_concurrently.yaml b/backend/plugin/advisor/pg/test/index_create_concurrently.yaml
index 2b209ee2d5..a3aef4aaf1 100644
--- a/backend/plugin/advisor/pg/test/index_create_concurrently.yaml
+++ b/backend/plugin/advisor/pg/test/index_create_concurrently.yaml
@@ -5,6 +5,8 @@
title: index.create-concurrently
content: Creating indexes will block writes on the table, unless use CONCURRENTLY
line: 1
+ column: 0
+ details: ""
- statement: create index concurrently on tech_book(id);
want:
- status: SUCCESS
@@ -12,3 +14,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/index_key_number_limit.yaml b/backend/plugin/advisor/pg/test/index_key_number_limit.yaml
index 44fb7feb61..e724baa8e5 100644
--- a/backend/plugin/advisor/pg/test/index_key_number_limit.yaml
+++ b/backend/plugin/advisor/pg/test/index_key_number_limit.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(name varchar(225));
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(name char(225), PRIMARY KEY (name));
want:
- status: SUCCESS
@@ -19,6 +23,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(id int, name char(225), c1 int, c2 int, c3 int, c4 int, CONSTRAINT t_id_name PRIMARY KEY (id, name, c1, c2, c3, c4));
want:
- status: WARN
@@ -26,6 +32,8 @@
title: index.key-number-limit
content: The number of keys of index "t_id_name" in table "t" should be not greater than 5
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE t(id int, name char(225), c1 int, c2 int, c3 int, c4 int, CONSTRAINT t_id_name UNIQUE (id, name, c1, c2, c3, c4));
want:
- status: WARN
@@ -33,6 +41,8 @@
title: index.key-number-limit
content: The number of keys of index "t_id_name" in table "t" should be not greater than 5
line: 1
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE address(id int, phone varchar(225), c1 int, c2 int, c3 int, c4 int);
CREATE INDEX idx_address_phone ON address(id, phone, c1, c2, c3, c4);
@@ -42,6 +52,8 @@
title: index.key-number-limit
content: The number of keys of index "idx_address_phone" in table "address" should be not greater than 5
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE address(id int, phone varchar(225), c1 int, c2 int, c3 int, c4 int);
CREATE UNIQUE INDEX idx_address_phone ON address(id, phone, c2, c1, c3, c4);
@@ -51,6 +63,8 @@
title: index.key-number-limit
content: The number of keys of index "idx_address_phone" in table "address" should be not greater than 5
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE address(id int, phone varchar(225), c1 int, c2 int, c3 int, c4 int);
ALTER TABLE address ADD CONSTRAINT address_id_name UNIQUE (id, phone, c1, c2, c3, c4);
@@ -60,3 +74,5 @@
title: index.key-number-limit
content: The number of keys of index "address_id_name" in table "address" should be not greater than 5
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/index_no_duplicate_column.yaml b/backend/plugin/advisor/pg/test/index_no_duplicate_column.yaml
index d332203a35..1ca3a3dac9 100644
--- a/backend/plugin/advisor/pg/test/index_no_duplicate_column.yaml
+++ b/backend/plugin/advisor/pg/test/index_no_duplicate_column.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t (
a int,
@@ -15,6 +17,8 @@
title: index.no-duplicate-column
content: PRIMARY KEY "" has duplicate column "t"."a"
line: 3
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(a int);
CREATE INDEX idx_a on t(a, a);
@@ -24,6 +28,8 @@
title: index.no-duplicate-column
content: INDEX "idx_a" has duplicate column "t"."a"
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(a int);
ALTER TABLE t ADD CONSTRAINT uk_a UNIQUE (a, a);
@@ -33,6 +39,8 @@
title: index.no-duplicate-column
content: UNIQUE KEY "uk_a" has duplicate column "t"."a"
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(a int);
ALTER TABLE t ADD CONSTRAINT pk_a PRIMARY KEY (a, a);
@@ -42,6 +50,8 @@
title: index.no-duplicate-column
content: PRIMARY KEY "pk_a" has duplicate column "t"."a"
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(a int);
ALTER TABLE t ADD CONSTRAINT fk_a FOREIGN KEY (a, a) REFERENCES t1(a, b);
@@ -51,3 +61,5 @@
title: index.no-duplicate-column
content: FOREIGN KEY "fk_a" has duplicate column "t"."a"
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/index_primary_key_type_allowlist.yaml b/backend/plugin/advisor/pg/test/index_primary_key_type_allowlist.yaml
index dfaad583fc..28949541da 100644
--- a/backend/plugin/advisor/pg/test/index_primary_key_type_allowlist.yaml
+++ b/backend/plugin/advisor/pg/test/index_primary_key_type_allowlist.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(a BIGSERIAL, PRIMARY KEY(a));
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(
a varchar(20) PRIMARY KEY
@@ -22,6 +26,8 @@
title: index.primary-key-type-allowlist
content: The column "a" is one of the primary key, but its type "character varying(20)" is not in allowlist
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(
a varchar(20),
@@ -33,3 +39,5 @@
title: index.primary-key-type-allowlist
content: The column "a" is one of the primary key, but its type "character varying(20)" is not in allowlist
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/index_total_number_limit.yaml b/backend/plugin/advisor/pg/test/index_total_number_limit.yaml
index 21c866a394..32d6497f3d 100644
--- a/backend/plugin/advisor/pg/test/index_total_number_limit.yaml
+++ b/backend/plugin/advisor/pg/test/index_total_number_limit.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE INDEX idx_id_name on tech_book(id, name)
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE INDEX idx_id_name_1 on tech_book(id, name);
CREATE INDEX idx_id_name_2 on tech_book(id, name);
@@ -24,6 +28,8 @@
title: index.total-number-limit
content: The count of index in table "public"."tech_book" should be no more than 5, but found 8
line: 5
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(a int PRIMARY KEY, b int, c int);
CREATE INDEX idx_a_b_1 on t(a, b);
@@ -37,6 +43,8 @@
title: index.total-number-limit
content: The count of index in table "public"."t" should be no more than 5, but found 6
line: 6
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(
a int PRIMARY KEY,
@@ -53,3 +61,5 @@
title: index.total-number-limit
content: The count of index in table "public"."t" should be no more than 5, but found 6
line: 9
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/naming_column.yaml b/backend/plugin/advisor/pg/test/naming_column.yaml
index 0112ae27fe..5df9efe826 100644
--- a/backend/plugin/advisor/pg/test/naming_column.yaml
+++ b/backend/plugin/advisor/pg/test/naming_column.yaml
@@ -5,6 +5,8 @@
title: naming.column
content: '"book"."creatorId" mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int, qavszgslczmsacubtvyymzhojfytkcmon int)
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int, creator_Id int)
want:
- status: SUCCESS
@@ -19,6 +23,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int, creator_id int)
want:
- status: SUCCESS
@@ -26,6 +32,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE book(id int, creator_id int);
ALTER TABLE book ADD COLUMN "creatorId" int
@@ -35,6 +43,8 @@
title: naming.column
content: '"book"."creatorId" mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE book(id int, creator_id int);
ALTER TABLE book ADD COLUMN "creator" int
@@ -44,6 +54,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE book(id int, creator_id int);
ALTER TABLE book RENAME COLUMN creator_id TO "creatorId"
@@ -53,6 +65,8 @@
title: naming.column
content: '"book"."creatorId" mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 2
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE book(id int, creator_id int);
ALTER TABLE book RENAME COLUMN creator_id TO "creator"
@@ -62,3 +76,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/naming_index_fk.yaml b/backend/plugin/advisor/pg/test/naming_index_fk.yaml
index 2789b3702a..eeaa164bac 100644
--- a/backend/plugin/advisor/pg/test/naming_index_fk.yaml
+++ b/backend/plugin/advisor/pg/test/naming_index_fk.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id)
want:
- status: WARN
@@ -12,6 +14,8 @@
title: naming.index.fk
content: Foreign key in table "tech_book" mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found "fk_author_id"
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT wlwflloczhmazamdotbibvqrrzyhmvkslvyzpmlmxt FOREIGN KEY (author_id) REFERENCES author (id)
want:
- status: WARN
@@ -19,6 +23,8 @@
title: naming.index.fk
content: Foreign key in table "tech_book" mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found "wlwflloczhmazamdotbibvqrrzyhmvkslvyzpmlmxt"
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD COLUMN author_id INT CONSTRAINT fk_tech_book_author_id_author_id REFERENCES author (id)
want:
- status: SUCCESS
@@ -26,6 +32,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD COLUMN author_id INT CONSTRAINT fk_author_id REFERENCES author (id)
want:
- status: WARN
@@ -33,6 +41,8 @@
title: naming.index.fk
content: Foreign key in table "tech_book" mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found "fk_author_id"
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT, author_id INT, CONSTRAINT fk_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id))
want:
- status: SUCCESS
@@ -40,6 +50,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT, author_id INT, CONSTRAINT fk_book_author_id FOREIGN KEY (author_id) REFERENCES author (id))
want:
- status: WARN
@@ -47,6 +59,8 @@
title: naming.index.fk
content: Foreign key in table "book" mismatches the naming convention, expect "^$|^fk_book_author_id_author_id$" but found "fk_book_author_id"
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT, author_id INT CONSTRAINT fk_book_author_id_author_id REFERENCES author (id))
want:
- status: SUCCESS
@@ -54,6 +68,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
-- this is the first line.
CREATE TABLE book(
@@ -66,3 +82,5 @@
title: naming.index.fk
content: Foreign key in table "book" mismatches the naming convention, expect "^$|^fk_book_author_id_author_id$" but found "fk_book_author_id"
line: 4
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/naming_index_idx.yaml b/backend/plugin/advisor/pg/test/naming_index_idx.yaml
index 21e22323e4..2f48cd1cb0 100644
--- a/backend/plugin/advisor/pg/test/naming_index_idx.yaml
+++ b/backend/plugin/advisor/pg/test/naming_index_idx.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE INDEX tech_book_id_name ON tech_book(id, name)
want:
- status: WARN
@@ -12,6 +14,8 @@
title: naming.index.idx
content: Index in table "tech_book" mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found "tech_book_id_name"
line: 1
+ column: 0
+ details: ""
- statement: CREATE INDEX wfdtqyetsyoovcvikjlyfukxyjxxxhifl ON tech_book(id, name)
want:
- status: WARN
@@ -19,6 +23,8 @@
title: naming.index.idx
content: Index in table "tech_book" mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found "wfdtqyetsyoovcvikjlyfukxyjxxxhifl"
line: 1
+ column: 0
+ details: ""
- statement: ALTER INDEX old_index RENAME TO idx_tech_book_id_name
want:
- status: SUCCESS
@@ -26,6 +32,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER INDEX old_index RENAME TO idx_tech_book
want:
- status: WARN
@@ -33,3 +41,5 @@
title: naming.index.idx
content: Index in table "tech_book" mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found "idx_tech_book"
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/naming_index_pk.yaml b/backend/plugin/advisor/pg/test/naming_index_pk.yaml
index 905fec17c0..f5b2a56531 100644
--- a/backend/plugin/advisor/pg/test/naming_index_pk.yaml
+++ b/backend/plugin/advisor/pg/test/naming_index_pk.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT tech_book_id_name PRIMARY KEY (id, name)
want:
- status: WARN
@@ -12,6 +14,8 @@
title: naming.index.pk
content: Primary key in table "tech_book" mismatches the naming convention, expect "^$|^pk_tech_book_id_name$" but found "tech_book_id_name"
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT udmhjtnsaablcmjhqcznfiwtnevcehcvw PRIMARY KEY (id, name)
want:
- status: WARN
@@ -19,6 +23,8 @@
title: naming.index.pk
content: Primary key in table "tech_book" mismatches the naming convention, expect "^$|^pk_tech_book_id_name$" but found "udmhjtnsaablcmjhqcznfiwtnevcehcvw"
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT, name VARCHAR(20), CONSTRAINT pk_book_name PRIMARY KEY (name))
want:
- status: SUCCESS
@@ -26,6 +32,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
-- this is the first line.
CREATE TABLE book(
@@ -39,6 +47,8 @@
title: naming.index.pk
content: Primary key in table "book" mismatches the naming convention, expect "^$|^pk_book_name$" but found "tech_book_name"
line: 5
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT, name VARCHAR(20), PRIMARY KEY (name))
want:
- status: SUCCESS
@@ -46,6 +56,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT, name VARCHAR(20) PRIMARY KEY)
want:
- status: SUCCESS
@@ -53,6 +65,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT pk_tech_book_id_name PRIMARY KEY USING INDEX old_index
want:
- status: SUCCESS
@@ -60,6 +74,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT pk_tech_book PRIMARY KEY USING INDEX old_index
want:
- status: WARN
@@ -67,6 +83,8 @@
title: naming.index.pk
content: Primary key in table "tech_book" mismatches the naming convention, expect "^$|^pk_tech_book_id_name$" but found "pk_tech_book"
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book RENAME CONSTRAINT old_pk TO pk_tech_book_id_name
want:
- status: SUCCESS
@@ -74,6 +92,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book RENAME CONSTRAINT old_pk TO pk_tech_book
want:
- status: WARN
@@ -81,6 +101,8 @@
title: naming.index.pk
content: Primary key in table "tech_book" mismatches the naming convention, expect "^$|^pk_tech_book_id_name$" but found "pk_tech_book"
line: 1
+ column: 0
+ details: ""
- statement: ALTER INDEX old_pk RENAME TO pk_tech_book_id_name
want:
- status: SUCCESS
@@ -88,6 +110,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER INDEX old_pk RENAME TO pk_tech_book
want:
- status: WARN
@@ -95,3 +119,5 @@
title: naming.index.pk
content: Primary key in table "tech_book" mismatches the naming convention, expect "^$|^pk_tech_book_id_name$" but found "pk_tech_book"
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/naming_index_uk.yaml b/backend/plugin/advisor/pg/test/naming_index_uk.yaml
index 8f2bc3641d..e36729bbf8 100644
--- a/backend/plugin/advisor/pg/test/naming_index_uk.yaml
+++ b/backend/plugin/advisor/pg/test/naming_index_uk.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE UNIQUE INDEX tech_book_id_name ON tech_book(id, name)
want:
- status: WARN
@@ -12,6 +14,8 @@
title: naming.index.uk
content: Unique key in table "tech_book" mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found "tech_book_id_name"
line: 1
+ column: 0
+ details: ""
- statement: CREATE UNIQUE INDEX dzfzqbhnkiiegdhvqjeqoevesfuwcmokrehxlapoqj ON tech_book(id, name)
want:
- status: WARN
@@ -19,6 +23,8 @@
title: naming.index.uk
content: Unique key in table "tech_book" mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found "dzfzqbhnkiiegdhvqjeqoevesfuwcmokrehxlapoqj"
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT uk_tech_book_id_name UNIQUE (id, name)
want:
- status: SUCCESS
@@ -26,6 +32,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT tech_book_id_name UNIQUE (id, name)
want:
- status: WARN
@@ -33,6 +41,8 @@
title: naming.index.uk
content: Unique key in table "tech_book" mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found "tech_book_id_name"
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), CONSTRAINT uk_book_name UNIQUE (name))
want:
- status: SUCCESS
@@ -40,6 +50,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
-- this is the first line.
CREATE TABLE book(
@@ -53,6 +65,8 @@
title: naming.index.uk
content: Unique key in table "book" mismatches the naming convention, expect "^$|^uk_book_name$" but found "book_name"
line: 5
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE (name))
want:
- status: SUCCESS
@@ -60,6 +74,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT PRIMARY KEY, name VARCHAR(20) UNIQUE)
want:
- status: SUCCESS
@@ -67,6 +83,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT uk_tech_book_id_name UNIQUE USING INDEX old_index
want:
- status: SUCCESS
@@ -74,6 +92,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT uk_tech_book UNIQUE USING INDEX old_index
want:
- status: WARN
@@ -81,6 +101,8 @@
title: naming.index.uk
content: Unique key in table "tech_book" mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found "uk_tech_book"
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book RENAME CONSTRAINT old_uk TO uk_tech_book_id_name
want:
- status: SUCCESS
@@ -88,6 +110,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book RENAME CONSTRAINT old_uk TO uk_tech_book
want:
- status: WARN
@@ -95,6 +119,8 @@
title: naming.index.uk
content: Unique key in table "tech_book" mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found "uk_tech_book"
line: 1
+ column: 0
+ details: ""
- statement: ALTER INDEX old_uk RENAME TO uk_tech_book_id_name
want:
- status: SUCCESS
@@ -102,6 +128,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER INDEX old_uk RENAME TO uk_tech_book
want:
- status: WARN
@@ -109,3 +137,5 @@
title: naming.index.uk
content: Unique key in table "tech_book" mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found "uk_tech_book"
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/naming_table.yaml b/backend/plugin/advisor/pg/test/naming_table.yaml
index b9a79812a2..0a91d56648 100644
--- a/backend/plugin/advisor/pg/test/naming_table.yaml
+++ b/backend/plugin/advisor/pg/test/naming_table.yaml
@@ -5,6 +5,8 @@
title: naming.table
content: '"techBook" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE "rlcmidzlevbivwvcntihenpoibtiutqeb"(id int, name varchar(255))
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE _techBook(id int, name varchar(255))
want:
- status: WARN
@@ -19,6 +23,8 @@
title: naming.table
content: '"_techbook" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE techBook(id int, name varchar(255))
want:
- status: SUCCESS
@@ -26,6 +32,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id int, name varchar(255))
want:
- status: SUCCESS
@@ -33,6 +41,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book RENAME TO "TechBook"
want:
- status: WARN
@@ -40,6 +50,8 @@
title: naming.table
content: '"TechBook" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 1
+ column: 0
+ details: ""
- statement: |-
create table techBook(id int);
ALTER TABLE techBook RENAME TO tech_book_tmp;
@@ -49,6 +61,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE _techBook(id int, name varchar(255));
ALTER TABLE tech_book RENAME TO "TechBook";
@@ -58,8 +72,12 @@
title: naming.table
content: '"_techbook" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 1
+ column: 0
+ details: ""
- status: WARN
code: 301
title: naming.table
content: '"TechBook" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/schema_backward_compatibility.yaml b/backend/plugin/advisor/pg/test/schema_backward_compatibility.yaml
index 10ba031797..369d9594ab 100644
--- a/backend/plugin/advisor/pg/test/schema_backward_compatibility.yaml
+++ b/backend/plugin/advisor/pg/test/schema_backward_compatibility.yaml
@@ -5,3 +5,5 @@
title: schema.backward-compatibility
content: '"ALTER TABLE tech_book ALTER COLUMN name TYPE TEXT" may cause incompatibility with the existing data and code'
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_add_check_not_valid.yaml b/backend/plugin/advisor/pg/test/statement_add_check_not_valid.yaml
index a96cae2f92..393d534b24 100644
--- a/backend/plugin/advisor/pg/test/statement_add_check_not_valid.yaml
+++ b/backend/plugin/advisor/pg/test/statement_add_check_not_valid.yaml
@@ -5,6 +5,8 @@
title: statement.add-check-not-valid
content: Adding check constraints with validation will block reads and writes. You can add check constraints not valid and then validate separately
line: 1
+ column: 0
+ details: ""
- statement: alter table tech_book add constraint check_id check(id > 0) NOT VALID;
want:
- status: SUCCESS
@@ -12,3 +14,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_affected_row_limit.yaml b/backend/plugin/advisor/pg/test/statement_affected_row_limit.yaml
index a23ef20e45..71cbed1869 100644
--- a/backend/plugin/advisor/pg/test/statement_affected_row_limit.yaml
+++ b/backend/plugin/advisor/pg/test/statement_affected_row_limit.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: UPDATE tech_book SET id = 1
want:
- status: SUCCESS
@@ -12,3 +14,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_create_specify_schema.yaml b/backend/plugin/advisor/pg/test/statement_create_specify_schema.yaml
new file mode 100644
index 0000000000..9e4026c8f2
--- /dev/null
+++ b/backend/plugin/advisor/pg/test/statement_create_specify_schema.yaml
@@ -0,0 +1,18 @@
+- statement: CREATE TABLE t(id int);
+ want:
+ - status: WARN
+ code: 216
+ title: statement.create-specify-schema
+ content: Table schema should be specified.
+ line: 1
+ column: 0
+ details: ""
+- statement: CREATE TABLE public.t(id int);
+ want:
+ - status: SUCCESS
+ code: 0
+ title: OK
+ content: ""
+ line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_disallow_add_column_with_default.yaml b/backend/plugin/advisor/pg/test/statement_disallow_add_column_with_default.yaml
index a7fa120a35..d40cd46275 100644
--- a/backend/plugin/advisor/pg/test/statement_disallow_add_column_with_default.yaml
+++ b/backend/plugin/advisor/pg/test/statement_disallow_add_column_with_default.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD COLUMN c int DEFAULT 0;
want:
- status: WARN
@@ -12,3 +14,5 @@
title: statement.disallow-add-column-with-default
content: Adding column with DEFAULT will locked the whole table and rewriting each rows
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_disallow_add_not_null.yaml b/backend/plugin/advisor/pg/test/statement_disallow_add_not_null.yaml
index ba7ec5010a..0b694be3b9 100644
--- a/backend/plugin/advisor/pg/test/statement_disallow_add_not_null.yaml
+++ b/backend/plugin/advisor/pg/test/statement_disallow_add_not_null.yaml
@@ -5,6 +5,8 @@
title: statement.disallow-add-not-null
content: Setting NOT NULL will block reads and writes. You can use CHECK ("name" IS NOT NULL) instead
line: 1
+ column: 0
+ details: ""
- statement: |-
alter table tech_book add constraint check_name_not_null check(name IS NOT NULL) NOT VALID;
alter table tech_book validate constraint check_name_not_null;
@@ -14,3 +16,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_disallow_commit.yaml b/backend/plugin/advisor/pg/test/statement_disallow_commit.yaml
index 0293cbec31..80ea802b96 100644
--- a/backend/plugin/advisor/pg/test/statement_disallow_commit.yaml
+++ b/backend/plugin/advisor/pg/test/statement_disallow_commit.yaml
@@ -8,6 +8,8 @@
title: statement.disallow-commit
content: 'Commit is not allowed, related statement: "COMMIT;"'
line: 3
+ column: 0
+ details: ""
- statement: |-
START TRANSACTION;
CREATE TABLE techBook(id int, name varchar(255));
@@ -22,8 +24,12 @@
title: statement.disallow-commit
content: 'Commit is not allowed, related statement: "COMMIT;"'
line: 3
+ column: 0
+ details: ""
- status: WARN
code: 206
title: statement.disallow-commit
content: 'Commit is not allowed, related statement: "COMMIT;"'
line: 7
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_dml_dry_run.yaml b/backend/plugin/advisor/pg/test/statement_dml_dry_run.yaml
index df16988259..6935ed4653 100644
--- a/backend/plugin/advisor/pg/test/statement_dml_dry_run.yaml
+++ b/backend/plugin/advisor/pg/test/statement_dml_dry_run.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: DELETE FROM tech_book
want:
- status: SUCCESS
@@ -12,3 +14,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_insert_disallow_order_by_rand.yaml b/backend/plugin/advisor/pg/test/statement_insert_disallow_order_by_rand.yaml
index f25b64d047..0b77998925 100644
--- a/backend/plugin/advisor/pg/test/statement_insert_disallow_order_by_rand.yaml
+++ b/backend/plugin/advisor/pg/test/statement_insert_disallow_order_by_rand.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: INSERT INTO tech_book SELECT * FROM tech_book ORDER BY random()
want:
- status: WARN
@@ -12,3 +14,5 @@
title: statement.insert.disallow-order-by-rand
content: The INSERT statement uses ORDER BY random() or random_between(), related statement "INSERT INTO tech_book SELECT * FROM tech_book ORDER BY random()"
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_insert_must_specify_column.yaml b/backend/plugin/advisor/pg/test/statement_insert_must_specify_column.yaml
index bcf13aec8f..38e58e3f4c 100644
--- a/backend/plugin/advisor/pg/test/statement_insert_must_specify_column.yaml
+++ b/backend/plugin/advisor/pg/test/statement_insert_must_specify_column.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: INSERT INTO tech_book VALUES (1, '1')
want:
- status: WARN
@@ -12,3 +14,5 @@
title: statement.insert.must-specify-column
content: The INSERT statement must specify columns but "INSERT INTO tech_book VALUES (1, '1')" does not
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_insert_row_limit.yaml b/backend/plugin/advisor/pg/test/statement_insert_row_limit.yaml
index 1ea838146b..9401798dca 100644
--- a/backend/plugin/advisor/pg/test/statement_insert_row_limit.yaml
+++ b/backend/plugin/advisor/pg/test/statement_insert_row_limit.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: INSERT INTO tech_book values(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')
want:
- status: WARN
@@ -12,6 +14,8 @@
title: statement.insert.row-limit
content: The statement "INSERT INTO tech_book values(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')" inserts 6 rows. The count exceeds 5.
line: 1
+ column: 0
+ details: ""
- statement: INSERT INTO tech_book SELECT * FROM tech_book;
want:
- status: SUCCESS
@@ -19,3 +23,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_merge_alter_table.yaml b/backend/plugin/advisor/pg/test/statement_merge_alter_table.yaml
index ae9d236417..61035b6c43 100644
--- a/backend/plugin/advisor/pg/test/statement_merge_alter_table.yaml
+++ b/backend/plugin/advisor/pg/test/statement_merge_alter_table.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: |-
CREATE TABLE t(a int);
ALTER TABLE tech_book ADD COLUMN a int;
@@ -15,3 +17,5 @@
title: statement.merge-alter-table
content: There are 2 statements to modify table `t`
line: 3
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_select_no_select_all.yaml b/backend/plugin/advisor/pg/test/statement_select_no_select_all.yaml
index 04eb9fd903..82302592d6 100644
--- a/backend/plugin/advisor/pg/test/statement_select_no_select_all.yaml
+++ b/backend/plugin/advisor/pg/test/statement_select_no_select_all.yaml
@@ -5,6 +5,8 @@
title: statement.select.no-select-all
content: '"SELECT * FROM t" uses SELECT all'
line: 1
+ column: 0
+ details: ""
- statement: SELECT a, b FROM t
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: SELECT a, b FROM (SELECT * from t1, t2) t
want:
- status: WARN
@@ -19,6 +23,8 @@
title: statement.select.no-select-all
content: '"SELECT a, b FROM (SELECT * from t1, t2) t" uses SELECT all'
line: 1
+ column: 0
+ details: ""
- statement: INSERT INTO t SELECT * FROM t1
want:
- status: WARN
@@ -26,3 +32,5 @@
title: statement.select.no-select-all
content: '"INSERT INTO t SELECT * FROM t1" uses SELECT all'
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_where_no_leading_wildcard_like.yaml b/backend/plugin/advisor/pg/test/statement_where_no_leading_wildcard_like.yaml
index f4e3424b48..43769de859 100644
--- a/backend/plugin/advisor/pg/test/statement_where_no_leading_wildcard_like.yaml
+++ b/backend/plugin/advisor/pg/test/statement_where_no_leading_wildcard_like.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: SELECT * FROM t WHERE a LIKE '%abc'
want:
- status: WARN
@@ -12,6 +14,8 @@
title: statement.where.no-leading-wildcard-like
content: '"SELECT * FROM t WHERE a LIKE ''%abc''" uses leading wildcard LIKE'
line: 1
+ column: 0
+ details: ""
- statement: SELECT * FROM t WHERE a LIKE 'abc' OR a LIKE '%abc'
want:
- status: WARN
@@ -19,6 +23,8 @@
title: statement.where.no-leading-wildcard-like
content: '"SELECT * FROM t WHERE a LIKE ''abc'' OR a LIKE ''%abc''" uses leading wildcard LIKE'
line: 1
+ column: 0
+ details: ""
- statement: SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc'
want:
- status: WARN
@@ -26,6 +32,8 @@
title: statement.where.no-leading-wildcard-like
content: '"SELECT * FROM t WHERE a LIKE ''%acc'' OR a LIKE ''%abc''" uses leading wildcard LIKE'
line: 1
+ column: 0
+ details: ""
- statement: SELECT * FROM (SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc') t1
want:
- status: WARN
@@ -33,3 +41,5 @@
title: statement.where.no-leading-wildcard-like
content: '"SELECT * FROM (SELECT * FROM t WHERE a LIKE ''%acc'' OR a LIKE ''%abc'') t1" uses leading wildcard LIKE'
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/statement_where_require.yaml b/backend/plugin/advisor/pg/test/statement_where_require.yaml
index 21a9f8868e..d3e324df2b 100644
--- a/backend/plugin/advisor/pg/test/statement_where_require.yaml
+++ b/backend/plugin/advisor/pg/test/statement_where_require.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: DELETE FROM t1
want:
- status: WARN
@@ -12,6 +14,8 @@
title: statement.where.require
content: '"DELETE FROM t1" requires WHERE clause'
line: 1
+ column: 0
+ details: ""
- statement: UPDATE t1 SET a = 1
want:
- status: WARN
@@ -19,6 +23,8 @@
title: statement.where.require
content: '"UPDATE t1 SET a = 1" requires WHERE clause'
line: 1
+ column: 0
+ details: ""
- statement: DELETE FROM t1 WHERE a > 0
want:
- status: SUCCESS
@@ -26,6 +32,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: UPDATE t1 SET a = 1 WHERE a > 10
want:
- status: SUCCESS
@@ -33,6 +41,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: SELECT a FROM t
want:
- status: WARN
@@ -40,6 +50,8 @@
title: statement.where.require
content: '"SELECT a FROM t" requires WHERE clause'
line: 1
+ column: 0
+ details: ""
- statement: SELECT a FROM t WHERE a > 0
want:
- status: SUCCESS
@@ -47,6 +59,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: SELECT a FROM t WHERE a > (SELECT max(id) FROM user)
want:
- status: WARN
@@ -54,3 +68,5 @@
title: statement.where.require
content: '"SELECT a FROM t WHERE a > (SELECT max(id) FROM user)" requires WHERE clause'
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/system_charset_allowlist.yaml b/backend/plugin/advisor/pg/test/system_charset_allowlist.yaml
index c931246661..a65eb3f315 100644
--- a/backend/plugin/advisor/pg/test/system_charset_allowlist.yaml
+++ b/backend/plugin/advisor/pg/test/system_charset_allowlist.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE DATABASE test
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE DATABASE test WITH ENCODING 'LATIN1'
want:
- status: WARN
@@ -19,6 +23,8 @@
title: system.charset.allowlist
content: '"" used disabled encoding ''latin1'''
line: 0
+ column: 0
+ details: ""
- statement: /* this is a comment */
want:
- status: SUCCESS
@@ -26,3 +32,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/system_collation_allowlist.yaml b/backend/plugin/advisor/pg/test/system_collation_allowlist.yaml
index 40704800be..ce8dbd5df2 100644
--- a/backend/plugin/advisor/pg/test/system_collation_allowlist.yaml
+++ b/backend/plugin/advisor/pg/test/system_collation_allowlist.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(a text COLLATE "unknown")
want:
- status: WARN
@@ -12,6 +14,8 @@
title: system.collation.allowlist
content: Use disabled collation "unknown", related statement "CREATE TABLE t(a text COLLATE "unknown")"
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ADD COLUMN c1 text COLLATE "unknown"
want:
- status: WARN
@@ -19,6 +23,8 @@
title: system.collation.allowlist
content: Use disabled collation "unknown", related statement "ALTER TABLE tech_book ADD COLUMN c1 text COLLATE "unknown""
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ALTER COLUMN id TYPE text COLLATE "unknown"
want:
- status: WARN
@@ -26,3 +32,5 @@
title: system.collation.allowlist
content: Use disabled collation "unknown", related statement "ALTER TABLE tech_book ALTER COLUMN id TYPE text COLLATE "unknown""
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/system_comment_length.yaml b/backend/plugin/advisor/pg/test/system_comment_length.yaml
index 1ae2bc6fb0..f9793de371 100644
--- a/backend/plugin/advisor/pg/test/system_comment_length.yaml
+++ b/backend/plugin/advisor/pg/test/system_comment_length.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: comment on column public.name is 'is a to long column name'
want:
- status: WARN
@@ -12,6 +14,8 @@
title: system.comment.length
content: The length of comment should be within 20 characters
line: 1
+ column: 0
+ details: ""
- statement: comment on table public is 'is a table name'
want:
- status: SUCCESS
@@ -19,6 +23,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: comment on table public is 'is a to long table name long long long long long long long'
want:
- status: WARN
@@ -26,3 +32,5 @@
title: system.comment.length
content: The length of comment should be within 20 characters
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/table_disallow_partition.yaml b/backend/plugin/advisor/pg/test/table_disallow_partition.yaml
index 6ffb12f043..153bc89763 100644
--- a/backend/plugin/advisor/pg/test/table_disallow_partition.yaml
+++ b/backend/plugin/advisor/pg/test/table_disallow_partition.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(a int) PARTITION BY RANGE (a);
want:
- status: WARN
@@ -12,6 +14,8 @@
title: table.disallow-partition
content: Table partition is forbidden, but "CREATE TABLE t(a int) PARTITION BY RANGE (a);" creates
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE tech_book ATTACH PARTITION p1 DEFAULT;
want:
- status: WARN
@@ -19,3 +23,5 @@
title: table.disallow-partition
content: Table partition is forbidden, but "ALTER TABLE tech_book ATTACH PARTITION p1 DEFAULT;" creates
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/table_drop_naming_convention.yaml b/backend/plugin/advisor/pg/test/table_drop_naming_convention.yaml
index 7143a405ab..6193fd1423 100644
--- a/backend/plugin/advisor/pg/test/table_drop_naming_convention.yaml
+++ b/backend/plugin/advisor/pg/test/table_drop_naming_convention.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: DROP TABLE IF EXISTS foo
want:
- status: WARN
@@ -12,6 +14,8 @@
title: table.drop-naming-convention
content: '`foo` mismatches drop table naming convention, naming format should be "_delete$"'
line: 1
+ column: 0
+ details: ""
- statement: DROP TABLE IF EXISTS foo_delete, bar
want:
- status: WARN
@@ -19,3 +23,5 @@
title: table.drop-naming-convention
content: '`bar` mismatches drop table naming convention, naming format should be "_delete$"'
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/table_no_foreign_key.yaml b/backend/plugin/advisor/pg/test/table_no_foreign_key.yaml
index 9ffb550eaf..1fd188c91e 100644
--- a/backend/plugin/advisor/pg/test/table_no_foreign_key.yaml
+++ b/backend/plugin/advisor/pg/test/table_no_foreign_key.yaml
@@ -5,6 +5,8 @@
title: table.no-foreign-key
content: 'Foreign key is not allowed in the table "public"."tech_book", related statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id)"'
line: 1
+ column: 0
+ details: ""
- statement: CREATE TABLE book(id INT, author_id INT, CONSTRAINT fk_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id))
want:
- status: WARN
@@ -12,3 +14,5 @@
title: table.no-foreign-key
content: 'Foreign key is not allowed in the table "public"."book", related statement: "CREATE TABLE book(id INT, author_id INT, CONSTRAINT fk_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id))"'
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/pg/test/table_require_pk.yaml b/backend/plugin/advisor/pg/test/table_require_pk.yaml
index 49ff47050f..281e278674 100644
--- a/backend/plugin/advisor/pg/test/table_require_pk.yaml
+++ b/backend/plugin/advisor/pg/test/table_require_pk.yaml
@@ -5,6 +5,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(id INT, PRIMARY KEY (id))
want:
- status: SUCCESS
@@ -12,6 +14,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: CREATE TABLE t(id INT)
want:
- status: WARN
@@ -19,6 +23,8 @@
title: table.require-pk
content: 'Table "public"."t" requires PRIMARY KEY, related statement: "CREATE TABLE t(id INT)"'
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE "tech_book" DROP CONSTRAINT "old_pk"
want:
- status: WARN
@@ -26,6 +32,8 @@
title: table.require-pk
content: 'Table "public"."tech_book" requires PRIMARY KEY, related statement: "ALTER TABLE \"tech_book\" DROP CONSTRAINT \"old_pk\""'
line: 1
+ column: 0
+ details: ""
- statement: ALTER TABLE "tech_book" DROP CONSTRAINT "old_index"
want:
- status: SUCCESS
@@ -33,6 +41,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE "tech_book" DROP CONSTRAINT constraint_not_in_catalog
want:
- status: SUCCESS
@@ -40,6 +50,8 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
- statement: ALTER TABLE "tech_book" DROP COLUMN id
want:
- status: WARN
@@ -47,6 +59,8 @@
title: table.require-pk
content: 'Table "public"."tech_book" requires PRIMARY KEY, related statement: "ALTER TABLE \"tech_book\" DROP COLUMN id"'
line: 1
+ column: 0
+ details: ""
- statement: |-
ALTER TABLE tech_book ADD COLUMN column_not_in_pk int;
ALTER TABLE "tech_book" DROP COLUMN column_not_in_pk;
@@ -56,3 +70,5 @@
title: OK
content: ""
line: 0
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.go
index 5c67de98b0..0adf3a4cc5 100644
--- a/backend/plugin/advisor/sql_review.go
+++ b/backend/plugin/advisor/sql_review.go
@@ -97,6 +97,8 @@ const (
SchemaRuleStatementDisallowAddNotNull = "statement.disallow-add-not-null"
// SchemaRuleStatementDisallowAddColumn disallow to add column.
SchemaRuleStatementSelectFullTableScan = "statement.select-full-table-scan"
+ // SchemaRuleStatementCreateSpecifySchema disallow to create table without specifying schema.
+ SchemaRuleStatementCreateSpecifySchema = "statement.create-specify-schema"
// SchemaRuleTableRequirePK require the table to have a primary key.
SchemaRuleTableRequirePK SQLReviewRuleType = "table.require-pk"
@@ -1455,6 +1457,10 @@ func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine storepb.Engine) (Ty
case storepb.Engine_MYSQL, storepb.Engine_MARIADB, storepb.Engine_OCEANBASE:
return MySQLStatementSelectFullTableScan, nil
}
+ case SchemaRuleStatementCreateSpecifySchema:
+ if engine == storepb.Engine_POSTGRES {
+ return PostgreSQLStatementCreateSpecifySchema, nil
+ }
case SchemaRuleCommentLength:
if engine == storepb.Engine_POSTGRES {
return PostgreSQLCommentConvention, nil
diff --git a/backend/plugin/advisor/utils_for_tests.go b/backend/plugin/advisor/utils_for_tests.go
index 19783090dd..9c7650c1ed 100644
--- a/backend/plugin/advisor/utils_for_tests.go
+++ b/backend/plugin/advisor/utils_for_tests.go
@@ -355,7 +355,8 @@ func SetDefaultSQLReviewRulePayload(ruleTp SQLReviewRuleType, dbType storepb.Eng
SchemaRuleIndexTypeNoBlob,
SchemaRuleIdentifierNoKeyword,
SchemaRuleTableNameNoKeyword,
- SchemaRuleDisallowProcedure:
+ SchemaRuleDisallowProcedure,
+ SchemaRuleStatementCreateSpecifySchema:
case SchemaRuleTableDropNamingConvention:
payload, err = json.Marshal(NamingRulePayload{
Format: "_delete$",
diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.json
index dbac5a4a77..276c2df309 100644
--- a/frontend/src/locales/sql-review/en-US.json
+++ b/frontend/src/locales/sql-review/en-US.json
@@ -374,6 +374,10 @@
"title": "Check full table scan for queries",
"description": "Full table scan is a resource-intensive operation and may cause serious performance impact. Suggestion error level: Error"
},
+ "statement-create-specify-schema": {
+ "title": "Prohibit creating objects without specifying the schema",
+ "description": "If the schema is not specified, the object will be created in the default schema, which may cause unexpected results."
+ },
"schema-backward-compatibility": {
"title": "Check application backward compatibility",
"description": "Some changes may affect running applications, such as modifying the name of database object, adding new constraints, etc. This rule can avoid careless changes that lead to the failure of existing application. Suggestion error level: Warning"
diff --git a/frontend/src/locales/sql-review/es-ES.json b/frontend/src/locales/sql-review/es-ES.json
index 1d410df6c4..b45f81bac9 100644
--- a/frontend/src/locales/sql-review/es-ES.json
+++ b/frontend/src/locales/sql-review/es-ES.json
@@ -374,6 +374,10 @@
"title": "Verificar escaneo completo de tabla en consultas",
"description": "El escaneo completo de tabla es una operación intensiva en recursos y puede causar un impacto grave en el rendimiento. Nivel de sugerencia de error: Error"
},
+ "statement-create-specify-schema": {
+ "title": "Prohibir la creación de objetos sin especificar el esquema",
+ "description": "Si no se especifica el esquema, el objeto se creará en el esquema predeterminado, lo que puede causar resultados inesperados."
+ },
"schema-backward-compatibility": {
"title": "Comprobación de la compatibilidad con versiones anteriores de la aplicación",
"description": "Algunos cambios pueden afectar las aplicaciones en ejecución, como modificar el nombre del objeto de la base de datos, agregar nuevas restricciones, etc. Esta regla puede evitar cambios descuidados que lleven al fallo de la aplicación existente. Nivel de error sugerido: Advertencia"
diff --git a/frontend/src/locales/sql-review/ja-JP.json b/frontend/src/locales/sql-review/ja-JP.json
index 9a15c4c599..43a74cd8a5 100644
--- a/frontend/src/locales/sql-review/ja-JP.json
+++ b/frontend/src/locales/sql-review/ja-JP.json
@@ -374,6 +374,10 @@
"title": "クエリのフルテーブルスキャンをチェックする",
"description": "フルテーブルスキャンはリソースを消費する操作であり、重大なパフォーマンスの影響を引き起こす可能性があります。提案エラーレベル:エラー"
},
+ "statement-create-specify-schema": {
+ "title": "スキーマを指定せずにオブジェクトを作成することを禁止する",
+ "description": "スキーマが指定されていない場合、オブジェクトはデフォルトのスキーマに作成され、予期しない結果を引き起こす可能性があります。"
+ },
"schema-backward-compatibility": {
"title": "アプリケーションの後方互換性を確認する",
"description": "一部の変更は実行中のアプリケーションに影響を与える可能性があります。データベースオブジェクトの名前の変更や新しい制約の追加などが該当します。このルールにより、既存のアプリケーションの障害を防ぐことができます。提案されるエラーレベル:警告"
diff --git a/frontend/src/locales/sql-review/vi-VN.json b/frontend/src/locales/sql-review/vi-VN.json
index f9a4bc4597..d58d1198de 100644
--- a/frontend/src/locales/sql-review/vi-VN.json
+++ b/frontend/src/locales/sql-review/vi-VN.json
@@ -374,6 +374,10 @@
"title": "Kiểm tra quét toàn bộ bảng cho các truy vấn",
"description": "Quét toàn bộ bảng là một hoạt động tốn tài nguyên và có thể gây ảnh hưởng nghiêm trọng đến hiệu suất. Mức độ lỗi đề xuất: Lỗi"
},
+ "statement-create-specify-schema": {
+ "title": "Cấm tạo đối tượng mà không chỉ định schema",
+ "description": "Nếu không chỉ định schema, đối tượng sẽ được tạo trong schema mặc định, điều này có thể gây ra kết quả không mong muốn."
+ },
"schema-backward-compatibility": {
"title": "Kiểm tra khả năng tương thích ngược của ứng dụng",
"description": "Một số thay đổi có thể ảnh hưởng đến các ứng dụng đang chạy, chẳng hạn như sửa đổi tên đối tượng cơ sở dữ liệu, thêm các ràng buộc mới, v.v. Quy tắc này có thể tránh những thay đổi bất cẩn dẫn đến lỗi ứng dụng hiện có. Mức độ lỗi đề xuất: Cảnh báo"
diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.json
index f068575459..e782efad85 100644
--- a/frontend/src/locales/sql-review/zh-CN.json
+++ b/frontend/src/locales/sql-review/zh-CN.json
@@ -375,6 +375,10 @@
"title": "检查查询是否存在全表扫描",
"description": "全表扫描是一种消耗大量资源的操作,可能导致严重的性能影响。建议错误等级:错误"
},
+ "statement-create-specify-schema": {
+ "title": "禁止创建未指定 schema 的对象",
+ "description": "如果未指定 schema,对象将在默认模式中创建,可能导致意外结果。"
+ },
"schema-backward-compatibility": {
"title": "检查应用向后兼容性",
"description": "某些变更可能影响现有应用功能,例如修改数据库对象名,增加新的约束等,此规范可避免不谨慎变更导致现有应用运行失败。建议错误等级:警告"
diff --git a/frontend/src/types/sql-review-schema.yaml b/frontend/src/types/sql-review-schema.yaml
index cf6a42eb5a..b8aa0c62c8 100644
--- a/frontend/src/types/sql-review-schema.yaml
+++ b/frontend/src/types/sql-review-schema.yaml
@@ -242,6 +242,11 @@ ruleList:
- OCEANBASE
- MARIADB
componentList: []
+ - type: statement.create-specify-schema
+ category: STATEMENT
+ engineList:
+ - POSTGRES
+ componentList: []
- type: naming.table
category: NAMING
engineList:
diff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.ts
index 2c61318c3c..42b77ecd64 100644
--- a/frontend/src/types/sqlReview.ts
+++ b/frontend/src/types/sqlReview.ts
@@ -149,6 +149,7 @@ export type RuleType =
| "statement.add-check-not-valid"
| "statement.disallow-add-not-null"
| "statement.select-full-table-scan"
+ | "statement.create-specify-schema"
| "schema.backward-compatibility"
| "database.drop-empty-database"
| "system.charset.allowlist"