Skip to content

Commit 8a6635b

Browse files
authored
chore: Never run v2 migrations on v1 database (#6438)
1 parent 22e3ff9 commit 8a6635b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

coderd/database/migrations/migrate.go

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func setup(db *sql.DB) (source.Driver, *migrate.Migrate, error) {
2525
return nil, nil, xerrors.Errorf("create iofs: %w", err)
2626
}
2727

28+
// migration_cursor is a v1 migration table. If this exists, we're on v1.
29+
// Do no run v2 migrations on a v1 database!
30+
row := db.QueryRowContext(ctx, "SELECT * FROM migration_cursor;")
31+
if row.Err() == nil {
32+
return nil, nil, xerrors.Errorf("currently connected to a Coder v1 database, aborting database setup")
33+
}
34+
2835
// there is a postgres.WithInstance() method that takes the DB instance,
2936
// but, when you close the resulting Migrate, it closes the DB, which
3037
// we don't want. Instead, create just a connection that will get closed

0 commit comments

Comments
 (0)