forked from Servicewall/clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrator_test.go
43 lines (36 loc) · 860 Bytes
/
migrator_test.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
package clickhouse_test
import (
"testing"
"time"
)
type User struct {
ID uint
Name string
FirstName string
LastName string
Age int64
Active bool
Salary float32
CreatedAt time.Time
UpdatedAt time.Time
}
func TestAutoMigrate(t *testing.T) {
type UserMigrateColumn struct {
ID uint
Name string
IsAdmin bool
Birthday time.Time `gorm:"precision:4"`
}
if DB.Migrator().HasColumn("users", "is_admin") {
t.Fatalf("users's is_admin column should not exists")
}
if err := DB.Table("users").AutoMigrate(&UserMigrateColumn{}); err != nil {
t.Fatalf("no error should happen when auto migrate")
}
if !DB.Migrator().HasTable("users") {
t.Fatalf("users should exists")
}
if !DB.Migrator().HasColumn("users", "is_admin") {
t.Fatalf("users's is_admin column should exists after auto migrate")
}
}