| Index: go/buildbot/db_setup.go
|
| diff --git a/go/buildbot/db_setup.go b/go/buildbot/db_setup.go
|
| index 5cacd2ee1efe73cfe80dc1b51ce49d27b3f7bb2d..9371f4e0c87e488ce1633753bf38e36867929fc9 100644
|
| --- a/go/buildbot/db_setup.go
|
| +++ b/go/buildbot/db_setup.go
|
| @@ -17,19 +17,10 @@ const (
|
| // Key of the password for the readwrite user.
|
| METADATA_KEY = "readwrite"
|
|
|
| - // Path where the SQLite database is stored when running locally.
|
| - SQLITE_DB_PATH = "./testing.db"
|
| -
|
| - DATABASE = "buildbot"
|
| -
|
| - // Template to generate the database connection string in production.
|
| - // The IP address of the database is found here:
|
| - // https://console.developers.google.com/project/31977622648/sql/instances/skia-master-db/overview
|
| - // And 3306 is the default port for MySQL.
|
| - DB_CONN_TMPL = "%s:%s@tcp(173.194.253.125:3306)/%s?parseTime=true"
|
| -
|
| - // Username of the read/write user.
|
| - RW_USER = "readwrite"
|
| + // Production database.
|
| + PROD_DATABASE = "buildbot"
|
| + PROD_DB_HOST = "tcp(173.194.253.125:3306)"
|
| + PROD_USER = "readwrite"
|
|
|
| TABLE_BUILDS = "builds"
|
| TABLE_BUILD_REVISIONS = "buildRevisions"
|
| @@ -41,7 +32,8 @@ var (
|
| )
|
|
|
| // Setup the database to be shared across the app.
|
| -func InitDB(conf *database.DatabaseConfig) error {
|
| +func InitDB(local bool) error {
|
| + conf := databaseConfig(local)
|
| vdb := database.NewVersionedDB(conf)
|
| dbVersion, err := vdb.DBVersion()
|
| if err != nil {
|
| @@ -57,51 +49,29 @@ func InitDB(conf *database.DatabaseConfig) error {
|
| if err = vdb.Close(); err != nil {
|
| return fmt.Errorf("Could not close database: %v", err)
|
| }
|
| - if conf.MySQLString != "" {
|
| - DB, err = sqlx.Open("mysql", conf.MySQLString)
|
| - } else {
|
| - DB, err = sqlx.Open("sqlite3", conf.SQLiteFilePath)
|
| - }
|
| + DB, err = sqlx.Open("mysql", conf.MySQLString)
|
| if err != nil {
|
| return fmt.Errorf("Failed to open database: %v", err)
|
| }
|
| return nil
|
| }
|
|
|
| -// Returns the DB connection string for running in production where a
|
| -// metadata server is available. If 'local' is true it will always return
|
| -// "" (empty string). When used with Init() this will cause it to use a
|
| -// local SQLite database. If it's not local and the meta data server is
|
| -// unreachable it will terminate.
|
| -func ProdDatabaseConfig(local bool) *database.DatabaseConfig {
|
| - mysqlStr := ""
|
| - sqlitePath := SQLITE_DB_PATH
|
| +// databaseConfig returns the DB connection config. If 'local' is true it
|
| +// returns a config suitable for local testing. Otherwise it assumes that it's
|
| +// running in production and a metadata server is available.
|
| +func databaseConfig(local bool) *database.DatabaseConfig {
|
| + if local {
|
| + return database.LocalTestDatabaseConfig(migrationSteps)
|
| + } else {
|
| + // We are in the production environment, so we look up the parameters.
|
|
|
| - // We are in the production environment, so we look up the parameters.
|
| - if !local {
|
| - // First, get the password from the metadata server.
|
| + // 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.")
|
| }
|
| - mysqlStr, sqlitePath = fmt.Sprintf(DB_CONN_TMPL, RW_USER, password, DATABASE), ""
|
| - }
|
| -
|
| - return &database.DatabaseConfig{
|
| - MySQLString: mysqlStr,
|
| - SQLiteFilePath: sqlitePath,
|
| - MigrationSteps: migrationSteps,
|
| - }
|
| -}
|
| -
|
| -// Returns a DB connection string for running a local testing MySQL instance.
|
| -func LocalMySQLTestDatabaseConfig(user, password string) *database.DatabaseConfig {
|
| - mysqlStr := fmt.Sprintf("%s:%s@/sk_testing", user, password)
|
| - return &database.DatabaseConfig{
|
| - MySQLString: mysqlStr,
|
| - SQLiteFilePath: "",
|
| - MigrationSteps: migrationSteps,
|
| + return database.NewDatabaseConfig(PROD_USER, password, PROD_DB_HOST, PROD_DATABASE, migrationSteps)
|
| }
|
| }
|
|
|
| @@ -152,9 +122,7 @@ var v1_down = []string{
|
| var migrationSteps = []database.MigrationStep{
|
| // version 1
|
| {
|
| - MySQLUp: v1_up,
|
| - MySQLDown: v1_down,
|
| - SQLiteUp: v1_up,
|
| - SQLiteDown: v1_down,
|
| + MySQLUp: v1_up,
|
| + MySQLDown: v1_down,
|
| },
|
| }
|
|
|