forked from mattes/migrate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
migration_test.go
56 lines (47 loc) · 1.55 KB
/
migration_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
package migrate
import (
"fmt"
"io/ioutil"
"log"
"strings"
)
func ExampleNewMigration() {
// Create a dummy migration body, this is coming from the source usually.
body := ioutil.NopCloser(strings.NewReader("dumy migration that creates users table"))
// Create a new Migration that represents version 1486686016.
// Once this migration has been applied to the database, the new
// migration version will be 1486689359.
migr, err := NewMigration(body, "create_users_table", 1486686016, 1486689359)
if err != nil {
log.Fatal(err)
}
fmt.Print(migr.LogString())
// Output:
// 1486686016/u create_users_table
}
func ExampleNewMigration_nilMigration() {
// Create a new Migration that represents a NilMigration.
// Once this migration has been applied to the database, the new
// migration version will be 1486689359.
migr, err := NewMigration(nil, "", 1486686016, 1486689359)
if err != nil {
log.Fatal(err)
}
fmt.Print(migr.LogString())
// Output:
// 1486686016/u <empty>
}
func ExampleNewMigration_nilVersion() {
// Create a dummy migration body, this is coming from the source usually.
body := ioutil.NopCloser(strings.NewReader("dumy migration that deletes users table"))
// Create a new Migration that represents version 1486686016.
// This is the last available down migration, so the migration version
// will be -1, meaning NilVersion once this migration ran.
migr, err := NewMigration(body, "drop_users_table", 1486686016, -1)
if err != nil {
log.Fatal(err)
}
fmt.Print(migr.LogString())
// Output:
// 1486686016/d drop_users_table
}