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

Unified Diff: perf/go/migratedb/main.go

Issue 608273002: Add versioning to perf SQL database (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Incorporating feedback 4 Created 6 years, 3 months 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
« no previous file with comments | « perf/go/ingest/main.go ('k') | perf/go/skiaperf/main.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: perf/go/migratedb/main.go
diff --git a/perf/go/migratedb/main.go b/perf/go/migratedb/main.go
new file mode 100644
index 0000000000000000000000000000000000000000..67c94aa109a248b32adabe302770c37db6413940
--- /dev/null
+++ b/perf/go/migratedb/main.go
@@ -0,0 +1,64 @@
+package main
+
+// Executes database migrations to the latest target version. In production this
+// requires the root password for MySQL. The user will be prompted for that so
+// it is not entered via the command line.
+
+import (
+ "bufio"
+ "flag"
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/golang/glog"
+ "skia.googlesource.com/buildbot.git/perf/go/db"
+)
+
+// flags
+var (
+ dbConnString = flag.String("db_conn_string", "root:%s@tcp(173.194.104.24:3306)/skia?parseTime=true", "\n\tDatabase string to open connect to the MySQL database. "+
+ "\n\tNeeds to follow the format of the golang-mysql driver (https://github.com/go-sql-driver/mysql."+
+ "\n\tIf the string contains %s the user will be prompted to enter a password which will then be used for subtitution.")
+)
+
+func main() {
+ flag.Parse()
+
+ var connectionStr = *dbConnString
+
+ // if it contains formatting information read the password from stdin.
+ if strings.Contains(connectionStr, "%s") {
+ glog.Infof("Using connection string: %s", connectionStr)
+ reader := bufio.NewReader(os.Stdin)
+ fmt.Print("Enter password for MySQL: ")
+ password, err := reader.ReadString('\n')
+ if err != nil {
+ glog.Fatalf("Unable to read password. Error: %s", err.Error())
+ }
+ connectionStr = fmt.Sprintf(connectionStr, strings.TrimRight(password, "\n"))
+ }
+
+ // Initialize the database.
+ db.Init(connectionStr)
+
+ // Get the current database version
+ maxDBVersion := db.MaxDBVersion()
+ glog.Infof("Latest database version: %d", maxDBVersion)
+
+ dbVersion, err := db.DBVersion()
+ if err != nil {
+ glog.Fatalf("Unable to retrieve database version. Error: %s", err.Error())
+ }
+ glog.Infof("Current database version: %d", dbVersion)
+
+ if dbVersion < maxDBVersion {
+ glog.Infof("Migrating to version: %d", maxDBVersion)
+ err = db.Migrate(maxDBVersion)
+ if err != nil {
+ glog.Fatalf("Unable to retrieve database version. Error: %s", err.Error())
+ }
+ }
+
+ glog.Infoln("Database migration finished.")
+}
« no previous file with comments | « perf/go/ingest/main.go ('k') | perf/go/skiaperf/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698