这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cli/migrate/source/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ func (f *File) Open(url string, logger *log.Logger) (source.Driver, error) {
continue // ignore files that we can't parse
}

if !nf.migrations.Append(m) {
return nil, fmt.Errorf("unable to parse file %v", fi.Name())
err = nf.migrations.Append(m)
if err != nil {
return nil, err
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions cli/migrate/source/migration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package source

import (
"fmt"
"sort"
)

Expand Down Expand Up @@ -47,23 +48,23 @@ func NewMigrations() *Migrations {
}
}

func (i *Migrations) Append(m *Migration) (ok bool) {
func (i *Migrations) Append(m *Migration) (err error) {
if m == nil {
return false
return fmt.Errorf("migration cannot be nill")
}

if i.migrations[m.Version] == nil {
i.migrations[m.Version] = make(map[Direction]*Migration)
}

// reject duplicate versions
if _, dup := i.migrations[m.Version][m.Direction]; dup {
return false
if migration, dup := i.migrations[m.Version][m.Direction]; dup {
return fmt.Errorf("found duplicate migrations for version %d\n- %s\n- %s", m.Version, m.Raw, migration.Raw)
}

i.migrations[m.Version][m.Direction] = m
i.buildIndex()
return true
return nil
}

func (i *Migrations) buildIndex() {
Expand Down