From 219bca0892a66b9b76f9db7affb1c0f000e6fd84 Mon Sep 17 00:00:00 2001 From: Mars Hall Date: Wed, 17 Oct 2018 10:31:12 -0700 Subject: [PATCH] Fix to use existing pg indexes --- backend/remote-state/pg/backend.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/remote-state/pg/backend.go b/backend/remote-state/pg/backend.go index d53729cd8d9e..557657279f7b 100644 --- a/backend/remote-state/pg/backend.go +++ b/backend/remote-state/pg/backend.go @@ -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. @@ -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 ( @@ -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 }