Skip to content

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

chore: warn if run into sp_rename (#12249)

h3n4lb3827ca8dc87
diff --git a/backend/plugin/advisor/mssql/advisor_migration_compatibility.go b/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
index 945c0df698..fd1d891d85 100644
--- a/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
@@ -294,51 +294,11 @@ func (l *migrationCompatibilityChecker) EnterExecute_body(ctx *parser.Execute_bo
if firstArgument.Execute_parameter().Constant().STRING() == nil {
return
}
- if len(unnamedArguments) == 2 {
- secondArgument := unnamedArguments[1]
- if secondArgument == nil {
- return
- }
- if secondArgument.Execute_parameter() == nil {
- return
- }
- if secondArgument.Execute_parameter().Constant() == nil {
- return
- }
- if secondArgument.Execute_parameter().Constant().STRING() == nil {
- return
- }
- l.adviceList = append(l.adviceList, advisor.Advice{
- Status: l.level,
- Code: advisor.CompatibilityRenameTable,
- Title: l.title,
- Content: fmt.Sprintf("Rename Table %s WITH may cause incompatibility with the existing data and code", firstArgument.GetText()),
- Line: ctx.GetStart().GetLine(),
- })
- } else if len(unnamedArguments) == 3 {
- thirdArgument := unnamedArguments[2]
- if thirdArgument == nil {
- return
- }
- if thirdArgument.Execute_parameter() == nil {
- return
- }
- if thirdArgument.Execute_parameter().Constant() == nil {
- return
- }
- if thirdArgument.Execute_parameter().Constant().STRING() == nil {
- return
- }
- if thirdArgument.GetText() != "'COLUMN'" {
- return
- }
-
- l.adviceList = append(l.adviceList, advisor.Advice{
- Status: l.level,
- Code: advisor.CompatibilityRenameColumn,
- Title: l.title,
- Content: fmt.Sprintf("Rename COLUMN %s may cause incompatibility with the existing data and code", firstArgument.GetText()),
- Line: ctx.GetStart().GetLine(),
- })
- }
+ l.adviceList = append(l.adviceList, advisor.Advice{
+ Status: l.level,
+ Code: advisor.CompatibilityRenameTable,
+ Title: l.title,
+ Content: "sp_rename may cause incompatibility with the existing data and code, and break scripts and stored procedures.",
+ Line: ctx.GetStart().GetLine(),
+ })
}
diff --git a/backend/plugin/advisor/mssql/test/column_type_disallow_list.yaml b/backend/plugin/advisor/mssql/test/column_type_disallow_list.yaml
index cde32a9052..56984fbb70 100644
--- a/backend/plugin/advisor/mssql/test/column_type_disallow_list.yaml
+++ b/backend/plugin/advisor/mssql/test/column_type_disallow_list.yaml
@@ -10,3 +10,5 @@
title: column.type-disallow-list
content: Column type JSON is disallowed
line: 4
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/mssql/test/index_not_redundant.yaml b/backend/plugin/advisor/mssql/test/index_not_redundant.yaml
index c7bb190bad..799e730c1a 100644
--- a/backend/plugin/advisor/mssql/test/index_not_redundant.yaml
+++ b/backend/plugin/advisor/mssql/test/index_not_redundant.yaml
@@ -1,22 +1,27 @@
-- statement: |-
- CREATE INDEX test_index ON dbo.pokes (c1, c2);
+- statement: CREATE INDEX test_index ON dbo.pokes (c1, c2);
want:
- status: WARN
- title: index.not-redundant
- content: "Redundant indexes with the same prefix ('idx_0' and 'test_index') in 'dbo.pokes' is not allowed"
code: 817
+ title: index.not-redundant
+ content: Redundant indexes with the same prefix ('idx_0' and 'test_index') in 'dbo.pokes' is not allowed
line: 1
-- statement: |-
- CREATE INDEX test_index ON dbo.pokes (c100, c200);
+ column: 0
+ details: ""
+- statement: CREATE INDEX test_index ON dbo.pokes (c100, c200);
want:
- status: SUCCESS
+ code: 0
title: OK
content: ""
-- statement: |-
- CREATE INDEX test_index ON [dbo].[pokes] (c1, c2);
+ line: 0
+ column: 0
+ details: ""
+- statement: CREATE INDEX test_index ON [dbo].[pokes] (c1, c2);
want:
- status: WARN
- title: index.not-redundant
- content: "Redundant indexes with the same prefix ('idx_0' and 'test_index') in 'dbo.pokes' is not allowed"
code: 817
+ title: index.not-redundant
+ content: Redundant indexes with the same prefix ('idx_0' and 'test_index') in 'dbo.pokes' is not allowed
line: 1
+ 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 366cf766e9..75da2ca6c6 100644
--- a/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
+++ b/backend/plugin/advisor/mssql/test/schema_backward_compatibility.yaml
@@ -1,3 +1,12 @@
+- statement: EXEC sp_rename N'Phone', N'Telephone', N'USERDATATYPE';
+ want:
+ - status: WARN
+ code: 102
+ title: schema.backward-compatibility
+ content: sp_rename may cause incompatibility with the existing data and code, and break scripts and stored procedures.
+ line: 1
+ column: 0
+ details: ""
- statement: DROP TABLE MyTable;
want:
- status: WARN
@@ -123,16 +132,16 @@
- status: WARN
code: 102
title: schema.backward-compatibility
- content: Rename Table 'Sales.SalesTerritory' WITH may cause incompatibility with the existing data and code
+ content: sp_rename may cause incompatibility with the existing data and code, and break scripts and stored procedures.
line: 1
column: 0
details: ""
- statement: EXEC sp_rename 'dbo.ErrorLog.ErrorTime', 'ErrorDateTime', 'COLUMN';
want:
- status: WARN
- code: 104
+ code: 102
title: schema.backward-compatibility
- content: Rename COLUMN 'dbo.ErrorLog.ErrorTime' may cause incompatibility with the existing data and code
+ content: sp_rename may cause incompatibility with the existing data and code, and break scripts and stored procedures.
line: 1
column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/statement_disallow_cross_db_queries.yaml b/backend/plugin/advisor/mssql/test/statement_disallow_cross_db_queries.yaml
index 90c25dbadd..0e38ff0a32 100644
--- a/backend/plugin/advisor/mssql/test/statement_disallow_cross_db_queries.yaml
+++ b/backend/plugin/advisor/mssql/test/statement_disallow_cross_db_queries.yaml
@@ -1,10 +1,12 @@
-# case insensitive.
-- statement: |-
- SELECT * FROM MASTER.dbo.pokes;
+- statement: SELECT * FROM MASTER.dbo.pokes;
want:
- status: SUCCESS
code: 0
title: OK
+ content: ""
+ line: 0
+ column: 0
+ details: ""
- statement: |-
WITH foo1 AS (SELECT * FROM master2.dbo.tech_book)
SELECT * FROM master.dbo.pokes;
@@ -13,9 +15,10 @@
- status: WARN
code: 233
title: statement.disallow-cross-db-queries
- content: "Cross database queries (target databse: 'master2', current database: 'master') are prohibited"
+ content: 'Cross database queries (target databse: ''master2'', current database: ''master'') are prohibited'
line: 1
-# Testing with database switching.
+ column: 0
+ details: ""
- statement: |-
USE master2;
SELECT * FROM master.dbo.pokes;
@@ -23,5 +26,7 @@
- status: WARN
code: 233
title: statement.disallow-cross-db-queries
- content: "Cross database queries (target databse: 'master', current database: 'master2') are prohibited"
+ content: 'Cross database queries (target databse: ''master'', current database: ''master2'') are prohibited'
line: 2
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yaml b/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yaml
index ab90fddf83..b193722be9 100644
--- a/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yaml
+++ b/backend/plugin/advisor/mssql/test/statement_where_disallow_functions_and_calculations.yaml
@@ -5,35 +5,46 @@
SELECT foo FROM pokes WHERE ~foo > 0;
want:
- status: WARN
- title: statement.where.disallow-functions-and-calculations
code: 234
+ title: statement.where.disallow-functions-and-calculations
content: Performing calculations in 'WHERE' clause is not allowed
line: 2
+ column: 0
+ details: ""
- status: WARN
- title: statement.where.disallow-functions-and-calculations
code: 234
+ title: statement.where.disallow-functions-and-calculations
content: Performing calculations in 'WHERE' clause is not allowed
line: 4
+ column: 0
+ details: ""
- statement: |-
SELECT foo FROM pokes WHERE foo | -foo > 0;
SELECT bar FROM pokes WHERE bar > AVG(bar);
want:
- status: WARN
- title: statement.where.disallow-functions-and-calculations
code: 234
+ title: statement.where.disallow-functions-and-calculations
content: Performing calculations in 'WHERE' clause is not allowed
line: 1
+ column: 0
+ details: ""
- status: WARN
- title: statement.where.disallow-functions-and-calculations
code: 234
+ title: statement.where.disallow-functions-and-calculations
content: Calling function 'AVG(bar)' in 'WHERE' clause is not allowed
line: 2
-- statement: |-
- SELECT bar FROM pokes WHERE bar > 1;
+ column: 0
+ details: ""
+- statement: SELECT bar FROM pokes WHERE bar > 1;
want:
- status: SUCCESS
+ code: 0
title: OK
content: ""
+ line: 0
+ column: 0
+ details: ""
- statement: |-
SELECT Department, AVG(Salary) AS AvgSalary
FROM Employees
@@ -41,13 +52,18 @@
HAVING AVG(Salary) * 3 + 1 > 50000;
want:
- status: SUCCESS
+ code: 0
title: OK
content: ""
-- statement: |-
- select * from (select * from t where t.a > 1) t1 where a > AVG(a);
+ line: 0
+ column: 0
+ details: ""
+- statement: select * from (select * from t where t.a > 1) t1 where a > AVG(a);
want:
- status: WARN
- title: statement.where.disallow-functions-and-calculations
code: 234
+ title: statement.where.disallow-functions-and-calculations
content: Calling function 'AVG(a)' in 'WHERE' clause is not allowed
line: 1
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/mssql/test/system_function_disallow_create.yaml b/backend/plugin/advisor/mssql/test/system_function_disallow_create.yaml
index 7569e4e185..feab254edc 100644
--- a/backend/plugin/advisor/mssql/test/system_function_disallow_create.yaml
+++ b/backend/plugin/advisor/mssql/test/system_function_disallow_create.yaml
@@ -17,7 +17,7 @@
- status: WARN
code: 1701
title: system.function.disallow-create
- content: |-
- Creating or altering functions is prohibited
+ content: Creating or altering functions is prohibited
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/system_procedure_disallow_create.yaml b/backend/plugin/advisor/mssql/test/system_procedure_disallow_create.yaml
index 5a9bf82970..e2f5f29bfa 100644
--- a/backend/plugin/advisor/mssql/test/system_procedure_disallow_create.yaml
+++ b/backend/plugin/advisor/mssql/test/system_procedure_disallow_create.yaml
@@ -21,7 +21,7 @@
- status: WARN
code: 1701
title: system.procedure.disallow-create
- content: |-
- Creating or altering procedures is prohibited
+ content: Creating or altering procedures is prohibited
line: 1
+ column: 0
details: ""
diff --git a/backend/plugin/advisor/mssql/test/table_disallow_ddl.yaml b/backend/plugin/advisor/mssql/test/table_disallow_ddl.yaml
index 84522f69cd..3f51f936be 100644
--- a/backend/plugin/advisor/mssql/test/table_disallow_ddl.yaml
+++ b/backend/plugin/advisor/mssql/test/table_disallow_ddl.yaml
@@ -13,3 +13,5 @@
title: table.disallow-ddl
content: DDL is disallowed on table MySchema.Identifier.
line: 5
+ column: 0
+ details: ""
diff --git a/backend/plugin/advisor/mssql/test/table_disallow_dml.yaml b/backend/plugin/advisor/mssql/test/table_disallow_dml.yaml
index ba5e7ec81a..72ecb91d1a 100644
--- a/backend/plugin/advisor/mssql/test/table_disallow_dml.yaml
+++ b/backend/plugin/advisor/mssql/test/table_disallow_dml.yaml
@@ -8,6 +8,8 @@
title: table.disallow-dml
content: DML is disallowed on table MySchema.Identifier.
line: 1
+ column: 0
+ details: ""
- statement: |-
INSERT INTO MySchema.MyTable (Id, Name) VALUES (1, 'Alice');
INSERT INTO MySchema.Identifier (Id, Name) VALUES (1, 'Alice');
@@ -17,27 +19,32 @@
title: table.disallow-dml
content: DML is disallowed on table MySchema.Identifier.
line: 2
-- statement: |-
- DELETE FROM MySchema.Identifier WHERE Id = 1;
+ column: 0
+ details: ""
+- statement: DELETE FROM MySchema.Identifier WHERE Id = 1;
want:
- status: WARN
code: 614
title: table.disallow-dml
content: DML is disallowed on table MySchema.Identifier.
line: 1
-- statement: |-
- UPDATE MySchema.Identifier SET Name = 'Bob' WHERE Id = 1;
+ column: 0
+ details: ""
+- statement: UPDATE MySchema.Identifier SET Name = 'Bob' WHERE Id = 1;
want:
- status: WARN
code: 614
title: table.disallow-dml
content: DML is disallowed on table MySchema.Identifier.
line: 1
-- statement: |-
- SELECT * INTO MySchema.Identifier FROM MySchema.MyTable;
+ column: 0
+ details: ""
+- statement: SELECT * INTO MySchema.Identifier FROM MySchema.MyTable;
want:
- status: WARN
code: 614
title: table.disallow-dml
content: DML is disallowed on table MySchema.Identifier.
line: 1
+ column: 0
+ details: ""