OLD | NEW |
(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 } |
OLD | NEW |