Skip to content

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

fix: prior backup check (#11459)

p0ny57a66fbb73c7
diff --git a/backend/plugin/advisor/mssql/test/column_maximum_varchar_length.yaml b/backend/plugin/advisor/mssql/test/column_maximum_varchar_length.yaml
index e268699b8d..b5c0105a06 100644
--- a/backend/plugin/advisor/mssql/test/column_maximum_varchar_length.yaml
+++ b/backend/plugin/advisor/mssql/test/column_maximum_varchar_length.yaml
@@ -5,6 +5,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ADD b VARCHAR(3000);
want:
@@ -13,6 +14,7 @@
title: column.maximum-varchar-length
content: The maximum varchar length is 2560.
line: 1
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ALTER COLUMN a VARCHAR(MAX);
want:
@@ -21,6 +23,7 @@
title: column.maximum-varchar-length
content: The maximum varchar length is 2560.
line: 1
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ALTER COLUMN a NVARCHAR(MAX);
want:
@@ -29,4 +32,5 @@
title: column.maximum-varchar-length
content: The maximum varchar length is 2560.
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/column_no_null.yaml b/backend/plugin/advisor/mssql/test/column_no_null.yaml
index 57370d5404..4c4e1d69f9 100644
--- a/backend/plugin/advisor/mssql/test/column_no_null.yaml
+++ b/backend/plugin/advisor/mssql/test/column_no_null.yaml
@@ -11,12 +11,14 @@
title: column.no-null
content: Column [age] is nullable, which is not allowed.
line: 4
+ column: 0
details: ""
- status: WARN
code: 402
title: column.no-null
content: Column [address] is nullable, which is not allowed.
line: 5
+ column: 0
details: ""
- statement: |-
CREATE TABLE MyTable (
@@ -32,6 +34,7 @@
title: column.no-null
content: Column [address] is nullable, which is not allowed.
line: 5
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ALTER COLUMN Name VARCHAR(100) NULL;
want:
@@ -40,6 +43,7 @@
title: column.no-null
content: Column [name] is nullable, which is not allowed.
line: 1
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ALTER COLUMN Name VARCHAR(100) NOT NULL;
want:
@@ -48,6 +52,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ADD Age INT;
want:
@@ -56,6 +61,7 @@
title: column.no-null
content: Column [age] is nullable, which is not allowed.
line: 1
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ADD Age INT NULL;
want:
@@ -64,6 +70,7 @@
title: column.no-null
content: Column [age] is nullable, which is not allowed.
line: 1
+ column: 0
details: ""
- statement: ALTER TABLE MyTable ADD Age INT NOT NULL;
want:
@@ -72,4 +79,5 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/column_required.yaml b/backend/plugin/advisor/mssql/test/column_required.yaml
index f435d8ce39..75bddb74d9 100644
--- a/backend/plugin/advisor/mssql/test/column_required.yaml
+++ b/backend/plugin/advisor/mssql/test/column_required.yaml
@@ -12,6 +12,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: |-
CREATE TABLE t (
@@ -24,30 +25,35 @@
title: column.required
content: Table t missing required column "created_ts"
line: 1
+ column: 0
details: ""
- status: WARN
code: 401
title: column.required
content: Table t missing required column "creator_id"
line: 1
+ column: 0
details: ""
- status: WARN
code: 401
title: column.required
content: Table t missing required column "id"
line: 1
+ column: 0
details: ""
- status: WARN
code: 401
title: column.required
content: Table t missing required column "updated_ts"
line: 1
+ column: 0
details: ""
- status: WARN
code: 401
title: column.required
content: Table t missing required column "updater_id"
line: 1
+ column: 0
details: ""
- statement: |-
CREATE TABLE t (
@@ -62,6 +68,7 @@
title: column.required
content: Table t missing required column "updated_ts"
line: 1
+ column: 0
details: ""
- statement: ALTER TABLE t DROP COLUMN created_ts;
want:
@@ -70,6 +77,7 @@
title: column.required
content: Table t missing required column "created_ts"
line: 1
+ column: 0
details: ""
- statement: ALTER TABLE t DROP COLUMN creator_id;
want:
@@ -78,4 +86,5 @@
title: column.required
content: Table t missing required column "creator_id"
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/naming_identifier_no_keyword.yaml b/backend/plugin/advisor/mssql/test/naming_identifier_no_keyword.yaml
index a2e83463ea..3fc258aed3 100644
--- a/backend/plugin/advisor/mssql/test/naming_identifier_no_keyword.yaml
+++ b/backend/plugin/advisor/mssql/test/naming_identifier_no_keyword.yaml
@@ -7,22 +7,26 @@
title: naming.identifier.no-keyword
content: Identifier [exec] is a keyword identifier and should be avoided.
line: 1
+ column: 0
details: ""
- status: WARN
code: 308
title: naming.identifier.no-keyword
content: Identifier [fillfactor] is a keyword identifier and should be avoided.
line: 1
+ column: 0
details: ""
- status: WARN
code: 308
title: naming.identifier.no-keyword
content: Identifier [add] is a keyword identifier and should be avoided.
line: 2
+ column: 0
details: ""
- status: WARN
code: 308
title: naming.identifier.no-keyword
content: Identifier [fillfactor] is a keyword identifier and should be avoided.
line: 2
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/naming_table.yaml b/backend/plugin/advisor/mssql/test/naming_table.yaml
index f0656c40aa..87cd490130 100644
--- a/backend/plugin/advisor/mssql/test/naming_table.yaml
+++ b/backend/plugin/advisor/mssql/test/naming_table.yaml
@@ -5,6 +5,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: CREATE TABLE [\\](ID INT);
want:
@@ -13,6 +14,7 @@
title: naming.table
content: '[\\] mismatches table naming convention, naming format should be "^[A-Z]([_A-Za-z])*$"'
line: 1
+ column: 0
details: ""
- statement: CREATE TABLE all_lowercase(ID INT);
want:
@@ -21,6 +23,7 @@
title: naming.table
content: all_lowercase mismatches table naming convention, naming format should be "^[A-Z]([_A-Za-z])*$"
line: 1
+ column: 0
details: ""
- statement: CREATE TABLE PascalCase(ID INT);
want:
@@ -29,6 +32,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: execute sp_rename 'Sales.SalesTerritory', 'SALESTERR';
want:
@@ -37,6 +41,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: execute sp_rename 'Sales.SalesTerritory', 'salesTerr';
want:
@@ -45,4 +50,5 @@
title: naming.table
content: salesTerr mismatches table naming convention, naming format should be "^[A-Z]([_A-Za-z])*$"
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/naming_table_no_keyword.yaml b/backend/plugin/advisor/mssql/test/naming_table_no_keyword.yaml
index a30fa4217c..d1c0da8242 100644
--- a/backend/plugin/advisor/mssql/test/naming_table_no_keyword.yaml
+++ b/backend/plugin/advisor/mssql/test/naming_table_no_keyword.yaml
@@ -5,6 +5,7 @@
title: naming.table.no-keyword
content: Table name [fillfactor] is a reserved keyword and should be avoided.
line: 1
+ column: 0
details: ""
- statement: CREATE TABLE MyDB.MySchema.[fillfactor] (id INT);
want:
@@ -13,6 +14,7 @@
title: naming.table.no-keyword
content: Table name [fillfactor] is a reserved keyword and should be avoided.
line: 1
+ column: 0
details: ""
- statement: CREATE TABLE Person(id INT);
want:
@@ -21,4 +23,5 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml b/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
index 929f17aaac..e5607d4cb0 100644
--- a/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
+++ b/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
@@ -5,6 +5,7 @@
title: schema.backward-compatibility
content: Drop table TEST_DB.dbo.MyTable may cause incompatibility with the existing data and code
line: 1
+ column: 0
details: ""
- statement: |-
CREATE TABLE MyTable(Id INT PRIMARY KEY);
@@ -15,6 +16,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: DROP SCHEMA MySchema;
want:
@@ -23,6 +25,7 @@
title: schema.backward-compatibility
content: Drop schema TEST_DB.myschema may cause incompatibility with the existing data and code
line: 1
+ column: 0
details: ""
- statement: |-
CREATE SCHEMA AUTHORIZATION dbo;
@@ -33,6 +36,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: DROP DATABASE MyDB;
want:
@@ -41,6 +45,7 @@
title: schema.backward-compatibility
content: Drop database mydb may cause incompatibility with the existing data and code
line: 1
+ column: 0
details: ""
- statement: |-
CREATE DATABASE MyDB;
@@ -51,6 +56,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: |-
ALTER TABLE MyTable DROP COLUMN MyColumnOne, MyColumnTwo;
@@ -68,42 +74,49 @@
title: schema.backward-compatibility
content: Drop column mycolumnone, mycolumntwo may cause incompatibility with the existing data and code
line: 1
+ column: 0
details: ""
- status: WARN
code: 111
title: schema.backward-compatibility
content: Alter COLUMN mycolumnone may cause incompatibility with the existing data and code
line: 2
+ column: 0
details: ""
- status: WARN
code: 106
title: schema.backward-compatibility
content: Add PRIMARY KEY may cause incompatibility with the existing data and code
line: 3
+ column: 0
details: ""
- status: WARN
code: 107
title: schema.backward-compatibility
content: Add UNIQUE KEY may cause incompatibility with the existing data and code
line: 4
+ column: 0
details: ""
- status: WARN
code: 109
title: schema.backward-compatibility
content: Add CHECK may cause incompatibility with the existing data and code
line: 5
+ column: 0
details: ""
- status: WARN
code: 108
title: schema.backward-compatibility
content: Add CHECK WITH NO CHECK may cause incompatibility with the existing data and code
line: 6
+ column: 0
details: ""
- status: WARN
code: 108
title: schema.backward-compatibility
content: Add FOREIGN KEY WITH NO CHECK may cause incompatibility with the existing data and code
line: 8
+ column: 0
details: ""
- statement: EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr';
want:
@@ -112,6 +125,7 @@
title: schema.backward-compatibility
content: Rename Table 'Sales.SalesTerritory' WITH may cause incompatibility with the existing data and code
line: 1
+ column: 0
details: ""
- statement: EXEC sp_rename 'dbo.ErrorLog.ErrorTime', 'ErrorDateTime', 'COLUMN';
want:
@@ -120,4 +134,5 @@
title: schema.backward-compatibility
content: Rename COLUMN 'dbo.ErrorLog.ErrorTime' may cause incompatibility with the existing data and code
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/statement_select_no_select_all.yaml b/backend/plugin/advisor/mssql/test/statement_select_no_select_all.yaml
index e0c5ddbd9c..31d8e275aa 100644
--- a/backend/plugin/advisor/mssql/test/statement_select_no_select_all.yaml
+++ b/backend/plugin/advisor/mssql/test/statement_select_no_select_all.yaml
@@ -5,6 +5,7 @@
title: statement.select.no-select-all
content: Avoid using SELECT *.
line: 1
+ column: 0
details: ""
- statement: SELECT a, b FROM t
want:
@@ -13,6 +14,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: SELECT a, b FROM (SELECT * from t1, t2) t
want:
@@ -21,6 +23,7 @@
title: statement.select.no-select-all
content: Avoid using SELECT *.
line: 1
+ column: 0
details: ""
- statement: INSERT INTO t SELECT * FROM t1
want:
@@ -29,4 +32,5 @@
title: statement.select.no-select-all
content: Avoid using SELECT *.
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/statement_where_require.yaml b/backend/plugin/advisor/mssql/test/statement_where_require.yaml
index f69aa048cd..297cd8670a 100644
--- a/backend/plugin/advisor/mssql/test/statement_where_require.yaml
+++ b/backend/plugin/advisor/mssql/test/statement_where_require.yaml
@@ -5,6 +5,7 @@
title: statement.where.require
content: WHERE clause is required for query specification.
line: 1
+ column: 0
details: ""
- statement: SELECT * FROM MyTable WHERE a = 1;
want:
@@ -13,6 +14,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: UPDATE MyTable SET a = 1;
want:
@@ -21,6 +23,7 @@
title: statement.where.require
content: WHERE clause is required for UPDATE statement.
line: 1
+ column: 0
details: ""
- statement: UPDATE MyTable SET a = 1 WHERE a = 1;
want:
@@ -29,6 +32,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: DELETE FROM MyTable;
want:
@@ -37,6 +41,7 @@
title: statement.where.require
content: WHERE clause is required for DELETE statement.
line: 1
+ column: 0
details: ""
- statement: DELETE FROM MyTable WHERE a = 1;
want:
@@ -45,6 +50,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: |-
WITH CteA AS (SELECT * FROM TableA WHERE a = 1),
@@ -56,12 +62,14 @@
title: statement.where.require
content: WHERE clause is required for query specification.
line: 2
+ column: 0
details: ""
- status: WARN
code: 202
title: statement.where.require
content: WHERE clause is required for query specification.
line: 3
+ column: 0
details: ""
- statement: SELECT 1;
want:
@@ -70,4 +78,5 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/table_drop_naming_convention.yaml b/backend/plugin/advisor/mssql/test/table_drop_naming_convention.yaml
index 4af9c3e4f9..5c3c2f67a0 100644
--- a/backend/plugin/advisor/mssql/test/table_drop_naming_convention.yaml
+++ b/backend/plugin/advisor/mssql/test/table_drop_naming_convention.yaml
@@ -5,6 +5,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: DROP TABLE Foo;
want:
@@ -13,6 +14,7 @@
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 [Foo], [Bar_delete];
want:
@@ -21,4 +23,5 @@
title: table.drop-naming-convention
content: '[foo] mismatches drop table naming convention, naming format should be "_delete$"'
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/table_no_foreign_key.yaml b/backend/plugin/advisor/mssql/test/table_no_foreign_key.yaml
index 3beb50cc0d..e6e7922ffb 100644
--- a/backend/plugin/advisor/mssql/test/table_no_foreign_key.yaml
+++ b/backend/plugin/advisor/mssql/test/table_no_foreign_key.yaml
@@ -11,6 +11,7 @@
title: table.no-foreign-key
content: FOREIGN KEY is not allowed in the table MyTable.
line: 3
+ column: 0
details: ""
- statement: |-
CREATE TABLE Customer
@@ -26,6 +27,7 @@
title: table.no-foreign-key
content: FOREIGN KEY is not allowed in the table Customer.
line: 6
+ column: 0
details: ""
- statement: |-
CREATE TABLE Customer
@@ -41,6 +43,7 @@
title: table.no-foreign-key
content: FOREIGN KEY is not allowed in the table Customer.
line: 7
+ column: 0
details: ""
- statement: |-
CREATE TABLE Customer
@@ -61,4 +64,5 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/table_require_pk.yaml b/backend/plugin/advisor/mssql/test/table_require_pk.yaml
index f20a7dcc9b..6f6abc2aea 100644
--- a/backend/plugin/advisor/mssql/test/table_require_pk.yaml
+++ b/backend/plugin/advisor/mssql/test/table_require_pk.yaml
@@ -9,6 +9,7 @@
title: table.require-pk
content: Table MySchema.MyTable requires PRIMARY KEY.
line: 1
+ column: 0
details: ""
- statement: |-
CREATE TABLE MySchema.MyTable (
@@ -21,6 +22,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: |-
CREATE TABLE MySchema.MyTable (
@@ -34,6 +36,7 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
- statement: ALTER TABLE MySchema.MyTable ADD CONSTRAINT PK_MyTable PRIMARY KEY (Id);
want:
@@ -42,4 +45,5 @@
title: OK
content: ""
line: 0
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mysql/advisor_statement_prior_backup_check.go b/backend/plugin/advisor/mysql/advisor_statement_prior_backup_check.go
index f6a5e9e294..fd89e3025e 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_prior_backup_check.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_prior_backup_check.go
@@ -96,7 +96,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx advisor.Context, _ string) ([
}
content = strings.TrimSuffix(content, ",")
content += fmt.Sprintf(" on table `%s`.`%s`, disallow mixing different types of DML statements", table.database, table.table)
- checker.adviceList = append(checker.adviceList, advisor.Advice{
+ adviceList = append(adviceList, advisor.Advice{
Status: checker.level,
Code: advisor.StatementPriorBackupCheck,
Title: checker.title,
diff --git a/backend/plugin/advisor/tidb/advisor_statement_prior_backup_check.go b/backend/plugin/advisor/tidb/advisor_statement_prior_backup_check.go
index 483b7a7450..a9e67a4192 100644
--- a/backend/plugin/advisor/tidb/advisor_statement_prior_backup_check.go
+++ b/backend/plugin/advisor/tidb/advisor_statement_prior_backup_check.go
@@ -85,7 +85,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx advisor.Context, _ string) ([
checker.text = stmtNode.Text()
checker.line = stmtNode.OriginTextPosition()
if err := checker.extractNode(stmtNode); err != nil {
- checker.adviceList = append(checker.adviceList, advisor.Advice{
+ adviceList = append(adviceList, advisor.Advice{
Status: checker.level,
Code: advisor.Internal,
Title: checker.title,
@@ -106,7 +106,7 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx advisor.Context, _ string) ([
}
content = strings.TrimSuffix(content, ",")
content += fmt.Sprintf(" on table `%s`.`%s`, disallow mixing different types of DML statements", table.database, table.table)
- checker.adviceList = append(checker.adviceList, advisor.Advice{
+ adviceList = append(adviceList, advisor.Advice{
Status: checker.level,
Code: advisor.StatementPriorBackupCheck,
Title: checker.title,
@@ -144,11 +144,10 @@ func databaseExists(ctx context.Context, driver *sql.DB, database string) bool {
}
type statementDisallowMixDMLChecker struct {
- adviceList []advisor.Advice
- level advisor.Status
- title string
- text string
- line int
+ level advisor.Status
+ title string
+ text string
+ line int
dmlStatementCount map[table]map[string]int
}