mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test: Use a template to prevent migrations from running for every test (#2462)
* test: Use a template to prevent migrations from running for every test * Create a single makefile target * Fix built-in race * Extend timeout of built-in PostgreSQL fetch
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
"github.com/coder/coder/cryptorand"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dbURL := "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable"
|
||||
db, err := sql.Open("postgres", dbURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
dbName, err := cryptorand.StringCharset(cryptorand.Lower, 10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
dbName = "ci" + dbName
|
||||
_, err = db.Exec("CREATE DATABASE " + dbName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = database.MigrateUp(db)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, _ = fmt.Println(dbName)
|
||||
}
|
||||
Reference in New Issue
Block a user