-
Notifications
You must be signed in to change notification settings - Fork 6
/
MigrationList.go
46 lines (39 loc) · 1020 Bytes
/
MigrationList.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
package installer
import (
"database/sql"
"github.com/vit1251/golden/internal/site/utils"
"time"
)
type MigrationList struct {
Migrations []Migration
}
func NewMigrationList() *MigrationList {
return new(MigrationList)
}
func (self *MigrationList) Register(migrationTime time.Time, down func(*sql.DB) error, up func(*sql.DB) error) {
migrationName := utils.DateHelper_renderDateWithSecond(migrationTime)
self.Set(migrationName, down, up)
}
// Deprecated: Set is deprecated.
func (self *MigrationList) Set(migrationTime string, down func(*sql.DB) error, up func(*sql.DB) error) {
m := NewMigration()
m.ID = migrationTime
m.Down = down
m.Up = up
self.Migrations = append(self.Migrations, *m)
}
func (self *MigrationList) GetList() []string {
var result []string
for _, m := range self.Migrations {
result = append(result, m.ID)
}
return result
}
func (self *MigrationList) GetByKey(key string) *Migration {
for _, m := range self.Migrations {
if m.ID == key {
return &m
}
}
return nil
}