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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « datahopper/Makefile ('k') | datahopper/go/datahopper/main.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 package main
2
3 // Executes database migrations to the latest target version. In production this
4 // requires the root password for MySQL. The user will be prompted for that so
5 // it is not entered via the command line.
6
7 import (
8 "flag"
9
10 "github.com/golang/glog"
11 "skia.googlesource.com/buildbot.git/go/buildbot"
12 "skia.googlesource.com/buildbot.git/go/common"
13 "skia.googlesource.com/buildbot.git/go/database"
14 )
15
16 var (
17 local = flag.Bool("local", false, "Running locally if true. As opposed t o in production.")
18 )
19
20 func main() {
21 // Set up flags.
22 database.SetupFlags(buildbot.PROD_DB_HOST, buildbot.PROD_DB_PORT, databa se.USER_ROOT, buildbot.PROD_DB_NAME)
23
24 // Global init to initialize glog and parse arguments.
25 common.Init()
26
27 conf, err := database.ConfigFromFlagsAndMetadata(*local, buildbot.Migrat ionSteps())
28 if err != nil {
29 glog.Fatal(err)
30 }
31 vdb := database.NewVersionedDB(conf)
32
33 // Get the current database version
34 maxDBVersion := vdb.MaxDBVersion()
35 glog.Infof("Latest database version: %d", maxDBVersion)
36
37 dbVersion, err := vdb.DBVersion()
38 if err != nil {
39 glog.Fatalf("Unable to retrieve database version. Error: %s", er r)
40 }
41 glog.Infof("Current database version: %d", dbVersion)
42
43 if dbVersion < maxDBVersion {
44 glog.Infof("Migrating to version: %d", maxDBVersion)
45 err = vdb.Migrate(maxDBVersion)
46 if err != nil {
47 glog.Fatalf("Unable to retrieve database version. Error: %s", err)
48 }
49 }
50
51 glog.Infoln("Database migration finished.")
52 }
OLDNEW
« 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