forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.go
91 lines (77 loc) · 2.74 KB
/
migration.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package pop
import (
"fmt"
"log"
"path/filepath"
"runtime"
"time"
"github.com/gobuffalo/makr"
"github.com/pkg/errors"
)
// MigrationCreate writes contents for a given migration in normalized files
func MigrationCreate(path, name, ext string, up, down []byte) error {
g := makr.New()
n := time.Now().UTC()
s := n.Format("20060102150405")
upf := filepath.Join(path, (fmt.Sprintf("%s_%s.up.%s", s, name, ext)))
g.Add(makr.NewFile(upf, string(up)))
downf := filepath.Join(path, (fmt.Sprintf("%s_%s.down.%s", s, name, ext)))
g.Add(makr.NewFile(downf, string(down)))
return g.Run(".", makr.Data{})
}
// MigrateUp is deprecated, and will be removed in a future version. Use FileMigrator#Up instead.
func (c *Connection) MigrateUp(path string) error {
warningMsg := "Connection#MigrateUp is deprecated, and will be removed in a future version. Use FileMigrator#Up instead."
_, file, no, ok := runtime.Caller(1)
if ok {
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
}
log.Println(warningMsg)
mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
}
return mig.Up()
}
// MigrateDown is deprecated, and will be removed in a future version. Use FileMigrator#Down instead.
func (c *Connection) MigrateDown(path string, step int) error {
warningMsg := "Connection#MigrateDown is deprecated, and will be removed in a future version. Use FileMigrator#Down instead."
_, file, no, ok := runtime.Caller(1)
if ok {
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
}
log.Println(warningMsg)
mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
}
return mig.Down(step)
}
// MigrateStatus is deprecated, and will be removed in a future version. Use FileMigrator#Status instead.
func (c *Connection) MigrateStatus(path string) error {
warningMsg := "Connection#MigrateStatus is deprecated, and will be removed in a future version. Use FileMigrator#Status instead."
_, file, no, ok := runtime.Caller(1)
if ok {
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
}
log.Println(warningMsg)
mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
}
return mig.Status()
}
// MigrateReset is deprecated, and will be removed in a future version. Use FileMigrator#Reset instead.
func (c *Connection) MigrateReset(path string) error {
warningMsg := "Connection#MigrateReset is deprecated, and will be removed in a future version. Use FileMigrator#Reset instead."
_, file, no, ok := runtime.Caller(1)
if ok {
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
}
log.Println(warningMsg)
mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
}
return mig.Reset()
}