-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (44 loc) · 1005 Bytes
/
main.go
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
44
45
46
47
package main
import (
"database/sql"
"fmt"
"github.com/cinemast/dbolve"
_ "github.com/lib/pq"
"log/slog"
)
func main() {
db, err := sql.Open("postgres", "postgres://postgres:postgres@localhost/dbolve_test?sslmode=disable")
if err != nil {
panic(err)
}
migrations := []dbolve.Migration{
{
Name: "Add account table",
Code: func(tx dbolve.Transaction) error {
return tx.Exec(`CREATE TABLE account(
user_id serial PRIMARY KEY,
username VARCHAR (50) UNIQUE NOT NULL,
password VARCHAR (50) NOT NULL
);`)
},
},
{
Name: "Add account 2 table",
Code: func(tx dbolve.Transaction) error {
return tx.Exec(`CREATE TABLE account2(
user_id serial PRIMARY KEY,
username VARCHAR (50) UNIQUE NOT NULL,
password VARCHAR (50) NOT NULL
);`)
},
},
}
m, err := dbolve.NewMigrator(db, migrations, slog.Default())
if err != nil {
panic(err)
}
if err := m.DryRun(); err != nil {
panic(err)
}
fmt.Println("Finished migrations")
}