forked from corverroos/truss
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmigrate_test.go
64 lines (47 loc) · 1.36 KB
/
migrate_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package truss
import (
"context"
"testing"
"github.com/luno/jettison/jtest"
"github.com/stretchr/testify/require"
)
func TestMigrateEmpty(t *testing.T) {
ConnectForTesting(t)
}
func TestMigrateBasic(t *testing.T) {
ql := []string{
"CREATE TABLE test1 (id BIGINT, name VARCHAR(255));",
"CREATE TABLE test2 (id BIGINT, name VARCHAR(255), PRIMARY KEY(id));",
"CREATE TABLE test3 (id TINYINT, name CHAR(3), PRIMARY KEY(id));",
}
dbc1 := ConnectForTesting(t, ql...)
ctx := context.Background()
ml1, err := listMigrations(ctx, dbc1)
jtest.RequireNil(t, err)
require.Len(t, ml1, 3)
sh, err := schemaHash(ctx, dbc1)
jtest.RequireNil(t, err)
require.Equal(t, ml1[2].SchemaHash, sh)
dbc2 := ConnectForTesting(t)
for i := 0; i < len(ql); i++ {
err := Migrate(ctx, dbc2, ql[:i+1])
jtest.RequireNil(t, err)
}
ml2, err := listMigrations(ctx, dbc2)
jtest.RequireNil(t, err)
require.Len(t, ml2, 3)
require.Equal(t, ml1[2].SchemaHash, ml2[2].SchemaHash)
}
func TestApplyMigration(t *testing.T) {
q := "CREATE TABLE test1 (id BIGINT, name VARCHAR(255));"
dbc := ConnectForTesting(t)
ctx := context.Background()
err := applyMigration(ctx, dbc, q)
jtest.RequireNil(t, err)
ml, err := listMigrations(ctx, dbc)
jtest.RequireNil(t, err)
require.Len(t, ml, 1)
sh, err := schemaHash(ctx, dbc)
jtest.RequireNil(t, err)
require.Equal(t, ml[0].SchemaHash, sh)
}