Skip to content

Commit b0d67b2

Browse files
chore: misc cleanup (#261)
1 parent f622a9f commit b0d67b2

File tree

6 files changed

+14
-66
lines changed

6 files changed

+14
-66
lines changed

cmd/pg-schema-diff/datastructs.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"sort"
6-
7-
"github.com/stripe/pg-schema-diff/internal/util"
85
)
96

107
func mustGetAndDeleteKey(m map[string]string, key string) (string, error) {
@@ -15,9 +12,3 @@ func mustGetAndDeleteKey(m map[string]string, key string) (string, error) {
1512
delete(m, key)
1613
return val, nil
1714
}
18-
19-
func keys(m map[string]string) []string {
20-
vals := util.Keys(m)
21-
sort.Strings(vals)
22-
return vals
23-
}

cmd/pg-schema-diff/plan_cmd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"encoding/json"
77
"fmt"
88
"io"
9+
"maps"
910
"regexp"
11+
"slices"
1012
"strconv"
1113
"strings"
1214
"time"
@@ -382,7 +384,7 @@ func parseTimeoutModifier(val string) (timeoutModifier, error) {
382384
}
383385

384386
if len(fm) > 0 {
385-
return timeoutModifier{}, fmt.Errorf("unknown keys %s", keys(fm))
387+
return timeoutModifier{}, fmt.Errorf("unknown keys %s", slices.Sorted(maps.Keys(fm)))
386388
}
387389

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

430432
if len(fm) > 0 {
431-
return insertStatement{}, fmt.Errorf("unknown keys %s", keys(fm))
433+
return insertStatement{}, fmt.Errorf("unknown keys %s", slices.Sorted(maps.Keys(fm)))
432434
}
433435

434436
index, err := strconv.Atoi(indexStr)

internal/util/map.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

internal/util/map_test.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

pkg/diff/materialized_view_sql_generator.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package diff
33
import (
44
"errors"
55
"fmt"
6-
"sort"
6+
"maps"
7+
"slices"
78
"strings"
89

910
"github.com/google/go-cmp/cmp"
1011
"github.com/stripe/pg-schema-diff/internal/schema"
11-
"github.com/stripe/pg-schema-diff/internal/util"
1212
)
1313

1414
type materializedViewDiff struct {
@@ -45,7 +45,9 @@ func buildMaterializedViewDiff(
4545
// It's possible a dependent column was deleted (or recreated).
4646
td, ok := tableDiffsByName[t.GetName()]
4747
if !ok {
48-
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))
48+
return materializedViewDiff{}, false, fmt.Errorf("processing materialized view table dependencies: expected a table diff to exist for %q. have=\n%s", t.GetName(),
49+
slices.Sorted(maps.Keys(tableDiffsByName)),
50+
)
4951
}
5052
deletedColumnsByName := buildSchemaObjByNameMap(td.columnsDiff.deletes)
5153
for _, c := range t.Columns {
@@ -85,8 +87,7 @@ func (mvsg *materializedViewSQLGenerator) Add(mv schema.MaterializedView) (parti
8587
}
8688
// Sort kvs so the generated DDL is deterministic. This is unnecessarily verbose because the slices
8789
// package is not yet available.
88-
// // TODO(https://github.com/stripe/pg-schema-diff/issues/227) - Remove this
89-
sort.Strings(kvs)
90+
slices.Sort(kvs)
9091
materializedViewSb.WriteString(fmt.Sprintf(" WITH (%s)", strings.Join(kvs, ", ")))
9192
}
9293
if len(mv.Tablespace) > 0 {

pkg/diff/view_sql_generator.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package diff
33
import (
44
"errors"
55
"fmt"
6-
"sort"
6+
"maps"
7+
"slices"
78
"strings"
89

910
"github.com/google/go-cmp/cmp"
1011
"github.com/stripe/pg-schema-diff/internal/schema"
11-
"github.com/stripe/pg-schema-diff/internal/util"
1212
)
1313

1414
type viewDiff struct {
@@ -45,7 +45,7 @@ func buildViewDiff(
4545
// It's possible a dependent column was deleted (or recreated).
4646
td, ok := tableDiffsByName[t.GetName()]
4747
if !ok {
48-
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))
48+
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)))
4949
}
5050
deletedColumnsByName := buildSchemaObjByNameMap(td.columnsDiff.deletes)
5151
for _, c := range t.Columns {
@@ -85,8 +85,7 @@ func (vsg *viewSQLGenerator) Add(v schema.View) (partialSQLGraph, error) {
8585
}
8686
// Sort kvs so the generated DDL is deterministic. This is unnecessarily verbose because the slices
8787
// package is not yet available.
88-
// // TODO(https://github.com/stripe/pg-schema-diff/issues/227) - Remove this
89-
sort.Strings(kvs)
88+
slices.Sort(kvs)
9089
viewSb.WriteString(fmt.Sprintf(" WITH (%s)", strings.Join(kvs, ", ")))
9190
}
9291
viewSb.WriteString(" AS\n")

0 commit comments

Comments
 (0)