Skip to content

Commit 1a5a623

Browse files
committed
select db
1 parent 884d922 commit 1a5a623

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

components/service-waiter/cmd/database.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ DB_CA_CERT and DB_USER(=gitpod)`,
5252
cfg.Net = "tcp"
5353
cfg.User = viper.GetString("username")
5454
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"
5559
cfg.Timeout = 1 * time.Second
5660

5761
dsn := cfg.FormatDSN()
@@ -84,7 +88,7 @@ DB_CA_CERT and DB_USER(=gitpod)`,
8488
}
8589

8690
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 {
8892
log.Info("attempting to check if database is available")
8993
if err := checkDbAvailable(ctx, cfg, &migration); err != nil {
9094
log.WithError(err).Debug("retry")
@@ -94,10 +98,9 @@ DB_CA_CERT and DB_USER(=gitpod)`,
9498
}
9599
}
96100

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 {
101104
log.Info("database became available")
102105
}
103106
},
@@ -118,7 +121,7 @@ func checkDbAvailable(ctx context.Context, cfg *mysql.Config, migration *migrati
118121
}
119122

120123
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)
122125
var name string
123126
if err := row.Scan(&name); err != nil {
124127
return err

0 commit comments

Comments
 (0)