Skip to content

Commit

Permalink
Merge pull request #26420 from remilapeyre/postgres-default-backend
Browse files Browse the repository at this point in the history
Always have the default workspace in the pg backend
  • Loading branch information
Pam Selle authored Sep 30, 2020
2 parents c51104f + 9acfe30 commit 3a99405
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions backend/remote-state/pg/backend_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
)

func (b *Backend) Workspaces() ([]string, error) {
query := `SELECT name FROM %s.%s ORDER BY name`
query := `SELECT name FROM %s.%s WHERE name != 'default' ORDER BY name`
rows, err := b.db.Query(fmt.Sprintf(query, b.schemaName, statesTableName))
if err != nil {
return nil, err
}
defer rows.Close()

var result []string
result := []string{
backend.DefaultStateName,
}

for rows.Next() {
var name string
Expand Down
2 changes: 2 additions & 0 deletions backend/remote-state/pg/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func TestBackendConfig(t *testing.T) {
if c.Name != backend.DefaultStateName {
t.Fatal("RemoteClient name is not configured")
}

backend.TestBackendStates(t, b)
}

func TestBackendConfigSkipSchema(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion backend/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestBackendStates(t *testing.T, b Backend) {

// Test it starts with only the default
if !noDefault && (len(workspaces) != 1 || workspaces[0] != DefaultStateName) {
t.Fatalf("should only default to start: %#v", workspaces)
t.Fatalf("should only have the default workspace to start: %#v", workspaces)
}

// Create a couple states
Expand Down

0 comments on commit 3a99405

Please sign in to comment.