Skip to content

Commit

Permalink
Adding postgres support for dropping unique constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Aug 20, 2019
1 parent 3ce8a14 commit e3f33c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/database/postgres/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"fmt"
"strings"

"github.com/lib/pq"
"github.com/schemahero/schemahero/pkg/database/types"
)

func RemoveConstrantStatement(tableName string, constraint *types.KeyConstraint) string {
if constraint == nil {
return ""
}
return fmt.Sprintf("alter table %s drop constraint %s", tableName, constraint.Name)
return fmt.Sprintf("alter table %s drop constraint %s", tableName, pq.QuoteIdentifier(constraint.Name))
}

func AddConstrantStatement(tableName string, constraint *types.KeyConstraint) string {
Expand Down
3 changes: 2 additions & 1 deletion pkg/database/postgres/foreignkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"fmt"
"strings"

"github.com/lib/pq"
schemasv1alpha2 "github.com/schemahero/schemahero/pkg/apis/schemas/v1alpha2"
"github.com/schemahero/schemahero/pkg/database/types"
)

func RemoveForeignKeyStatement(tableName string, foreignKey *types.ForeignKey) string {
return fmt.Sprintf("alter table %s drop constraint %s", tableName, foreignKey.Name)
return fmt.Sprintf("alter table %s drop constraint %s", tableName, pq.QuoteIdentifier(foreignKey.Name))
}

func AddForeignKeyStatement(tableName string, schemaForeignKey *schemasv1alpha2.SQLTableForeignKey) string {
Expand Down
3 changes: 3 additions & 0 deletions pkg/database/postgres/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
)

func RemoveIndexStatement(tableName string, index *types.Index) string {
if index.IsUnique {
return fmt.Sprintf("alter table %s drop constraint %s", tableName, pq.QuoteIdentifier(index.Name))
}
return fmt.Sprintf("drop index %s", pq.QuoteIdentifier(index.Name))
}

Expand Down

0 comments on commit e3f33c6

Please sign in to comment.