Skip to content

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

fix: correctly drop table in pg schema design (#8935)

rebelicecc900d0566be
diff --git a/backend/plugin/schema-engine/pg/structurer.go b/backend/plugin/schema-engine/pg/structurer.go
index 2b7a4b86bc..90a9c820fa 100644
--- a/backend/plugin/schema-engine/pg/structurer.go
+++ b/backend/plugin/schema-engine/pg/structurer.go
@@ -900,6 +900,17 @@ func (g *designSchemaGenerator) EnterCreatestmt(ctx *postgres.CreatestmtContext)
return
}
+ if _, err := g.result.WriteString(
+ ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{
+ Start: g.lastTokenIndex,
+ Stop: ctx.GetStart().GetTokenIndex() - 1,
+ }),
+ ); err != nil {
+ g.err = err
+ return
+ }
+ g.lastTokenIndex = ctx.GetStart().GetTokenIndex()
+
schema, exists := g.to.schemas[schemaName]
if !exists {
// Skip not found schema.
@@ -914,18 +925,6 @@ func (g *designSchemaGenerator) EnterCreatestmt(ctx *postgres.CreatestmtContext)
return
}
- g.currentTable = table
-
- if _, err := g.result.WriteString(
- ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{
- Start: g.lastTokenIndex,
- Stop: ctx.GetStart().GetTokenIndex() - 1,
- }),
- ); err != nil {
- g.err = err
- return
- }
-
g.currentTable = table
g.firstElementInTable = true
g.columnDefine.Reset()
diff --git a/backend/plugin/schema-engine/pg/testdata/get_design_schema.yaml b/backend/plugin/schema-engine/pg/testdata/get_design_schema.yaml
index 82c02d45d6..765fafd8eb 100644
--- a/backend/plugin/schema-engine/pg/testdata/get_design_schema.yaml
+++ b/backend/plugin/schema-engine/pg/testdata/get_design_schema.yaml
@@ -3,6 +3,10 @@
"a" int,
CONSTRAINT t_a_check CHECK ("a" > 0)
);
+ CREATE TABLE public."x" (
+ "a" int,
+ CONSTRAINT x_a_check CHECK ("a" > 0)
+ );
COMMENT ON COLUMN public.t.a IS 'this is a comment';
COMMENT ON TABLE public.t IS 'hello';
ALTER TABLE public."t" ADD CONSTRAINT fk_t_a_t2_b FOREIGN KEY ("a") REFERENCES public."t2" ("b");
@@ -159,6 +163,8 @@
+
+
CREATE TABLE public.t4 (
a varchar(10) NOT NULL DEFAULT 'default value',
c int NOT NULL,