-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.go
45 lines (38 loc) · 1008 Bytes
/
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
package migrate
import (
"context"
"sort"
"github.com/clinia/x/elasticx"
)
// MigrationFunc is used to define actions to be performed for a migration.
type MigrationFunc func(ctx context.Context, engine elasticx.Engine) error
// Migration represents single engine migration.
// Migration contains:
//
// - version: migration version, must be unique in migration list
//
// - description: text description of migration
//
// - up: callback which will be called in "up" migration process
//
// - down: callback which will be called in "down" migration process for reverting changes
type Migration struct {
Version uint64
Description string
Up MigrationFunc
Down MigrationFunc
}
type Migrations []Migration
func (m Migrations) Sort() {
sort.Slice(m, func(i, j int) bool {
return m[i].Version < m[j].Version
})
}
func HasVersion(migrations []Migration, version uint64) bool {
for _, m := range migrations {
if m.Version == version {
return true
}
}
return false
}