Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions cmd/pg-schema-diff/datastructs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package main

import (
"fmt"
"sort"

"github.com/stripe/pg-schema-diff/internal/util"
)

func mustGetAndDeleteKey(m map[string]string, key string) (string, error) {
Expand All @@ -15,9 +12,3 @@ func mustGetAndDeleteKey(m map[string]string, key string) (string, error) {
delete(m, key)
return val, nil
}

func keys(m map[string]string) []string {
vals := util.Keys(m)
sort.Strings(vals)
return vals
}
6 changes: 4 additions & 2 deletions cmd/pg-schema-diff/plan_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"encoding/json"
"fmt"
"io"
"maps"
"regexp"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -382,7 +384,7 @@ func parseTimeoutModifier(val string) (timeoutModifier, error) {
}

if len(fm) > 0 {
return timeoutModifier{}, fmt.Errorf("unknown keys %s", keys(fm))
return timeoutModifier{}, fmt.Errorf("unknown keys %s", slices.Sorted(maps.Keys(fm)))
}

duration, err := time.ParseDuration(timeoutStr)
Expand Down Expand Up @@ -428,7 +430,7 @@ func parseInsertStatementStr(val string) (insertStatement, error) {
}

if len(fm) > 0 {
return insertStatement{}, fmt.Errorf("unknown keys %s", keys(fm))
return insertStatement{}, fmt.Errorf("unknown keys %s", slices.Sorted(maps.Keys(fm)))
}

index, err := strconv.Atoi(indexStr)
Expand Down
11 changes: 0 additions & 11 deletions internal/util/map.go

This file was deleted.

34 changes: 0 additions & 34 deletions internal/util/map_test.go

This file was deleted.

11 changes: 6 additions & 5 deletions pkg/diff/materialized_view_sql_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package diff
import (
"errors"
"fmt"
"sort"
"maps"
"slices"
"strings"

"github.com/google/go-cmp/cmp"
"github.com/stripe/pg-schema-diff/internal/schema"
"github.com/stripe/pg-schema-diff/internal/util"
)

type materializedViewDiff struct {
Expand Down Expand Up @@ -45,7 +45,9 @@ func buildMaterializedViewDiff(
// It's possible a dependent column was deleted (or recreated).
td, ok := tableDiffsByName[t.GetName()]
if !ok {
return materializedViewDiff{}, false, fmt.Errorf("processing materialized view table dependencies: expected a table diff to exist for %q. have=\n%s", t.GetName(), util.Keys(tableDiffsByName))
return materializedViewDiff{}, false, fmt.Errorf("processing materialized view table dependencies: expected a table diff to exist for %q. have=\n%s", t.GetName(),
slices.Sorted(maps.Keys(tableDiffsByName)),
)
}
deletedColumnsByName := buildSchemaObjByNameMap(td.columnsDiff.deletes)
for _, c := range t.Columns {
Expand Down Expand Up @@ -85,8 +87,7 @@ func (mvsg *materializedViewSQLGenerator) Add(mv schema.MaterializedView) (parti
}
// Sort kvs so the generated DDL is deterministic. This is unnecessarily verbose because the slices
// package is not yet available.
// // TODO(https://github.com/stripe/pg-schema-diff/issues/227) - Remove this
sort.Strings(kvs)
slices.Sort(kvs)
materializedViewSb.WriteString(fmt.Sprintf(" WITH (%s)", strings.Join(kvs, ", ")))
}
if len(mv.Tablespace) > 0 {
Expand Down
9 changes: 4 additions & 5 deletions pkg/diff/view_sql_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package diff
import (
"errors"
"fmt"
"sort"
"maps"
"slices"
"strings"

"github.com/google/go-cmp/cmp"
"github.com/stripe/pg-schema-diff/internal/schema"
"github.com/stripe/pg-schema-diff/internal/util"
)

type viewDiff struct {
Expand Down Expand Up @@ -45,7 +45,7 @@ func buildViewDiff(
// It's possible a dependent column was deleted (or recreated).
td, ok := tableDiffsByName[t.GetName()]
if !ok {
return viewDiff{}, false, fmt.Errorf("processing view table dependencies: expected a table diff to exist for %q. have=\n%s", t.GetName(), util.Keys(tableDiffsByName))
return viewDiff{}, false, fmt.Errorf("processing view table dependencies: expected a table diff to exist for %q. have=\n%s", t.GetName(), slices.Sorted(maps.Keys(tableDiffsByName)))
}
deletedColumnsByName := buildSchemaObjByNameMap(td.columnsDiff.deletes)
for _, c := range t.Columns {
Expand Down Expand Up @@ -85,8 +85,7 @@ func (vsg *viewSQLGenerator) Add(v schema.View) (partialSQLGraph, error) {
}
// Sort kvs so the generated DDL is deterministic. This is unnecessarily verbose because the slices
// package is not yet available.
// // TODO(https://github.com/stripe/pg-schema-diff/issues/227) - Remove this
sort.Strings(kvs)
slices.Sort(kvs)
viewSb.WriteString(fmt.Sprintf(" WITH (%s)", strings.Join(kvs, ", ")))
}
viewSb.WriteString(" AS\n")
Expand Down