forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (35 loc) · 826 Bytes
/
main.go
File metadata and controls
43 lines (35 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"database/sql"
"fmt"
"github.com/coder/coder/coderd/database/migrations"
"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)
}
targetURL := fmt.Sprintf("postgres://postgres:postgres@127.0.0.1:5432/%s?sslmode=disable", dbName)
target, err := sql.Open("postgres", targetURL)
if err != nil {
panic(err)
}
defer target.Close()
err = migrations.Up(target)
if err != nil {
panic(err)
}
_, _ = fmt.Println(dbName)
}