Skip to content

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

refactor: migrate pgantlr test helper to use ANTLR catalog walkthrough (#17922)

h3n4la0767d630f05
diff --git a/backend/plugin/advisor/pgantlr/test/table_require_pk.yaml b/backend/plugin/advisor/pgantlr/test/table_require_pk.yaml
index 13c8fc9c8d..aa72fb531c 100644
--- a/backend/plugin/advisor/pgantlr/test/table_require_pk.yaml
+++ b/backend/plugin/advisor/pgantlr/test/table_require_pk.yaml
@@ -24,7 +24,7 @@
column: 0
- statement: ALTER TABLE "tech_book" DROP CONSTRAINT "old_index"
changeType: 1
-- statement: ALTER TABLE "tech_book" DROP CONSTRAINT constraint_not_in_catalog
+- statement: ALTER TABLE "tech_book" DROP CONSTRAINT IF EXISTS constraint_not_in_catalog
changeType: 1
- statement: ALTER TABLE "tech_book" DROP COLUMN id
changeType: 1
diff --git a/backend/plugin/advisor/pgantlr/test_helper.go b/backend/plugin/advisor/pgantlr/test_helper.go
index 952e1c71d3..e7dc0d41e2 100644
--- a/backend/plugin/advisor/pgantlr/test_helper.go
+++ b/backend/plugin/advisor/pgantlr/test_helper.go
@@ -16,7 +16,6 @@ import (
"github.com/bytebase/bytebase/backend/plugin/advisor"
"github.com/bytebase/bytebase/backend/plugin/advisor/catalog"
"github.com/bytebase/bytebase/backend/plugin/parser/pg"
- pglegacy "github.com/bytebase/bytebase/backend/plugin/parser/pg/legacy"
)
// TestCase is the data struct for test.
@@ -75,11 +74,9 @@ func RunANTLRAdvisorRuleTest(t *testing.T, rule advisor.SQLReviewRuleType, dbTyp
tree, err := pg.ParsePostgreSQL(tc.Statement)
require.NoError(t, err, "Failed to parse SQL: %s", tc.Statement)
- // Also parse with legacy parser for catalog WalkThrough
+ // Use ANTLR tree for catalog WalkThrough
if needMetaData {
- legacyAST, err := pglegacy.Parse(pglegacy.ParseContext{}, tc.Statement)
- require.NoError(t, err, "Failed to parse SQL with legacy parser: %s", tc.Statement)
- err = finder.WalkThrough(legacyAST)
+ err = finder.WalkThrough(tree)
require.NoError(t, err, "Failed to walk through catalog: %s", tc.Statement)
}