| Index: golden/go/db/db.go
|
| diff --git a/golden/go/db/db.go b/golden/go/db/db.go
|
| index 99277cc245e92a5fde5d4d82a83aca8224495493..ec7128063742aa859acb4b3358b7de49b058321d 100644
|
| --- a/golden/go/db/db.go
|
| +++ b/golden/go/db/db.go
|
| @@ -2,11 +2,8 @@ package db
|
|
|
| import (
|
| "fmt"
|
| - "strings"
|
|
|
| - "github.com/golang/glog"
|
| "skia.googlesource.com/buildbot.git/go/database"
|
| - "skia.googlesource.com/buildbot.git/go/metadata"
|
| )
|
|
|
| const (
|
| @@ -28,34 +25,19 @@ func MigrationSteps() []database.MigrationStep {
|
| return migrationSteps
|
| }
|
|
|
| -// GetConfig returns a DatabaseConfig instance for running in production if a
|
| -// metadata server is available. If 'local' is true it will always
|
| -// set the MySQL connection string to "" and thus use a local SQLite database
|
| -// when used with database.NewVersionedDB.
|
| -func GetConfig(mySQLConnStr string, sqlitePath string, local bool) *database.DatabaseConfig {
|
| - useMySQLConnStr := mySQLConnStr
|
| -
|
| - // We are in the production environment, so we look up the password.
|
| - if !local {
|
| - // First, get the password from the metadata server.
|
| - // See https://developers.google.com/compute/docs/metadata#custom.
|
| - password, err := metadata.Get(METADATA_KEY)
|
| - if err != nil {
|
| - glog.Fatalf("Failed to find metadata. Use 'local' flag when running locally.")
|
| - }
|
| - useMySQLConnStr = fmt.Sprintf(mySQLConnStr, password)
|
| - }
|
| -
|
| - // If there is still a placeholder in the connection string, we
|
| - // set it to empty, so that the the local SQLite database kicks in.
|
| - if strings.Contains(useMySQLConnStr, "%s") {
|
| - useMySQLConnStr = ""
|
| +// DatabaseConfig returns a DatabaseConfig instance. If mySQLConnStr is
|
| +// provided, it overrides all other settings. Otherwise, if 'local' is true
|
| +// a config for a local MySQL database is returned. If 'local' is false, a
|
| +// config appropriate for running in production is returned.
|
| +func DatabaseConfig(mySQLConnStr string, local bool) (*database.DatabaseConfig, error) {
|
| + if mySQLConnStr != "" {
|
| + return database.ResolveCustomMySQLString(mySQLConnStr, migrationSteps)
|
| }
|
|
|
| - return &database.DatabaseConfig{
|
| - MySQLString: useMySQLConnStr,
|
| - SQLiteFilePath: sqlitePath,
|
| - MigrationSteps: migrationSteps,
|
| + if local {
|
| + return database.LocalDatabaseConfig(DEFAULT_DB_NAME, migrationSteps), nil
|
| + } else {
|
| + return database.ProdDatabaseConfig(database.AddrFromHostPort(DEFAULT_DB_HOST, DEFAULT_DB_PORT), DEFAULT_DB_NAME, migrationSteps), nil
|
| }
|
| }
|
|
|
| @@ -97,17 +79,6 @@ var migrationSteps = []database.MigrationStep{
|
| MySQLDown: []string{
|
| `DROP TABLE expectations`,
|
| },
|
| - SQLiteUp: []string{
|
| - `CREATE TABLE expectations (
|
| - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
| - userid TEXT NOT NULL,
|
| - ts BIGINT NOT NULL,
|
| - expectations MEDIUXMTEXT NOT NULL
|
| - )`,
|
| - },
|
| - SQLiteDown: []string{
|
| - `DROP TABLE expectations`,
|
| - },
|
| },
|
|
|
| // Use this is a template for more migration steps.
|
| @@ -115,7 +86,5 @@ var migrationSteps = []database.MigrationStep{
|
| // {
|
| // MySQLUp: ,
|
| // MySQLDown: ,
|
| - // SQLiteUp: ,
|
| - // SQLiteDown: ,
|
| // },
|
| }
|
|
|