satellite: add ctx to DB.CreateTables

Change-Id: I9ecad624cf5a7fc9c86bb91c68f96a3a4efd2e92
This commit is contained in:
Egon Elbre 2020-01-13 15:31:09 +02:00
parent 0835b9024c
commit 24958bd7d3
5 changed files with 10 additions and 8 deletions

View File

@ -248,7 +248,9 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
}
func cmdMigrationRun(cmd *cobra.Command, args []string) (err error) {
ctx, _ := process.Ctx(cmd)
log := zap.L()
db, err := satellitedb.New(log.Named("migration"), runCfg.Database, satellitedb.Options{})
if err != nil {
return errs.New("Error creating new master database connection for satellitedb migration: %+v", err)
@ -257,7 +259,7 @@ func cmdMigrationRun(cmd *cobra.Command, args []string) (err error) {
err = errs.Combine(err, db.Close())
}()
err = db.CreateTables()
err = db.CreateTables(ctx)
if err != nil {
return errs.New("Error creating tables for master database on satellite: %+v", err)
}

View File

@ -435,7 +435,7 @@ func (planet *Planet) newSatellites(count int) ([]*SatelliteSystem, error) {
return xs, err
}
err = db.CreateTables()
err = db.CreateTables(context.TODO())
if err != nil {
return nil, err
}

View File

@ -4,6 +4,8 @@
package satellite
import (
"context"
"gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/common/identity"
@ -45,7 +47,7 @@ var mon = monkit.Package()
// architecture: Master Database
type DB interface {
// CreateTables initializes the database
CreateTables() error
CreateTables(ctx context.Context) error
// CheckVersion checks the database is the correct version
CheckVersion() error
// Close closes the database

View File

@ -23,9 +23,7 @@ var (
)
// CreateTables is a method for creating all tables for database
func (db *satelliteDB) CreateTables() error {
ctx := context.TODO()
func (db *satelliteDB) CreateTables(ctx context.Context) error {
// First handle the idiosyncrasies of postgres and cockroach migrations. Postgres
// will need to create any schemas specified in the search path, and cockroach
// will need to create the database it was told to connect to. These things should

View File

@ -185,7 +185,7 @@ func Run(t *testing.T, test func(t *testing.T, db satellite.DB)) {
}
}()
err = db.CreateTables()
err = db.CreateTables(ctx)
if err != nil {
t.Fatal(err)
}
@ -220,7 +220,7 @@ func Bench(b *testing.B, bench func(b *testing.B, db satellite.DB)) {
}
}()
err = db.CreateTables()
err = db.CreateTables(ctx)
if err != nil {
b.Fatal(err)
}