Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: perf/go/db/db.go

Issue 813443002: Overhaul database package (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Comments/readme cleanup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: perf/go/db/db.go
diff --git a/perf/go/db/db.go b/perf/go/db/db.go
index 56380dce6fedd47bb9a1b502b5654539706a5f4f..b874f98915f701f4bab16c230fe8a99ee3070ee6 100644
--- a/perf/go/db/db.go
+++ b/perf/go/db/db.go
@@ -3,28 +3,17 @@ package db
import (
"database/sql"
- "fmt"
-
- "github.com/golang/glog"
"skia.googlesource.com/buildbot.git/go/database"
- "skia.googlesource.com/buildbot.git/go/metadata"
)
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 = "./perf.db"
+ // Name of the database in production.
+ PROD_DB = "skia"
- // 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/skiaperf/overview
// And 3306 is the default port for MySQL.
- DB_CONN_TMPL = "%s:%s@tcp(173.194.104.24:3306)/skia?parseTime=true"
-
- // Username of the read/write user.
- RW_USER = "readwrite"
+ PROD_DB_HOST = "tcp(173.194.104.24:3306)"
)
var (
@@ -44,28 +33,15 @@ func MigrationSteps() []database.MigrationStep {
// 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
+// local MySQL test 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
-
+func DatabaseConfig(local bool) *database.DatabaseConfig {
// We are in the production environment, so we look up the parameters.
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.")
- }
- mysqlStr, sqlitePath = fmt.Sprintf(DB_CONN_TMPL, RW_USER, password), ""
+ return database.ProdDatabaseConfig(PROD_DB_HOST, PROD_DB, migrationSteps)
}
- return &database.DatabaseConfig{
- MySQLString: mysqlStr,
- SQLiteFilePath: sqlitePath,
- MigrationSteps: migrationSteps,
- }
+ return database.LocalDatabaseConfig(PROD_DB, migrationSteps)
}
// Define the migration steps.
@@ -97,31 +73,6 @@ var migrationSteps = []database.MigrationStep{
)`,
},
MySQLDown: []string{},
- SQLiteUp: []string{
- `CREATE TABLE clusters (
- id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- ts TIMESTAMP NOT NULL,
- hash TEXT NOT NULL,
- regression FLOAT NOT NULL,
- cluster MEDIUMTEXT NOT NULL,
- status TEXT NOT NULL,
- message TEXT NOT NULL
- )`,
- `CREATE TABLE shortcuts (
- id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- traces MEDIUMTEXT NOT NULL
- )`,
- `CREATE TABLE tries (
- issue VARCHAR(255) NOT NULL PRIMARY KEY,
- lastUpdated TIMESTAMP NOT NULL,
- results MEDIUMTEXT NOT NULL
- )`,
- },
- SQLiteDown: []string{
- `DROP TABLE IF EXISTS clusters`,
- `DROP TABLE IF EXISTS shortcuts`,
- `DROP TABLE IF EXISTS tries`,
- },
},
// version 2
{
@@ -135,18 +86,6 @@ var migrationSteps = []database.MigrationStep{
)`,
},
MySQLDown: []string{},
- SQLiteUp: []string{
- `CREATE TABLE activitylog (
- id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- timestamp TIMESTAMP NOT NULL,
- userid TEXT NOT NULL,
- action TEXT NOT NULL,
- url TEXT
- )`,
- },
- SQLiteDown: []string{
- `DROP TABLE IF EXISTS activitylog`,
- },
},
// Use this is a template for more migration steps.
@@ -154,7 +93,5 @@ var migrationSteps = []database.MigrationStep{
// {
// MySQLUp: ,
// MySQLDown: ,
- // SQLiteUp: ,
- // SQLiteDown: ,
// },
}
« go/buildbot/db.go ('K') | « perf/DESIGN.md ('k') | perf/go/db/db_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698