Skip to content

Commit

Permalink
Fix to use existing pg indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
mars committed Oct 17, 2018
1 parent 6a145b1 commit 43d508c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions backend/remote-state/pg/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (

const (
locksTableName = "locks"
locksIndexName = "locks_by_name"
statesTableName = "states"
statesIndexName = "states_by_name"
)

// New creates a new backend for Postgres remote state.
Expand Down Expand Up @@ -89,8 +91,8 @@ func (b *Backend) configure(ctx context.Context) error {
if _, err := db.Query(fmt.Sprintf(query, b.schemaName, locksTableName)); err != nil {
return err
}
query = `CREATE UNIQUE INDEX ON %s.%s (name)`
if _, err := db.Query(fmt.Sprintf(query, b.schemaName, locksTableName)); err != nil {
query = `CREATE UNIQUE INDEX IF NOT EXISTS %s ON %s.%s (name)`
if _, err := db.Query(fmt.Sprintf(query, locksIndexName, b.schemaName, locksTableName)); err != nil {
return err
}
query = `CREATE TABLE IF NOT EXISTS %s.%s (
Expand All @@ -100,8 +102,8 @@ func (b *Backend) configure(ctx context.Context) error {
if _, err := db.Query(fmt.Sprintf(query, b.schemaName, statesTableName)); err != nil {
return err
}
query = `CREATE UNIQUE INDEX ON %s.%s (name)`
if _, err := db.Query(fmt.Sprintf(query, b.schemaName, statesTableName)); err != nil {
query = `CREATE UNIQUE INDEX IF NOT EXISTS %s ON %s.%s (name)`
if _, err := db.Query(fmt.Sprintf(query, statesIndexName, b.schemaName, statesTableName)); err != nil {
return err
}

Expand Down

0 comments on commit 43d508c

Please sign in to comment.