From b474d179ccf4972d16ab3b66bd619ddff5b2e8c1 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 3 Sep 2021 11:11:55 +0300 Subject: [PATCH] fix DROP CONSTRAINT --- cmd/goerd/main.go | 15 ++++++++++----- schema/diff.go | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/goerd/main.go b/cmd/goerd/main.go index dd0c61e..d330b19 100644 --- a/cmd/goerd/main.go +++ b/cmd/goerd/main.go @@ -67,7 +67,8 @@ func main() { fmt.Println("--", q) continue } - if strings.Contains(strings.ToUpper(q), "DROP COLUMN") { + if strings.Contains(strings.ToUpper(q), "DROP COLUMN") || + strings.Contains(strings.ToUpper(q), "DROP CONSTRAINT") { fmt.Println("--", q) continue } @@ -129,7 +130,8 @@ func main() { fmt.Println("--", q) continue } - if strings.Contains(strings.ToUpper(q), "DROP COLUMN") { + if strings.Contains(strings.ToUpper(q), "DROP COLUMN") || + strings.Contains(strings.ToUpper(q), "DROP CONSTRAINT") { fmt.Println("--", q) continue } @@ -151,7 +153,8 @@ func main() { fmt.Println("--", q) continue } - if strings.Contains(strings.ToUpper(q), "DROP COLUMN") { + if strings.Contains(strings.ToUpper(q), "DROP COLUMN") || + strings.Contains(strings.ToUpper(q), "DROP CONSTRAINT") { fmt.Println("--", q) continue } @@ -224,7 +227,8 @@ func main() { fmt.Println("--", q) continue } - if strings.Contains(strings.ToUpper(q), "DROP COLUMN") { + if strings.Contains(strings.ToUpper(q), "DROP COLUMN") || + strings.Contains(strings.ToUpper(q), "DROP CONSTRAINT") { fmt.Println("--", q) continue } @@ -246,7 +250,8 @@ func main() { fmt.Println("--", q) continue } - if strings.Contains(strings.ToUpper(q), "DROP COLUMN") { + if strings.Contains(strings.ToUpper(q), "DROP COLUMN") || + strings.Contains(strings.ToUpper(q), "DROP CONSTRAINT") { fmt.Println("--", q) continue } diff --git a/schema/diff.go b/schema/diff.go index d0b9ce3..6d14838 100644 --- a/schema/diff.go +++ b/schema/diff.go @@ -315,7 +315,10 @@ func (c *PatchConstraint) alter() []string { } func (c *PatchConstraint) drop() []string { - // always drop unused constraints + if c.to == nil && c.from.Type == TypePK { + // pk not drop + return nil + } return []string{ fmt.Sprintf("ALTER TABLE %s DROP CONSTRAINT IF EXISTS %s", c.tableName, c.from.Name), }