Skip to content

Commit

Permalink
fix DROP CONSTRAINT
Browse files Browse the repository at this point in the history
  • Loading branch information
covrom committed Sep 3, 2021
1 parent 9dde696 commit b474d17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cmd/goerd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion schema/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit b474d17

Please sign in to comment.