Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1250a3

Browse files
committed
chore: improve error when db migration fails
1 parent 8befb34 commit a1250a3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cli/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,10 @@ func ConnectToPostgres(ctx context.Context, logger slog.Logger, driver string, d
21572157

21582158
err = migrations.Up(sqlDB)
21592159
if err != nil {
2160+
// Checks for database schema version mismatch
2161+
if errors.Is(err, os.ErrNotExist) && strings.Contains(err.Error(), "no migration found for version") {
2162+
return nil, xerrors.New("Current database schema requires a newer version of Coder!")
2163+
}
21602164
return nil, xerrors.Errorf("migrate up: %w", err)
21612165
}
21622166
// The default is 0 but the request will fail with a 500 if the DB

0 commit comments

Comments
 (0)