fix(coderd): remove `CREATE INDEX CONCURRENTLY` from migrations (#8353)

This commit is contained in:
Colin Adler 2023-07-06 16:44:29 -05:00 committed by GitHub
parent 2ebd0ec6c5
commit 9a0ba1bdc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -1 +1 @@
CREATE INDEX CONCURRENTLY workspace_resources_job_id_idx ON workspace_resources USING btree (job_id);
CREATE INDEX workspace_resources_job_id_idx ON workspace_resources USING btree (job_id);

View File

@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"github.com/coder/coder/coderd/database/migrations"
"github.com/coder/coder/coderd/database/postgres"
@ -47,6 +48,22 @@ func TestMigrate(t *testing.T) {
require.NoError(t, err)
})
t.Run("Parallel", func(t *testing.T) {
t.Parallel()
db := testSQLDB(t)
eg := errgroup.Group{}
eg.Go(func() error {
return migrations.Up(db)
})
eg.Go(func() error {
return migrations.Up(db)
})
require.NoError(t, eg.Wait())
})
t.Run("Twice", func(t *testing.T) {
t.Parallel()
@ -86,6 +103,13 @@ func testSQLDB(t testing.TB) *sql.DB {
require.NoError(t, err)
t.Cleanup(func() { _ = db.Close() })
// postgres.Open automatically runs migrations, but we want to actually test
// migration behavior in this package.
_, err = db.Exec(`DROP SCHEMA public CASCADE`)
require.NoError(t, err)
_, err = db.Exec(`CREATE SCHEMA public`)
require.NoError(t, err)
return db
}