[#5618] added support to conditionally reapply migrations
This commit is contained in:
@@ -7,9 +7,10 @@ import (
|
||||
)
|
||||
|
||||
type Migration struct {
|
||||
Up func(txApp App) error
|
||||
Down func(txApp App) error
|
||||
File string
|
||||
Up func(txApp App) error
|
||||
Down func(txApp App) error
|
||||
File string
|
||||
ReapplyCondition func(txApp App, runner *MigrationsRunner, fileName string) (bool, error)
|
||||
}
|
||||
|
||||
// MigrationsList defines a list with migration definitions
|
||||
@@ -34,9 +35,27 @@ func (l *MigrationsList) Copy(list MigrationsList) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds adds an existing migration definition to the list.
|
||||
//
|
||||
// If m.File is not provided, it will try to get the name from its .go file.
|
||||
//
|
||||
// The list will be sorted automatically based on the migrations file name.
|
||||
func (l *MigrationsList) Add(m *Migration) {
|
||||
if m.File == "" {
|
||||
_, path, _, _ := runtime.Caller(1)
|
||||
m.File = filepath.Base(path)
|
||||
}
|
||||
|
||||
l.list = append(l.list, m)
|
||||
|
||||
sort.SliceStable(l.list, func(i int, j int) bool {
|
||||
return l.list[i].File < l.list[j].File
|
||||
})
|
||||
}
|
||||
|
||||
// Register adds new migration definition to the list.
|
||||
//
|
||||
// If `optFilename` is not provided, it will try to get the name from its .go file.
|
||||
// If optFilename is not provided, it will try to get the name from its .go file.
|
||||
//
|
||||
// The list will be sorted automatically based on the migrations file name.
|
||||
func (l *MigrationsList) Register(
|
||||
|
||||
Reference in New Issue
Block a user