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

Unified Diff: datahopper/go/buildbot_migratedb/main.go

Issue 813443002: Overhaul database package (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Assume the MySQL password is "" when running locally Created 5 years, 11 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 | « datahopper/Makefile ('k') | datahopper/go/datahopper/main.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: datahopper/go/buildbot_migratedb/main.go
diff --git a/datahopper/go/buildbot_migratedb/main.go b/datahopper/go/buildbot_migratedb/main.go
new file mode 100644
index 0000000000000000000000000000000000000000..45f8ef93462c66fa48e169e55ca8a6362bd7e1d4
--- /dev/null
+++ b/datahopper/go/buildbot_migratedb/main.go
@@ -0,0 +1,52 @@
+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 (
+ "flag"
+
+ "github.com/golang/glog"
+ "skia.googlesource.com/buildbot.git/go/buildbot"
+ "skia.googlesource.com/buildbot.git/go/common"
+ "skia.googlesource.com/buildbot.git/go/database"
+)
+
+var (
+ local = flag.Bool("local", false, "Running locally if true. As opposed to in production.")
+)
+
+func main() {
+ // Set up flags.
+ database.SetupFlags(buildbot.PROD_DB_HOST, buildbot.PROD_DB_PORT, database.USER_ROOT, buildbot.PROD_DB_NAME)
+
+ // Global init to initialize glog and parse arguments.
+ common.Init()
+
+ conf, err := database.ConfigFromFlagsAndMetadata(*local, buildbot.MigrationSteps())
+ if err != nil {
+ glog.Fatal(err)
+ }
+ vdb := database.NewVersionedDB(conf)
+
+ // Get the current database version
+ maxDBVersion := vdb.MaxDBVersion()
+ glog.Infof("Latest database version: %d", maxDBVersion)
+
+ dbVersion, err := vdb.DBVersion()
+ if err != nil {
+ glog.Fatalf("Unable to retrieve database version. Error: %s", err)
+ }
+ glog.Infof("Current database version: %d", dbVersion)
+
+ if dbVersion < maxDBVersion {
+ glog.Infof("Migrating to version: %d", maxDBVersion)
+ err = vdb.Migrate(maxDBVersion)
+ if err != nil {
+ glog.Fatalf("Unable to retrieve database version. Error: %s", err)
+ }
+ }
+
+ glog.Infoln("Database migration finished.")
+}
« no previous file with comments | « datahopper/Makefile ('k') | datahopper/go/datahopper/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698