@@ -52,6 +52,10 @@ DB_CA_CERT and DB_USER(=gitpod)`,
52
52
cfg .Net = "tcp"
53
53
cfg .User = viper .GetString ("username" )
54
54
cfg .Passwd = viper .GetString ("password" )
55
+
56
+ // Must be "gitpod"
57
+ // Align to https://github.com/gitpod-io/gitpod/blob/884d922e8e33d8b936ec18d7fe3c8dcffde42b5a/components/gitpod-db/go/conn.go#L37
58
+ cfg .DBName = "gitpod"
55
59
cfg .Timeout = 1 * time .Second
56
60
57
61
dsn := cfg .FormatDSN ()
@@ -84,7 +88,7 @@ DB_CA_CERT and DB_USER(=gitpod)`,
84
88
}
85
89
86
90
log .WithField ("timeout" , timeout .String ()).WithField ("dsn" , censoredDSN ).WithField ("migrationName" , migration .Name ).WithField ("migrationTimestamp" , migration .Timestamp ).Info ("waiting for database" )
87
- for {
91
+ for ctx . Err () == nil {
88
92
log .Info ("attempting to check if database is available" )
89
93
if err := checkDbAvailable (ctx , cfg , & migration ); err != nil {
90
94
log .WithError (err ).Debug ("retry" )
@@ -94,10 +98,9 @@ DB_CA_CERT and DB_USER(=gitpod)`,
94
98
}
95
99
}
96
100
97
- select {
98
- case <- ctx .Done ():
99
- log .WithField ("timeout" , timeout .String ()).Fatal ("database did not become available in time" )
100
- default :
101
+ if ctx .Err () != nil {
102
+ log .WithField ("timeout" , timeout .String ()).WithError (ctx .Err ()).Fatal ("database did not become available in time" )
103
+ } else {
101
104
log .Info ("database became available" )
102
105
}
103
106
},
@@ -118,7 +121,7 @@ func checkDbAvailable(ctx context.Context, cfg *mysql.Config, migration *migrati
118
121
}
119
122
120
123
log .Info ("checking if database is migrated" )
121
- row := db .QueryRowContext (ctx , "SELECT name FROM " + migrationTableName + " WHERE 1690915807191 = ?" , migration .Timestamp )
124
+ row := db .QueryRowContext (ctx , "SELECT name FROM " + migrationTableName + " WHERE timestamp = ?" , migration .Timestamp )
122
125
var name string
123
126
if err := row .Scan (& name ); err != nil {
124
127
return err
0 commit comments