Skip to content

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

chore(differ): fix bugs for dropping statements in differ (#3560)

rebelice0b18584f7aa7
diff --git a/plugin/parser/differ/pg/differ.go b/plugin/parser/differ/pg/differ.go
index 30bd1a7da7..f1d3007756 100644
--- a/plugin/parser/differ/pg/differ.go
+++ b/plugin/parser/differ/pg/differ.go
@@ -34,9 +34,9 @@ type diffNode struct {
dropIndexList []ast.Node
dropDefaultList []ast.Node
dropSequenceOwnedByList []ast.Node
- dropSequenceList []ast.Node
dropColumnList []ast.Node
dropTableList []ast.Node
+ dropSequenceList []ast.Node
dropSchemaList []ast.Node
// Create nodes
@@ -973,15 +973,15 @@ func (diff *diffNode) deparse() (string, error) {
if err := printStmtSlice(&buf, diff.dropSequenceOwnedByList); err != nil {
return "", err
}
- if err := printStmtSlice(&buf, diff.dropSequenceList); err != nil {
- return "", err
- }
if err := printStmtSlice(&buf, diff.dropColumnList); err != nil {
return "", err
}
if err := printStmtSlice(&buf, diff.dropTableList); err != nil {
return "", err
}
+ if err := printStmtSlice(&buf, diff.dropSequenceList); err != nil {
+ return "", err
+ }
if err := printStmtSlice(&buf, diff.dropSchemaList); err != nil {
return "", err
}
@@ -1049,10 +1049,6 @@ func (diff *diffNode) dropConstraint(m schemaMap) {
func dropTable(m schemaMap) *ast.DropTableStmt {
var tableList []*tableInfo
for _, schema := range m {
- if !schema.existsInNew {
- // dropped by DROP SCHEMA ... CASCADE statements
- continue
- }
for _, table := range schema.tableMap {
if table.existsInNew {
// no need to drop
@@ -1104,10 +1100,6 @@ func dropSchema(m schemaMap) *ast.DropSchemaStmt {
func dropIndex(m schemaMap) *ast.DropIndexStmt {
var indexList []*indexInfo
for _, schema := range m {
- if !schema.existsInNew {
- // dropped by DROP SCHEMA ... CASCADE statements
- continue
- }
for _, index := range schema.indexMap {
if index.existsInNew {
// no need to drop
diff --git a/plugin/parser/differ/pg/test-data/test_differ_data.yaml b/plugin/parser/differ/pg/test-data/test_differ_data.yaml
index effc3657d8..4a73b1e09c 100644
--- a/plugin/parser/differ/pg/test-data/test_differ_data.yaml
+++ b/plugin/parser/differ/pg/test-data/test_differ_data.yaml
@@ -150,3 +150,21 @@
ALTER COLUMN "e" SET DATA TYPE jsonb;
ALTER TABLE "public"."t"
ALTER COLUMN "f" SET DATA TYPE pg_catalog.bit(4);
+- oldSchema: |
+ create schema schema1;
+ create table schema1.t1(a int, b int, c int);
+ create index idx_t1_a on schema1.t1(a);
+ create sequence schema1.sequence1
+ NO MINVALUE
+ NO MAXVALUE
+ START WITH 1;
+ alter sequence schema1.sequence1 owned by schema1.t1.a;
+ alter table schema1.t1 alter column a set default nextval('schema1.sequence1'::regclass);
+ newSchema: ""
+ diff: |
+ DROP INDEX "schema1"."idx_t1_a";
+ ALTER SEQUENCE "schema1"."sequence1"
+ OWNED BY NONE;
+ DROP TABLE "schema1"."t1";
+ DROP SEQUENCE "schema1"."sequence1";
+ DROP SCHEMA "schema1";
diff --git a/plugin/parser/differ/pg/test-data/test_differ_sequence.yaml b/plugin/parser/differ/pg/test-data/test_differ_sequence.yaml
index cdcdb06a0b..1dce2e943f 100644
--- a/plugin/parser/differ/pg/test-data/test_differ_sequence.yaml
+++ b/plugin/parser/differ/pg/test-data/test_differ_sequence.yaml
@@ -37,8 +37,8 @@
diff: |
ALTER SEQUENCE "public"."s1"
OWNED BY NONE;
- DROP SEQUENCE "public"."s1";
DROP TABLE "public"."t1";
+ DROP SEQUENCE "public"."s1";
- oldSchema: |
create table public.t1 (a int);
create sequence public.s1