2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-05 09:35:50 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellitedb
|
|
|
|
|
|
|
|
import (
|
2020-10-28 13:48:31 +00:00
|
|
|
"context"
|
2020-01-10 01:12:27 +00:00
|
|
|
"sync"
|
|
|
|
|
2018-12-07 14:46:42 +00:00
|
|
|
"github.com/zeebo/errs"
|
2019-02-14 21:55:21 +00:00
|
|
|
"go.uber.org/zap"
|
2018-12-07 14:46:42 +00:00
|
|
|
|
2021-08-12 17:26:43 +01:00
|
|
|
"storj.io/common/lrucache"
|
2021-04-23 10:52:40 +01:00
|
|
|
"storj.io/private/dbutil"
|
|
|
|
"storj.io/private/dbutil/pgutil"
|
|
|
|
"storj.io/private/tagsql"
|
2020-11-28 16:23:39 +00:00
|
|
|
"storj.io/storj/private/migrate"
|
2018-12-27 09:56:25 +00:00
|
|
|
"storj.io/storj/satellite"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting"
|
2019-06-19 13:02:37 +01:00
|
|
|
"storj.io/storj/satellite/attribution"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2021-11-12 20:47:41 +00:00
|
|
|
"storj.io/storj/satellite/buckets"
|
2020-03-10 20:42:11 +00:00
|
|
|
"storj.io/storj/satellite/compensation"
|
2019-01-16 20:23:28 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2019-09-25 18:12:44 +01:00
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
2020-07-01 16:25:20 +01:00
|
|
|
"storj.io/storj/satellite/nodeapiversion"
|
2022-10-31 15:28:29 +00:00
|
|
|
"storj.io/storj/satellite/nodeevents"
|
2022-01-19 18:25:31 +00:00
|
|
|
"storj.io/storj/satellite/oidc"
|
2019-03-27 10:24:35 +00:00
|
|
|
"storj.io/storj/satellite/orders"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2022-04-26 21:23:27 +01:00
|
|
|
"storj.io/storj/satellite/payments/billing"
|
2022-05-20 10:18:59 +01:00
|
|
|
"storj.io/storj/satellite/payments/storjscan"
|
2023-04-06 12:41:14 +01:00
|
|
|
"storj.io/storj/satellite/payments/stripe"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/repair/queue"
|
2021-06-23 00:09:39 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2020-06-03 14:51:02 +01:00
|
|
|
"storj.io/storj/satellite/revocation"
|
2020-01-15 02:29:51 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/dbx"
|
2021-01-14 16:41:36 +00:00
|
|
|
"storj.io/storj/satellite/snopayouts"
|
2018-12-05 09:35:50 +00:00
|
|
|
)
|
|
|
|
|
2021-01-15 15:34:41 +00:00
|
|
|
// Error is the default satellitedb errs class.
|
|
|
|
var Error = errs.Class("satellitedb")
|
2018-12-07 14:46:42 +00:00
|
|
|
|
2020-11-28 16:23:39 +00:00
|
|
|
type satelliteDBCollection struct {
|
|
|
|
dbs map[string]*satelliteDB
|
|
|
|
}
|
|
|
|
|
2019-12-14 02:29:54 +00:00
|
|
|
// satelliteDB combines access to different database tables with a record
|
|
|
|
// of the db driver, db implementation, and db source URL.
|
|
|
|
type satelliteDB struct {
|
|
|
|
*dbx.DB
|
2020-01-10 01:12:27 +00:00
|
|
|
|
2020-10-09 13:35:34 +01:00
|
|
|
migrationDB tagsql.DB
|
|
|
|
|
2021-05-11 09:49:26 +01:00
|
|
|
opts Options
|
|
|
|
log *zap.Logger
|
|
|
|
driver string
|
|
|
|
impl dbutil.Implementation
|
|
|
|
source string
|
2020-01-10 01:12:27 +00:00
|
|
|
|
|
|
|
consoleDBOnce sync.Once
|
|
|
|
consoleDB *ConsoleDB
|
2020-06-03 14:51:02 +01:00
|
|
|
|
|
|
|
revocationDBOnce sync.Once
|
|
|
|
revocationDB *revocationDB
|
2020-01-10 01:12:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Options includes options for how a satelliteDB runs.
|
2020-01-10 01:12:27 +00:00
|
|
|
type Options struct {
|
2020-12-04 10:24:39 +00:00
|
|
|
ApplicationName string
|
2021-04-23 13:59:10 +01:00
|
|
|
APIKeysLRUOptions lrucache.Options
|
|
|
|
RevocationLRUOptions lrucache.Options
|
2020-01-15 21:45:17 +00:00
|
|
|
|
2020-11-29 16:13:06 +00:00
|
|
|
// How many storage node rollups to save/read in one batch.
|
2020-11-28 20:54:52 +00:00
|
|
|
SaveRollupBatchSize int
|
2020-11-29 16:13:06 +00:00
|
|
|
ReadRollupBatchSize int
|
2018-12-05 09:35:50 +00:00
|
|
|
}
|
|
|
|
|
2019-12-14 02:29:54 +00:00
|
|
|
var _ dbx.DBMethods = &satelliteDB{}
|
|
|
|
|
2020-11-28 16:23:39 +00:00
|
|
|
var safelyPartitionableDBs = map[string]bool{
|
|
|
|
// WARNING: only list additional db names here after they have been
|
|
|
|
// validated to be safely partitionable and that they do not do
|
|
|
|
// cross-db queries.
|
2022-11-22 22:41:24 +00:00
|
|
|
"repairqueue": true,
|
|
|
|
"nodeevents": true,
|
|
|
|
"verifyqueue": true,
|
|
|
|
"reverifyqueue": true,
|
2020-11-28 16:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open creates instance of satellite.DB.
|
|
|
|
func Open(ctx context.Context, log *zap.Logger, databaseURL string, opts Options) (rv satellite.DB, err error) {
|
|
|
|
dbMapping, err := dbutil.ParseDBMapping(databaseURL)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
dbc := &satelliteDBCollection{dbs: map[string]*satelliteDB{}}
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
err = errs.Combine(err, dbc.Close())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
for key, val := range dbMapping {
|
|
|
|
db, err := open(ctx, log, val, opts, key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
dbc.dbs[key] = db
|
|
|
|
}
|
|
|
|
|
|
|
|
return dbc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func open(ctx context.Context, log *zap.Logger, databaseURL string, opts Options, override string) (*satelliteDB, error) {
|
2021-05-11 09:49:26 +01:00
|
|
|
driver, source, impl, err := dbutil.SplitConnStr(databaseURL)
|
2018-12-05 09:35:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-11 09:49:26 +01:00
|
|
|
if impl != dbutil.Postgres && impl != dbutil.Cockroach {
|
2019-10-18 20:03:10 +01:00
|
|
|
return nil, Error.New("unsupported driver %q", driver)
|
2019-03-12 13:29:13 +00:00
|
|
|
}
|
2019-10-18 20:03:10 +01:00
|
|
|
|
2020-12-04 10:24:39 +00:00
|
|
|
source, err = pgutil.CheckApplicationName(source, opts.ApplicationName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-18 20:03:10 +01:00
|
|
|
|
2020-01-03 19:13:57 +00:00
|
|
|
dbxDB, err := dbx.Open(driver, source)
|
2018-12-05 09:35:50 +00:00
|
|
|
if err != nil {
|
2019-12-14 02:29:54 +00:00
|
|
|
return nil, Error.New("failed opening database via DBX at %q: %v",
|
|
|
|
source, err)
|
2018-12-05 09:35:50 +00:00
|
|
|
}
|
2019-05-14 16:13:18 +01:00
|
|
|
log.Debug("Connected to:", zap.String("db source", source))
|
2018-12-27 09:56:25 +00:00
|
|
|
|
2020-11-28 16:23:39 +00:00
|
|
|
name := "satellitedb"
|
|
|
|
if override != "" {
|
|
|
|
name += ":" + override
|
|
|
|
}
|
|
|
|
dbutil.Configure(ctx, dbxDB.DB, name, mon)
|
2019-05-21 15:30:06 +01:00
|
|
|
|
2019-12-14 02:29:54 +00:00
|
|
|
core := &satelliteDB{
|
2020-01-10 01:12:27 +00:00
|
|
|
DB: dbxDB,
|
|
|
|
|
2021-05-11 09:49:26 +01:00
|
|
|
opts: opts,
|
|
|
|
log: log,
|
|
|
|
driver: driver,
|
|
|
|
impl: impl,
|
|
|
|
source: source,
|
2019-12-14 02:29:54 +00:00
|
|
|
}
|
2020-10-09 13:35:34 +01:00
|
|
|
|
|
|
|
core.migrationDB = core
|
|
|
|
|
2018-12-27 09:56:25 +00:00
|
|
|
return core, nil
|
2018-12-05 09:35:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) getByName(name string) *satelliteDB {
|
|
|
|
if safelyPartitionableDBs[name] {
|
|
|
|
if db, exists := dbc.dbs[name]; exists {
|
|
|
|
return db
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dbc.dbs[""]
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// PeerIdentities returns a storage for peer identities.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) PeerIdentities() overlay.PeerIdentities {
|
|
|
|
return &peerIdentities{db: dbc.getByName("peeridentities")}
|
2019-08-26 17:49:42 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Attribution is a getter for value attribution repository.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) Attribution() attribution.DB {
|
|
|
|
return &attributionDB{db: dbc.getByName("attribution")}
|
2019-06-18 14:06:33 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// OverlayCache is a getter for overlay cache repository.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) OverlayCache() overlay.DB {
|
|
|
|
return &overlaycache{db: dbc.getByName("overlaycache")}
|
2018-12-17 20:14:16 +00:00
|
|
|
}
|
2018-12-05 09:35:50 +00:00
|
|
|
|
2022-10-31 15:28:29 +00:00
|
|
|
// NodeEvents is a getter for node events repository.
|
|
|
|
func (dbc *satelliteDBCollection) NodeEvents() nodeevents.DB {
|
|
|
|
return &nodeEvents{db: dbc.getByName("nodeevents")}
|
|
|
|
}
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
// Reputation is a getter for overlay cache repository.
|
|
|
|
func (dbc *satelliteDBCollection) Reputation() reputation.DB {
|
|
|
|
return &reputations{db: dbc.getByName("reputations")}
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// RepairQueue is a getter for RepairQueue repository.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) RepairQueue() queue.RepairQueue {
|
|
|
|
return &repairQueue{db: dbc.getByName("repairqueue")}
|
2018-12-21 15:11:19 +00:00
|
|
|
}
|
2018-12-05 09:35:50 +00:00
|
|
|
|
2022-11-01 17:45:41 +00:00
|
|
|
// VerifyQueue is a getter for VerifyQueue database.
|
|
|
|
func (dbc *satelliteDBCollection) VerifyQueue() audit.VerifyQueue {
|
|
|
|
return &verifyQueue{db: dbc.getByName("verifyqueue")}
|
|
|
|
}
|
|
|
|
|
2022-10-05 14:24:04 +01:00
|
|
|
// ReverifyQueue is a getter for ReverifyQueue database.
|
|
|
|
func (dbc *satelliteDBCollection) ReverifyQueue() audit.ReverifyQueue {
|
|
|
|
return &reverifyQueue{db: dbc.getByName("reverifyqueue")}
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// StoragenodeAccounting returns database for tracking storagenode usage.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) StoragenodeAccounting() accounting.StoragenodeAccounting {
|
|
|
|
return &StoragenodeAccounting{db: dbc.getByName("storagenodeaccounting")}
|
2019-05-10 20:05:42 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// ProjectAccounting returns database for tracking project data use.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) ProjectAccounting() accounting.ProjectAccounting {
|
|
|
|
return &ProjectAccounting{db: dbc.getByName("projectaccounting")}
|
2018-12-14 14:27:21 +00:00
|
|
|
}
|
2018-12-05 09:35:50 +00:00
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Revocation returns the database to deal with macaroon revocation.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) Revocation() revocation.DB {
|
|
|
|
db := dbc.getByName("revocation")
|
2020-06-03 14:51:02 +01:00
|
|
|
db.revocationDBOnce.Do(func() {
|
2023-04-04 10:11:06 +01:00
|
|
|
options := db.opts.RevocationLRUOptions
|
|
|
|
options.Name = "satellitedb-revocations"
|
2020-06-03 14:51:02 +01:00
|
|
|
db.revocationDB = &revocationDB{
|
|
|
|
db: db,
|
2023-04-20 14:08:26 +01:00
|
|
|
lru: lrucache.NewOf[bool](options),
|
2020-06-03 14:51:02 +01:00
|
|
|
methods: db,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return db.revocationDB
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Console returns database for storing users, projects and api keys.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) Console() console.DB {
|
|
|
|
db := dbc.getByName("console")
|
2020-01-10 01:12:27 +00:00
|
|
|
db.consoleDBOnce.Do(func() {
|
|
|
|
db.consoleDB = &ConsoleDB{
|
|
|
|
apikeysLRUOptions: db.opts.APIKeysLRUOptions,
|
|
|
|
|
|
|
|
db: db,
|
|
|
|
methods: db,
|
|
|
|
|
|
|
|
apikeysOnce: new(sync.Once),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return db.consoleDB
|
2019-01-16 20:23:28 +00:00
|
|
|
}
|
2019-03-27 10:24:35 +00:00
|
|
|
|
2022-01-19 18:25:31 +00:00
|
|
|
// OIDC returns the database for storing OAuth and OIDC information.
|
|
|
|
func (dbc *satelliteDBCollection) OIDC() oidc.DB {
|
|
|
|
db := dbc.getByName("oidc")
|
|
|
|
return oidc.NewDB(db.DB)
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Orders returns database for storing orders.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) Orders() orders.DB {
|
|
|
|
db := dbc.getByName("orders")
|
2021-01-22 13:51:29 +00:00
|
|
|
return &ordersDB{db: db}
|
2019-03-27 10:24:35 +00:00
|
|
|
}
|
2019-05-22 15:50:22 +01:00
|
|
|
|
2022-11-23 15:24:30 +00:00
|
|
|
// Containment returns database for storing pending audit info.
|
|
|
|
// It does all of its work by way of the ReverifyQueue.
|
|
|
|
func (dbc *satelliteDBCollection) Containment() audit.Containment {
|
|
|
|
return &containment{reverifyQueue: dbc.ReverifyQueue()}
|
2022-11-22 16:59:04 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// GracefulExit returns database for graceful exit.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) GracefulExit() gracefulexit.DB {
|
|
|
|
return &gracefulexitDB{db: dbc.getByName("gracefulexit")}
|
2019-09-25 18:12:44 +01:00
|
|
|
}
|
2019-10-10 18:12:23 +01:00
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
// StripeCoinPayments returns database for stripecoinpayments.
|
2023-04-06 12:41:14 +01:00
|
|
|
func (dbc *satelliteDBCollection) StripeCoinPayments() stripe.DB {
|
2020-11-28 16:23:39 +00:00
|
|
|
return &stripeCoinPaymentsDB{db: dbc.getByName("stripecoinpayments")}
|
2019-10-17 15:04:50 +01:00
|
|
|
}
|
2019-12-27 22:03:03 +00:00
|
|
|
|
2022-04-26 21:23:27 +01:00
|
|
|
// Billing returns database for billing and payment transactions.
|
|
|
|
func (dbc *satelliteDBCollection) Billing() billing.TransactionsDB {
|
|
|
|
return &billingDB{db: dbc.getByName("billing")}
|
|
|
|
}
|
|
|
|
|
2022-05-20 10:18:59 +01:00
|
|
|
// Wallets returns database for storjscan wallets.
|
|
|
|
func (dbc *satelliteDBCollection) Wallets() storjscan.WalletsDB {
|
|
|
|
return &storjscanWalletsDB{db: dbc.getByName("storjscan")}
|
|
|
|
}
|
|
|
|
|
2021-01-15 16:23:19 +00:00
|
|
|
// SNOPayouts returns database for storagenode payStubs and payments info.
|
|
|
|
func (dbc *satelliteDBCollection) SNOPayouts() snopayouts.DB {
|
|
|
|
return &snopayoutsDB{db: dbc.getByName("snopayouts")}
|
2020-03-13 15:56:25 +00:00
|
|
|
}
|
2020-03-10 20:42:11 +00:00
|
|
|
|
2022-05-20 10:18:59 +01:00
|
|
|
// Compensation returns database for storage node compensation.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) Compensation() compensation.DB {
|
|
|
|
return &compensationDB{db: dbc.getByName("compensation")}
|
2020-03-10 20:42:11 +00:00
|
|
|
}
|
2020-07-01 16:25:20 +01:00
|
|
|
|
|
|
|
// NodeAPIVersion returns database for storage node api version lower bounds.
|
2020-11-28 16:23:39 +00:00
|
|
|
func (dbc *satelliteDBCollection) NodeAPIVersion() nodeapiversion.DB {
|
|
|
|
return &nodeAPIVersionDB{db: dbc.getByName("nodeapiversion")}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buckets returns database for interacting with buckets.
|
2021-11-12 20:47:41 +00:00
|
|
|
func (dbc *satelliteDBCollection) Buckets() buckets.DB {
|
2020-11-28 16:23:39 +00:00
|
|
|
return &bucketsDB{db: dbc.getByName("buckets")}
|
|
|
|
}
|
|
|
|
|
2022-05-10 13:18:23 +01:00
|
|
|
// StorjscanPayments returns database for storjscan payments.
|
|
|
|
func (dbc *satelliteDBCollection) StorjscanPayments() storjscan.PaymentsDB {
|
|
|
|
return &storjscanPayments{db: dbc.getByName("storjscan_payments")}
|
|
|
|
}
|
|
|
|
|
2020-11-28 16:23:39 +00:00
|
|
|
// CheckVersion confirms all databases are at the desired version.
|
|
|
|
func (dbc *satelliteDBCollection) CheckVersion(ctx context.Context) error {
|
|
|
|
var eg errs.Group
|
|
|
|
for _, db := range dbc.dbs {
|
|
|
|
eg.Add(db.CheckVersion(ctx))
|
|
|
|
}
|
|
|
|
return eg.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MigrateToLatest migrates all databases to the latest version.
|
|
|
|
func (dbc *satelliteDBCollection) MigrateToLatest(ctx context.Context) error {
|
|
|
|
var eg errs.Group
|
|
|
|
for _, db := range dbc.dbs {
|
|
|
|
eg.Add(db.MigrateToLatest(ctx))
|
|
|
|
}
|
|
|
|
return eg.Err()
|
|
|
|
}
|
|
|
|
|
2023-02-06 12:15:36 +00:00
|
|
|
// Close closes all satellite dbs.
|
|
|
|
func (dbc *satelliteDBCollection) Close() error {
|
2020-11-28 16:23:39 +00:00
|
|
|
var eg errs.Group
|
|
|
|
for _, db := range dbc.dbs {
|
2023-02-06 12:15:36 +00:00
|
|
|
eg.Add(db.Close())
|
2020-11-28 16:23:39 +00:00
|
|
|
}
|
|
|
|
return eg.Err()
|
|
|
|
}
|
|
|
|
|
2023-02-06 12:15:36 +00:00
|
|
|
// Testing provides access to testing facilities. These should not be used in production code.
|
|
|
|
func (db *satelliteDB) Testing() satellite.TestingDB {
|
|
|
|
return &satelliteDBTesting{satelliteDB: db}
|
|
|
|
}
|
|
|
|
|
|
|
|
type satelliteDBTesting struct{ *satelliteDB }
|
|
|
|
|
|
|
|
// RawDB returns the underlying database connection to the primary database.
|
|
|
|
func (db *satelliteDBTesting) RawDB() tagsql.DB {
|
|
|
|
return db.satelliteDB.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schema returns the full schema for the database.
|
|
|
|
func (db *satelliteDBTesting) Schema() string {
|
|
|
|
return db.satelliteDB.Schema()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProductionMigration returns the primary migration.
|
|
|
|
func (db *satelliteDBTesting) ProductionMigration() *migrate.Migration {
|
|
|
|
return db.satelliteDB.ProductionMigration()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestMigration returns the migration used for tests.
|
|
|
|
func (db *satelliteDBTesting) TestMigration() *migrate.Migration {
|
|
|
|
return db.satelliteDB.TestMigration()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Testing provides access to testing facilities. These should not be used in production code.
|
|
|
|
func (dbc *satelliteDBCollection) Testing() satellite.TestingDB {
|
|
|
|
return &satelliteDBCollectionTesting{satelliteDBCollection: dbc}
|
|
|
|
}
|
|
|
|
|
|
|
|
type satelliteDBCollectionTesting struct{ *satelliteDBCollection }
|
|
|
|
|
|
|
|
// RawDB returns the underlying database connection to the primary database.
|
|
|
|
func (dbc *satelliteDBCollectionTesting) RawDB() tagsql.DB {
|
|
|
|
return dbc.getByName("").DB.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schema returns the full schema for the database.
|
|
|
|
func (dbc *satelliteDBCollectionTesting) Schema() string {
|
|
|
|
return dbc.getByName("").Schema()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MigrateToLatest initializes the database for testplanet.
|
|
|
|
func (dbc *satelliteDBCollectionTesting) TestMigrateToLatest(ctx context.Context) error {
|
2020-11-28 16:23:39 +00:00
|
|
|
var eg errs.Group
|
|
|
|
for _, db := range dbc.dbs {
|
2023-02-06 12:15:36 +00:00
|
|
|
eg.Add(db.Testing().TestMigrateToLatest(ctx))
|
2020-11-28 16:23:39 +00:00
|
|
|
}
|
|
|
|
return eg.Err()
|
2020-07-01 16:25:20 +01:00
|
|
|
}
|
2023-02-06 12:15:36 +00:00
|
|
|
|
|
|
|
// ProductionMigration returns the primary migration.
|
|
|
|
func (dbc *satelliteDBCollectionTesting) ProductionMigration() *migrate.Migration {
|
|
|
|
return dbc.getByName("").ProductionMigration()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestMigration returns the migration used for tests.
|
|
|
|
func (dbc *satelliteDBCollectionTesting) TestMigration() *migrate.Migration {
|
|
|
|
return dbc.getByName("").TestMigration()
|
|
|
|
}
|
2023-05-08 12:15:09 +01:00
|
|
|
|
|
|
|
func withRows(rows tagsql.Rows, err error) func(func(tagsql.Rows) error) error {
|
|
|
|
return func(callback func(tagsql.Rows) error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err := callback(rows)
|
|
|
|
return errs.Combine(rows.Err(), rows.Close(), err)
|
|
|
|
}
|
|
|
|
}
|