forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration_info.go
41 lines (34 loc) · 927 Bytes
/
migration_info.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
package pop
import "github.com/pkg/errors"
type Migration struct {
// Path to the migration (./migrations/123_create_widgets.up.sql)
Path string
// Version of the migration (123)
Version string
// Name of the migration (create_widgets)
Name string
// Direction of the migration (up)
Direction string
// Type of migration (sql)
Type string
// Runner function to run/execute the migration
Runner func(Migration, *Connection) error
}
// Run the migration. Returns an error if there is
// no mf.Runner defined.
func (mf Migration) Run(c *Connection) error {
if mf.Runner == nil {
return errors.Errorf("no runner defined for %s", mf.Path)
}
return mf.Runner(mf, c)
}
type Migrations []Migration
func (mfs Migrations) Len() int {
return len(mfs)
}
func (mfs Migrations) Less(i, j int) bool {
return mfs[i].Version < mfs[j].Version
}
func (mfs Migrations) Swap(i, j int) {
mfs[i], mfs[j] = mfs[j], mfs[i]
}