satellite: remove implementation detail from DB interface

Which database access and how it internally does migrations is an
implementation detail and does not belong in the requirements interface.

Change-Id: Ia4a6994f39470063a96a8e5f3a1bd27aa79fe5cd
This commit is contained in:
Egon Elbre 2020-11-30 13:18:45 +02:00
parent 28ea63be92
commit f456d7ce03
2 changed files with 13 additions and 10 deletions

View File

@ -12,7 +12,6 @@ import (
"storj.io/common/identity"
"storj.io/private/debug"
"storj.io/storj/pkg/server"
"storj.io/storj/private/migrate"
version_checker "storj.io/storj/private/version/checker"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/accounting/live"
@ -48,7 +47,6 @@ import (
"storj.io/storj/satellite/repair/repairer"
"storj.io/storj/satellite/revocation"
"storj.io/storj/satellite/rewards"
"storj.io/storj/satellite/satellitedb/dbx"
"storj.io/storj/satellite/snopayout"
)
@ -71,12 +69,6 @@ type DB interface {
// TestingMigrateToLatest initializes the database for testplanet.
TestingMigrateToLatest(ctx context.Context) error
// MigrationTestingDefaultDB assists in testing migrations themselves
// against the default database.
MigrationTestingDefaultDB() interface {
TestDBAccess() *dbx.DB
PostgresMigration() *migrate.Migration
}
// PeerIdentities returns a storage for peer identities
PeerIdentities() overlay.PeerIdentities

View File

@ -25,7 +25,9 @@ import (
"storj.io/storj/private/dbutil/pgtest"
"storj.io/storj/private/dbutil/pgutil"
"storj.io/storj/private/dbutil/tempdb"
"storj.io/storj/private/migrate"
"storj.io/storj/satellite/satellitedb"
"storj.io/storj/satellite/satellitedb/dbx"
)
// loadSnapshots loads all the dbschemas from `testdata/postgres.*`.
@ -132,6 +134,15 @@ func loadSchemaFromSQL(ctx context.Context, connstr, script string) (_ *dbschema
func TestMigratePostgres(t *testing.T) { migrateTest(t, pgtest.PickPostgres(t)) }
func TestMigrateCockroach(t *testing.T) { migrateTest(t, pgtest.PickCockroachAlt(t)) }
type migrationTestingAccess interface {
// MigrationTestingDefaultDB assists in testing migrations themselves
// against the default database.
MigrationTestingDefaultDB() interface {
TestDBAccess() *dbx.DB
PostgresMigration() *migrate.Migration
}
}
func migrateTest(t *testing.T, connStr string) {
t.Parallel()
@ -151,7 +162,7 @@ func migrateTest(t *testing.T, connStr string) {
defer func() { require.NoError(t, db.Close()) }()
// we need raw database access unfortunately
rawdb := db.MigrationTestingDefaultDB().TestDBAccess()
rawdb := db.(migrationTestingAccess).MigrationTestingDefaultDB().TestDBAccess()
snapshots, dbxschema, err := loadSnapshots(ctx, connStr, rawdb.Schema())
require.NoError(t, err)
@ -159,7 +170,7 @@ func migrateTest(t *testing.T, connStr string) {
var finalSchema *dbschema.Schema
// get migration for this database
migrations := db.MigrationTestingDefaultDB().PostgresMigration()
migrations := db.(migrationTestingAccess).MigrationTestingDefaultDB().PostgresMigration()
for i, step := range migrations.Steps {
tag := fmt.Sprintf("#%d - v%d", i, step.Version)