Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
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.yamlindex 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: OKcontent: ""line: 0+ column: 0details: ""- statement: ALTER TABLE MyTable ADD b VARCHAR(3000);want:@@ -13,6 +14,7 @@title: column.maximum-varchar-lengthcontent: The maximum varchar length is 2560.line: 1+ column: 0details: ""- statement: ALTER TABLE MyTable ALTER COLUMN a VARCHAR(MAX);want:@@ -21,6 +23,7 @@title: column.maximum-varchar-lengthcontent: The maximum varchar length is 2560.line: 1+ column: 0details: ""- statement: ALTER TABLE MyTable ALTER COLUMN a NVARCHAR(MAX);want:@@ -29,4 +32,5 @@title: column.maximum-varchar-lengthcontent: The maximum varchar length is 2560.line: 1+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/column_no_null.yaml b/backend/plugin/advisor/mssql/test/column_no_null.yamlindex 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-nullcontent: Column [age] is nullable, which is not allowed.line: 4+ column: 0details: ""- status: WARNcode: 402title: column.no-nullcontent: Column [address] is nullable, which is not allowed.line: 5+ column: 0details: ""- statement: |-CREATE TABLE MyTable (@@ -32,6 +34,7 @@title: column.no-nullcontent: Column [address] is nullable, which is not allowed.line: 5+ column: 0details: ""- statement: ALTER TABLE MyTable ALTER COLUMN Name VARCHAR(100) NULL;want:@@ -40,6 +43,7 @@title: column.no-nullcontent: Column [name] is nullable, which is not allowed.line: 1+ column: 0details: ""- statement: ALTER TABLE MyTable ALTER COLUMN Name VARCHAR(100) NOT NULL;want:@@ -48,6 +52,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: ALTER TABLE MyTable ADD Age INT;want:@@ -56,6 +61,7 @@title: column.no-nullcontent: Column [age] is nullable, which is not allowed.line: 1+ column: 0details: ""- statement: ALTER TABLE MyTable ADD Age INT NULL;want:@@ -64,6 +70,7 @@title: column.no-nullcontent: Column [age] is nullable, which is not allowed.line: 1+ column: 0details: ""- statement: ALTER TABLE MyTable ADD Age INT NOT NULL;want:@@ -72,4 +79,5 @@title: OKcontent: ""line: 0+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/column_required.yaml b/backend/plugin/advisor/mssql/test/column_required.yamlindex 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: OKcontent: ""line: 0+ column: 0details: ""- statement: |-CREATE TABLE t (@@ -24,30 +25,35 @@title: column.requiredcontent: Table t missing required column "created_ts"line: 1+ column: 0details: ""- status: WARNcode: 401title: column.requiredcontent: Table t missing required column "creator_id"line: 1+ column: 0details: ""- status: WARNcode: 401title: column.requiredcontent: Table t missing required column "id"line: 1+ column: 0details: ""- status: WARNcode: 401title: column.requiredcontent: Table t missing required column "updated_ts"line: 1+ column: 0details: ""- status: WARNcode: 401title: column.requiredcontent: Table t missing required column "updater_id"line: 1+ column: 0details: ""- statement: |-CREATE TABLE t (@@ -62,6 +68,7 @@title: column.requiredcontent: Table t missing required column "updated_ts"line: 1+ column: 0details: ""- statement: ALTER TABLE t DROP COLUMN created_ts;want:@@ -70,6 +77,7 @@title: column.requiredcontent: Table t missing required column "created_ts"line: 1+ column: 0details: ""- statement: ALTER TABLE t DROP COLUMN creator_id;want:@@ -78,4 +86,5 @@title: column.requiredcontent: Table t missing required column "creator_id"line: 1+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/naming_identifier_no_keyword.yaml b/backend/plugin/advisor/mssql/test/naming_identifier_no_keyword.yamlindex 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-keywordcontent: Identifier [exec] is a keyword identifier and should be avoided.line: 1+ column: 0details: ""- status: WARNcode: 308title: naming.identifier.no-keywordcontent: Identifier [fillfactor] is a keyword identifier and should be avoided.line: 1+ column: 0details: ""- status: WARNcode: 308title: naming.identifier.no-keywordcontent: Identifier [add] is a keyword identifier and should be avoided.line: 2+ column: 0details: ""- status: WARNcode: 308title: naming.identifier.no-keywordcontent: Identifier [fillfactor] is a keyword identifier and should be avoided.line: 2+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/naming_table.yaml b/backend/plugin/advisor/mssql/test/naming_table.yamlindex 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: OKcontent: ""line: 0+ column: 0details: ""- statement: CREATE TABLE [\\](ID INT);want:@@ -13,6 +14,7 @@title: naming.tablecontent: '[\\] mismatches table naming convention, naming format should be "^[A-Z]([_A-Za-z])*$"'line: 1+ column: 0details: ""- statement: CREATE TABLE all_lowercase(ID INT);want:@@ -21,6 +23,7 @@title: naming.tablecontent: all_lowercase mismatches table naming convention, naming format should be "^[A-Z]([_A-Za-z])*$"line: 1+ column: 0details: ""- statement: CREATE TABLE PascalCase(ID INT);want:@@ -29,6 +32,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: execute sp_rename 'Sales.SalesTerritory', 'SALESTERR';want:@@ -37,6 +41,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: execute sp_rename 'Sales.SalesTerritory', 'salesTerr';want:@@ -45,4 +50,5 @@title: naming.tablecontent: salesTerr mismatches table naming convention, naming format should be "^[A-Z]([_A-Za-z])*$"line: 1+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/naming_table_no_keyword.yaml b/backend/plugin/advisor/mssql/test/naming_table_no_keyword.yamlindex 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-keywordcontent: Table name [fillfactor] is a reserved keyword and should be avoided.line: 1+ column: 0details: ""- statement: CREATE TABLE MyDB.MySchema.[fillfactor] (id INT);want:@@ -13,6 +14,7 @@title: naming.table.no-keywordcontent: Table name [fillfactor] is a reserved keyword and should be avoided.line: 1+ column: 0details: ""- statement: CREATE TABLE Person(id INT);want:@@ -21,4 +23,5 @@title: OKcontent: ""line: 0+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml b/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yamlindex 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-compatibilitycontent: Drop table TEST_DB.dbo.MyTable may cause incompatibility with the existing data and codeline: 1+ column: 0details: ""- statement: |-CREATE TABLE MyTable(Id INT PRIMARY KEY);@@ -15,6 +16,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: DROP SCHEMA MySchema;want:@@ -23,6 +25,7 @@title: schema.backward-compatibilitycontent: Drop schema TEST_DB.myschema may cause incompatibility with the existing data and codeline: 1+ column: 0details: ""- statement: |-CREATE SCHEMA AUTHORIZATION dbo;@@ -33,6 +36,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: DROP DATABASE MyDB;want:@@ -41,6 +45,7 @@title: schema.backward-compatibilitycontent: Drop database mydb may cause incompatibility with the existing data and codeline: 1+ column: 0details: ""- statement: |-CREATE DATABASE MyDB;@@ -51,6 +56,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: |-ALTER TABLE MyTable DROP COLUMN MyColumnOne, MyColumnTwo;@@ -68,42 +74,49 @@title: schema.backward-compatibilitycontent: Drop column mycolumnone, mycolumntwo may cause incompatibility with the existing data and codeline: 1+ column: 0details: ""- status: WARNcode: 111title: schema.backward-compatibilitycontent: Alter COLUMN mycolumnone may cause incompatibility with the existing data and codeline: 2+ column: 0details: ""- status: WARNcode: 106title: schema.backward-compatibilitycontent: Add PRIMARY KEY may cause incompatibility with the existing data and codeline: 3+ column: 0details: ""- status: WARNcode: 107title: schema.backward-compatibilitycontent: Add UNIQUE KEY may cause incompatibility with the existing data and codeline: 4+ column: 0details: ""- status: WARNcode: 109title: schema.backward-compatibilitycontent: Add CHECK may cause incompatibility with the existing data and codeline: 5+ column: 0details: ""- status: WARNcode: 108title: schema.backward-compatibilitycontent: Add CHECK WITH NO CHECK may cause incompatibility with the existing data and codeline: 6+ column: 0details: ""- status: WARNcode: 108title: schema.backward-compatibilitycontent: Add FOREIGN KEY WITH NO CHECK may cause incompatibility with the existing data and codeline: 8+ column: 0details: ""- statement: EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr';want:@@ -112,6 +125,7 @@title: schema.backward-compatibilitycontent: Rename Table 'Sales.SalesTerritory' WITH may cause incompatibility with the existing data and codeline: 1+ column: 0details: ""- statement: EXEC sp_rename 'dbo.ErrorLog.ErrorTime', 'ErrorDateTime', 'COLUMN';want:@@ -120,4 +134,5 @@title: schema.backward-compatibilitycontent: Rename COLUMN 'dbo.ErrorLog.ErrorTime' may cause incompatibility with the existing data and codeline: 1+ column: 0details: ""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.yamlindex 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-allcontent: Avoid using SELECT *.line: 1+ column: 0details: ""- statement: SELECT a, b FROM twant:@@ -13,6 +14,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: SELECT a, b FROM (SELECT * from t1, t2) twant:@@ -21,6 +23,7 @@title: statement.select.no-select-allcontent: Avoid using SELECT *.line: 1+ column: 0details: ""- statement: INSERT INTO t SELECT * FROM t1want:@@ -29,4 +32,5 @@title: statement.select.no-select-allcontent: Avoid using SELECT *.line: 1+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/statement_where_require.yaml b/backend/plugin/advisor/mssql/test/statement_where_require.yamlindex 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.requirecontent: WHERE clause is required for query specification.line: 1+ column: 0details: ""- statement: SELECT * FROM MyTable WHERE a = 1;want:@@ -13,6 +14,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: UPDATE MyTable SET a = 1;want:@@ -21,6 +23,7 @@title: statement.where.requirecontent: WHERE clause is required for UPDATE statement.line: 1+ column: 0details: ""- statement: UPDATE MyTable SET a = 1 WHERE a = 1;want:@@ -29,6 +32,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: DELETE FROM MyTable;want:@@ -37,6 +41,7 @@title: statement.where.requirecontent: WHERE clause is required for DELETE statement.line: 1+ column: 0details: ""- statement: DELETE FROM MyTable WHERE a = 1;want:@@ -45,6 +50,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: |-WITH CteA AS (SELECT * FROM TableA WHERE a = 1),@@ -56,12 +62,14 @@title: statement.where.requirecontent: WHERE clause is required for query specification.line: 2+ column: 0details: ""- status: WARNcode: 202title: statement.where.requirecontent: WHERE clause is required for query specification.line: 3+ column: 0details: ""- statement: SELECT 1;want:@@ -70,4 +78,5 @@title: OKcontent: ""line: 0+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/table_drop_naming_convention.yaml b/backend/plugin/advisor/mssql/test/table_drop_naming_convention.yamlindex 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: OKcontent: ""line: 0+ column: 0details: ""- statement: DROP TABLE Foo;want:@@ -13,6 +14,7 @@title: table.drop-naming-conventioncontent: '[foo] mismatches drop table naming convention, naming format should be "_delete$"'line: 1+ column: 0details: ""- statement: DROP TABLE [Foo], [Bar_delete];want:@@ -21,4 +23,5 @@title: table.drop-naming-conventioncontent: '[foo] mismatches drop table naming convention, naming format should be "_delete$"'line: 1+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/table_no_foreign_key.yaml b/backend/plugin/advisor/mssql/test/table_no_foreign_key.yamlindex 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-keycontent: FOREIGN KEY is not allowed in the table MyTable.line: 3+ column: 0details: ""- statement: |-CREATE TABLE Customer@@ -26,6 +27,7 @@title: table.no-foreign-keycontent: FOREIGN KEY is not allowed in the table Customer.line: 6+ column: 0details: ""- statement: |-CREATE TABLE Customer@@ -41,6 +43,7 @@title: table.no-foreign-keycontent: FOREIGN KEY is not allowed in the table Customer.line: 7+ column: 0details: ""- statement: |-CREATE TABLE Customer@@ -61,4 +64,5 @@title: OKcontent: ""line: 0+ column: 0details: ""diff --git a/backend/plugin/advisor/mssql/test/table_require_pk.yaml b/backend/plugin/advisor/mssql/test/table_require_pk.yamlindex 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-pkcontent: Table MySchema.MyTable requires PRIMARY KEY.line: 1+ column: 0details: ""- statement: |-CREATE TABLE MySchema.MyTable (@@ -21,6 +22,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: |-CREATE TABLE MySchema.MyTable (@@ -34,6 +36,7 @@title: OKcontent: ""line: 0+ column: 0details: ""- statement: ALTER TABLE MySchema.MyTable ADD CONSTRAINT PK_MyTable PRIMARY KEY (Id);want:@@ -42,4 +45,5 @@title: OKcontent: ""line: 0+ column: 0details: ""diff --git a/backend/plugin/advisor/mysql/advisor_statement_prior_backup_check.go b/backend/plugin/advisor/mysql/advisor_statement_prior_backup_check.goindex 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.goindex 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 intdmlStatementCount map[table]map[string]int}