Skip to content

Commit 47170c5

Browse files
committed
Switch to borp
This switches to an early version of borp, before the PR that adds contexts to all of borp's relevant functions. It involves mainly the dependency change, plus a bunch of renamings.
1 parent cf770df commit 47170c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+339
-1028
lines changed

cmd/cert-checker/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type reportEntry struct {
8282
Problems []string `json:"problems,omitempty"`
8383
}
8484

85-
// certDB is an interface collecting the gorp.saDbMap functions that the various
85+
// certDB is an interface collecting the borp.DbMap functions that the various
8686
// parts of cert-checker rely on. Using this adapter shim allows tests to swap
8787
// out the saDbMap implementation.
8888
type certDB interface {

cmd/id-exporter/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ func (c idExporter) findIDsWithExampleHostnames() (idExporterResults, error) {
119119
func (c idExporter) findIDsForHostnames(hostnames []string) (idExporterResults, error) {
120120
var holder idExporterResults
121121
for _, hostname := range hostnames {
122-
// Pass the same list in each time, gorp will happily just append to the slice
122+
// Pass the same list in each time, borp will happily just append to the slice
123123
// instead of overwriting it each time
124-
// https://github.com/go-gorp/gorp/blob/2ae7d174a4cf270240c4561092402affba25da5e/select.go#L348-L355
124+
// https://github.com/letsencrypt/borp/blob/c87bd6443d59746a33aca77db34a60cfc344adb2/select.go#L349-L353
125125
_, err := c.dbMap.Select(
126126
&holder,
127127
`SELECT DISTINCT c.registrationID AS id

cmd/notify-mailer/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (m *mailer) resolveAddresses() (addressToRecipientMap, error) {
258258
return result, nil
259259
}
260260

261-
// dbSelector abstracts over a subset of methods from `gorp.DbMap` objects to
261+
// dbSelector abstracts over a subset of methods from `borp.DbMap` objects to
262262
// facilitate mocking in unit tests.
263263
type dbSelector interface {
264264
SelectOne(holder interface{}, query string, args ...interface{}) error

db/gorm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewMappedSelector[T any](executor MappedExecutor) (MappedSelector[T], error
5151
// - Note that the reverse is not true: it's perfectly okay for there to be
5252
// database columns which do not correspond to fields in the struct; those
5353
// columns will be ignored.
54-
// TODO: In the future, when we replace gorp's TableMap with our own, this
54+
// TODO: In the future, when we replace borp's TableMap with our own, this
5555
// check should be performed at the time the mapping is declared.
5656
columns := make([]string, 0)
5757
seen := make(map[string]struct{})
@@ -81,15 +81,15 @@ type mappedSelector[T any] struct {
8181
}
8282

8383
// Query performs a SELECT on the appropriate table for T. It combines the best
84-
// features of gorp, the go stdlib, and generics, using the type parameter of
84+
// features of borp, the go stdlib, and generics, using the type parameter of
8585
// the typeSelector object to automatically look up the proper table name and
8686
// columns to select. It returns an iterable which yields fully-populated
8787
// objects of the parameterized type directly. The given clauses MUST be only
8888
// the bits of a sql query from "WHERE ..." onwards; if they contain any of the
8989
// "SELECT ... FROM ..." portion of the query it will result in an error. The
90-
// args take the same kinds of values as gorp's SELECT: either one argument per
90+
// args take the same kinds of values as borp's SELECT: either one argument per
9191
// positional placeholder, or a map of placeholder names to their arguments
92-
// (see https://pkg.go.dev/gopkg.in/gorp.v2#readme-ad-hoc-sql).
92+
// (see https://pkg.go.dev/github.com/letsencrypt/borp#readme-ad-hoc-sql).
9393
//
9494
// The caller is responsible for calling `Rows.Close()` when they are done with
9595
// the query. The caller is also responsible for ensuring that the clauses
@@ -106,7 +106,7 @@ func (ts mappedSelector[T]) Query(ctx context.Context, clauses string, args ...i
106106
}
107107

108108
// QueryFrom is the same as Query, but it additionally takes a table name to
109-
// select from, rather than automatically computing the table name from gorp's
109+
// select from, rather than automatically computing the table name from borp's
110110
// DbMap.
111111
//
112112
// The caller is responsible for calling `Rows.Close()` when they are done with

db/interfaces.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"errors"
77
"reflect"
88

9-
"github.com/go-gorp/gorp/v3"
9+
"github.com/letsencrypt/borp"
1010
)
1111

1212
// These interfaces exist to aid in mocking database operations for unit tests.
@@ -36,7 +36,7 @@ type Execer interface {
3636
Exec(string, ...interface{}) (sql.Result, error)
3737
}
3838

39-
// SelectExecer offers a subset of gorp.SqlExecutor's methods: Select and
39+
// SelectExecer offers a subset of borp.SqlExecutor's methods: Select and
4040
// Exec.
4141
type SelectExecer interface {
4242
Selector
@@ -53,7 +53,7 @@ type DatabaseMap interface {
5353
}
5454

5555
// Executor offers the full combination of OneSelector, Inserter, SelectExecer
56-
// and adds a handful of other high level Gorp methods we use in Boulder.
56+
// and adds a handful of other high level borp methods we use in Boulder.
5757
type Executor interface {
5858
OneSelector
5959
Inserter
@@ -77,14 +77,14 @@ type Transaction interface {
7777
Executor
7878
Rollback() error
7979
Commit() error
80-
WithContext(ctx context.Context) gorp.SqlExecutor
80+
WithContext(ctx context.Context) borp.SqlExecutor
8181
}
8282

8383
// MappedExecutor is anything that can map types to tables, and which can
8484
// produce a SqlExecutor bound to a context.
8585
type MappedExecutor interface {
86-
TableFor(reflect.Type, bool) (*gorp.TableMap, error)
87-
WithContext(ctx context.Context) gorp.SqlExecutor
86+
TableFor(reflect.Type, bool) (*borp.TableMap, error)
87+
WithContext(ctx context.Context) borp.SqlExecutor
8888
}
8989

9090
// MappedSelector is anything that can execute various kinds of SQL statements
@@ -106,7 +106,7 @@ type Rows[T any] interface {
106106
// MockSqlExecuter implement SqlExecutor by returning errors from every call.
107107
//
108108
// To mock out WithContext, we need to be able to return objects that satisfy
109-
// gorp.SqlExecutor. That's a pretty big interface, so we specify one no-op mock
109+
// borp.SqlExecutor. That's a pretty big interface, so we specify one no-op mock
110110
// that we can embed everywhere we need to satisfy it.
111111
// Note: MockSqlExecutor does *not* implement WithContext. The expectation is
112112
// that structs that embed MockSqlExecutor will define their own WithContext

db/map.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"fmt"
88
"regexp"
99

10-
gorp "github.com/go-gorp/gorp/v3"
1110
"github.com/go-sql-driver/mysql"
11+
"github.com/letsencrypt/borp"
1212
)
1313

1414
// ErrDatabaseOp wraps an underlying err with a description of the operation
@@ -44,7 +44,7 @@ func (e ErrDatabaseOp) Unwrap() error {
4444

4545
// IsNoRows is a utility function for determining if an error wraps the go sql
4646
// package's ErrNoRows, which is returned when a Scan operation has no more
47-
// results to return, and as such is returned by many gorp methods.
47+
// results to return, and as such is returned by many borp methods.
4848
func IsNoRows(err error) bool {
4949
return errors.Is(err, sql.ErrNoRows)
5050
}
@@ -57,10 +57,10 @@ func IsDuplicate(err error) bool {
5757
return errors.As(err, &dbErr) && dbErr.Number == 1062
5858
}
5959

60-
// WrappedMap wraps a *gorp.DbMap such that its major functions wrap error
60+
// WrappedMap wraps a *borp.DbMap such that its major functions wrap error
6161
// results in ErrDatabaseOp instances before returning them to the caller.
6262
type WrappedMap struct {
63-
*gorp.DbMap
63+
*borp.DbMap
6464
}
6565

6666
func (m *WrappedMap) Get(holder interface{}, keys ...interface{}) (interface{}, error) {
@@ -95,7 +95,7 @@ func (m *WrappedMap) Exec(query string, args ...interface{}) (sql.Result, error)
9595
return WrappedExecutor{SqlExecutor: m.DbMap}.Exec(query, args...)
9696
}
9797

98-
func (m *WrappedMap) WithContext(ctx context.Context) gorp.SqlExecutor {
98+
func (m *WrappedMap) WithContext(ctx context.Context) borp.SqlExecutor {
9999
return WrappedExecutor{SqlExecutor: m.DbMap.WithContext(ctx)}
100100
}
101101

@@ -112,14 +112,14 @@ func (m *WrappedMap) Begin() (Transaction, error) {
112112
}, err
113113
}
114114

115-
// WrappedTransaction wraps a *gorp.Transaction such that its major functions
115+
// WrappedTransaction wraps a *borp.Transaction such that its major functions
116116
// wrap error results in ErrDatabaseOp instances before returning them to the
117117
// caller.
118118
type WrappedTransaction struct {
119-
*gorp.Transaction
119+
*borp.Transaction
120120
}
121121

122-
func (tx WrappedTransaction) WithContext(ctx context.Context) gorp.SqlExecutor {
122+
func (tx WrappedTransaction) WithContext(ctx context.Context) borp.SqlExecutor {
123123
return WrappedExecutor{SqlExecutor: tx.Transaction.WithContext(ctx)}
124124
}
125125

@@ -163,11 +163,11 @@ func (tx WrappedTransaction) Exec(query string, args ...interface{}) (sql.Result
163163
return (WrappedExecutor{SqlExecutor: tx.Transaction}).Exec(query, args...)
164164
}
165165

166-
// WrappedExecutor wraps a gorp.SqlExecutor such that its major functions
166+
// WrappedExecutor wraps a borp.SqlExecutor such that its major functions
167167
// wrap error results in ErrDatabaseOp instances before returning them to the
168168
// caller.
169169
type WrappedExecutor struct {
170-
gorp.SqlExecutor
170+
borp.SqlExecutor
171171
}
172172

173173
func errForOp(operation string, err error, list []interface{}) ErrDatabaseOp {
@@ -271,7 +271,7 @@ var (
271271

272272
// tableRegexps is a list of regexps that tableFromQuery will try to use in
273273
// succession to find the table name for an SQL query. While tableFromQuery
274-
// isn't used by the higher level gorp Insert/Update/Select/etc functions we
274+
// isn't used by the higher level borp Insert/Update/Select/etc functions we
275275
// include regexps for matching inserts, updates, selects, etc because we want
276276
// to match the correct table when these types of queries are run through
277277
// Exec().

db/map_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"testing"
99

10-
gorp "github.com/go-gorp/gorp/v3"
10+
"github.com/letsencrypt/borp"
1111

1212
"github.com/go-sql-driver/mysql"
1313
"github.com/letsencrypt/boulder/core"
@@ -236,10 +236,10 @@ func testDbMap(t *testing.T) *WrappedMap {
236236
dbConn, err := sql.Open("mysql", config.FormatDSN())
237237
test.AssertNotError(t, err, "opening DB connection")
238238

239-
dialect := gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8"}
239+
dialect := borp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8"}
240240
// NOTE(@cpu): We avoid giving a sa.BoulderTypeConverter to the DbMap field to
241241
// avoid the cyclic dep. We don't need to convert any types in the db tests.
242-
dbMap := &gorp.DbMap{Db: dbConn, Dialect: dialect, TypeConverter: nil}
242+
dbMap := &borp.DbMap{Db: dbConn, Dialect: dialect, TypeConverter: nil}
243243
return &WrappedMap{DbMap: dbMap}
244244
}
245245

db/multi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (mi *MultiInserter) Add(row []interface{}) error {
6868
}
6969

7070
// query returns the formatted query string, and the slice of arguments for
71-
// for gorp to use in place of the query's question marks. Currently only
71+
// for borp to use in place of the query's question marks. Currently only
7272
// used by .Insert(), below.
7373
func (mi *MultiInserter) query() (string, []interface{}) {
7474
var questionsBuf strings.Builder

docs/CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ Specifically, that means that all of our `SELECT` statements should enumerate
191191
columns to select, and not use `*`. Also, generally speaking, we will need a
192192
separate model `struct` for serializing and deserializing data before and
193193
after the migration. This is because the ORM package we use,
194-
[`gorp`](https://github.com/go-gorp/gorp), expects every field in a struct to
194+
[`borp`](https://github.com/letsencrypt/borp), expects every field in a struct to
195195
map to a column in the table. If we add a new field to a model struct and
196196
Boulder attempts to write that struct to a table that doesn't yet have the
197-
corresponding column (case 1), gorp will fail with `Insert failed table posts
197+
corresponding column (case 1), borp will fail with `Insert failed table posts
198198
has no column named Foo`. There are examples of such models in sa/model.go,
199199
along with code to turn a model into a `struct` used internally.
200200

@@ -270,14 +270,14 @@ func (ssa *SQLStorageAuthority) AddPerson(p Person) (error) {
270270
```
271271

272272
You will also need to update the `initTables` function from `sa/database.go` to
273-
tell Gorp which table to use for your versioned model structs. Make sure to
273+
tell borp which table to use for your versioned model structs. Make sure to
274274
consult the flag you defined so that only **one** of the table maps is added at
275-
any given time, otherwise Gorp will error. Depending on your table you may also
275+
any given time, otherwise borp will error. Depending on your table you may also
276276
need to add `SetKeys` and `SetVersionCol` entries for your versioned models.
277277
Example:
278278

279279
```go
280-
func initTables(dbMap *gorp.DbMap) {
280+
func initTables(dbMap *borp.DbMap) {
281281
// < unrelated lines snipped for brevity >
282282

283283
if features.Enabled(features.AllowWizards) {

go.mod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/aws/smithy-go v1.13.5
1010
github.com/beeker1121/goque v1.0.3-0.20191103205551-d618510128af
1111
github.com/eggsampler/acme/v3 v3.4.0
12-
github.com/go-gorp/gorp/v3 v3.1.0
1312
github.com/go-logr/stdr v1.2.2
1413
github.com/go-redis/redis/v8 v8.11.5
1514
github.com/go-sql-driver/mysql v1.5.0
@@ -18,6 +17,7 @@ require (
1817
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
1918
github.com/hpcloud/tail v1.0.0
2019
github.com/jmhodges/clock v1.2.0
20+
github.com/letsencrypt/borp v0.0.0-20230705195456-792de221e471
2121
github.com/letsencrypt/challtestsrv v1.2.1
2222
github.com/letsencrypt/pkcs11key/v4 v4.0.0
2323
github.com/letsencrypt/validator/v10 v10.0.0-20230215210743-a0c7dfc17158
@@ -73,11 +73,12 @@ require (
7373
github.com/golang/protobuf v1.5.3 // indirect
7474
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
7575
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
76+
github.com/kr/pretty v0.3.1 // indirect
7677
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
7778
github.com/pelletier/go-toml v1.9.3 // indirect
79+
github.com/poy/onpar v1.1.2 // indirect
7880
github.com/prometheus/common v0.37.0 // indirect
7981
github.com/prometheus/procfs v0.8.0 // indirect
80-
github.com/rogpeppe/go-internal v1.9.0 // indirect
8182
github.com/syndtr/goleveldb v1.0.0 // indirect
8283
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.15.0 // indirect
8384
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.15.0 // indirect
@@ -87,6 +88,7 @@ require (
8788
golang.org/x/sys v0.9.0 // indirect
8889
golang.org/x/tools v0.8.0 // indirect
8990
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
91+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
9092
gopkg.in/fsnotify.v1 v1.4.7 // indirect
9193
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
9294
k8s.io/klog/v2 v2.80.1 // indirect
@@ -96,3 +98,5 @@ require (
9698
// that we do not rely upon. It appears to introduce performance regressions
9799
// for us.
98100
exclude github.com/go-sql-driver/mysql v1.6.0
101+
102+
exclude github.com/go-sql-driver/mysql v1.7.1

0 commit comments

Comments
 (0)