e2c0dd437a
..although it ought to work for other storage.KeyValueStore needs as well. it's just optimized to work pretty well for a largish hierarchy of paths. This includes the addition of "long benchmarks" for KeyValueStore testing. These will only be run when -test-bench-long is added to the test flags. In these benchmarks, a large corpus of paths matching a natural ("real-life") hierarchy is read from paths.data.gz (which you can get from https://github.com/storj/path-test-corpus) and imported into a particular KeyValueStore. Recursive and non-recursive queries are run on it to detect performance problems that arise only at scale. This also includes alternate implementation of the postgreskv client, which works in a less-bizarre way for non-recursive queries, but suffers from poor performance in tests such as the long benchmarks. Once this alternate impl is committed to the tree, we can remove it again; I just want it to be available for future reference.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
//go:generate go-bindata -o data.go -pkg schema -ignore ".*go" .
|
|
|
|
package schema
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
// this isn't strictly necessary to import, but we just need the go-bindata
|
|
// binary for the above generate, and go mod tidy wants to remove
|
|
// go-bindata because nothing else is importing it. better solutions?
|
|
_ "github.com/go-bindata/go-bindata"
|
|
|
|
"github.com/golang-migrate/migrate/v3"
|
|
"github.com/golang-migrate/migrate/v3/database/postgres"
|
|
"github.com/golang-migrate/migrate/v3/source/go_bindata"
|
|
)
|
|
|
|
// PrepareDB applies schema migrations as necessary to the given database to
|
|
// get it up to date.
|
|
func PrepareDB(db *sql.DB) error {
|
|
srcDriver, err := bindata.WithInstance(bindata.Resource(AssetNames(),
|
|
func(name string) ([]byte, error) {
|
|
return Asset(name)
|
|
}))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
dbDriver, err := postgres.WithInstance(db, &postgres.Config{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m, err := migrate.NewWithInstance("go-bindata migrations", srcDriver, "postgreskv db", dbDriver)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = m.Up()
|
|
if err == migrate.ErrNoChange {
|
|
err = nil
|
|
}
|
|
return err
|
|
}
|