MCPcopy Index your code
hub / github.com/coder/coder / main

Function main

scripts/migrate-ci/main.go:11–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func main() {
12 dbURL := "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable"
13 db, err := sql.Open("postgres", dbURL)
14 if err != nil {
15 panic(err)
16 }
17 defer db.Close()
18
19 dbName, err := cryptorand.StringCharset(cryptorand.Lower, 10)
20 if err != nil {
21 panic(err)
22 }
23
24 dbName = "ci" + dbName
25 _, err = db.Exec("CREATE DATABASE " + dbName)
26 if err != nil {
27 panic(err)
28 }
29
30 targetURL := fmt.Sprintf("postgres://postgres:postgres@127.0.0.1:5432/%s?sslmode=disable", dbName)
31 target, err := sql.Open("postgres", targetURL)
32 if err != nil {
33 panic(err)
34 }
35 defer target.Close()
36
37 err = migrations.Up(target)
38 if err != nil {
39 panic(err)
40 }
41
42 _, _ = fmt.Println(dbName)
43}

Callers

nothing calls this directly

Calls 5

StringCharsetFunction · 0.92
UpFunction · 0.92
CloseMethod · 0.65
ExecMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected