OLD | NEW |
1 package main | 1 package main |
2 | 2 |
3 // Executes database migrations to the latest target version. In production this | 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 | 4 // requires the root password for MySQL. The user will be prompted for that so |
5 // it is not entered via the command line. | 5 // it is not entered via the command line. |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "flag" | 9 "flag" |
10 "fmt" | 10 "fmt" |
11 "os" | 11 "os" |
12 "strings" | 12 "strings" |
13 | 13 |
14 "github.com/golang/glog" | 14 "github.com/golang/glog" |
15 "skia.googlesource.com/buildbot.git/go/database" | 15 "skia.googlesource.com/buildbot.git/go/database" |
16 "skia.googlesource.com/buildbot.git/perf/go/db" | 16 "skia.googlesource.com/buildbot.git/perf/go/db" |
17 ) | 17 ) |
18 | 18 |
19 func main() { | 19 func main() { |
20 defaultConnStr := strings.Replace(db.DB_CONN_TMPL, "%s", "root", 1) | 20 defaultConnStr := strings.Replace(db.DB_CONN_TMPL, "%s", "root", 1) |
21 | 21 |
22 // flags | 22 // flags |
23 dbConnString := flag.String("db_conn_string", defaultConnStr, "\n\tDatab
ase string to open connect to the MySQL database. "+ | 23 dbConnString := flag.String("db_conn_string", defaultConnStr, "\n\tDatab
ase string to open connect to the MySQL database. "+ |
24 "\n\tNeeds to follow the format of the golang-mysql driver (http
s://github.com/go-sql-driver/mysql."+ | 24 "\n\tNeeds to follow the format of the golang-mysql driver (http
s://github.com/go-sql-driver/mysql."+ |
25 "\n\tIf the string contains %s the user will be prompted to ente
r a password which will then be used for subtitution.") | 25 "\n\tIf the string contains %s the user will be prompted to ente
r a password which will then be used for subtitution.") |
26 | 26 |
27 flag.Parse() | 27 flag.Parse() |
| 28 defer glog.Flush() |
28 | 29 |
29 var connectionStr = *dbConnString | 30 var connectionStr = *dbConnString |
30 | 31 |
31 // if it contains formatting information read the password from stdin. | 32 // if it contains formatting information read the password from stdin. |
32 if strings.Contains(connectionStr, "%s") { | 33 if strings.Contains(connectionStr, "%s") { |
33 glog.Infof("Using connection string: %s", connectionStr) | 34 glog.Infof("Using connection string: %s", connectionStr) |
34 reader := bufio.NewReader(os.Stdin) | 35 reader := bufio.NewReader(os.Stdin) |
35 fmt.Print("Enter password for MySQL: ") | 36 fmt.Print("Enter password for MySQL: ") |
36 password, err := reader.ReadString('\n') | 37 password, err := reader.ReadString('\n') |
37 if err != nil { | 38 if err != nil { |
(...skipping 21 matching lines...) Expand all Loading... |
59 if dbVersion < maxDBVersion { | 60 if dbVersion < maxDBVersion { |
60 glog.Infof("Migrating to version: %d", maxDBVersion) | 61 glog.Infof("Migrating to version: %d", maxDBVersion) |
61 err = vdb.Migrate(maxDBVersion) | 62 err = vdb.Migrate(maxDBVersion) |
62 if err != nil { | 63 if err != nil { |
63 glog.Fatalf("Unable to retrieve database version. Error:
%s", err.Error()) | 64 glog.Fatalf("Unable to retrieve database version. Error:
%s", err.Error()) |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 glog.Infoln("Database migration finished.") | 68 glog.Infoln("Database migration finished.") |
68 } | 69 } |
OLD | NEW |