-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate_test.go
51 lines (43 loc) · 1.37 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
package sqlite
import (
"context"
"testing"
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/require"
)
func TestMigrate(t *testing.T) {
db, err := Open(":memory:")
require.NoError(t, err)
defer db.Close()
migrations := []Migration{
func(ctx context.Context, db *sqlx.DB) error {
_, err := db.ExecContext(ctx, "CREATE TABLE test (id INTEGER PRIMARY KEY)")
return err
},
}
require.NoError(t, Migrate(context.Background(), db, migrations))
migrations = append(migrations,
func(ctx context.Context, db *sqlx.DB) error {
_, err := db.ExecContext(ctx, "CREATE TABLE test2 (id INTEGER PRIMARY KEY)")
return err
},
)
require.NoError(t, Migrate(context.Background(), db, migrations))
require.NoError(t, Migrate(context.Background(), db, migrations))
migrations = append(migrations,
func(ctx context.Context, db *sqlx.DB) error {
_, err := db.ExecContext(ctx, "CREATE TABLE test3 (id INTEGER PRIMARY KEY)")
return err
},
func(ctx context.Context, db *sqlx.DB) error {
_, err := db.ExecContext(ctx, "CREATE TABLE test4 (id INTEGER PRIMARY KEY)")
return err
},
func(ctx context.Context, db *sqlx.DB) error {
_, err := db.ExecContext(ctx, "CREATE TABLE test5 (id INTEGER PRIMARY KEY)")
return err
},
)
require.NoError(t, Migrate(context.Background(), db, migrations))
require.NoError(t, Migrate(context.Background(), db, migrations))
}