Skip to content

Commit

Permalink
Modify create command to parse filename of assigned directory to set …
Browse files Browse the repository at this point in the history
…version properly for timestamp
  • Loading branch information
kaneshin committed Jun 14, 2020
1 parent 6aa798c commit 4abca7c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ func (s Service) walker(indexPath map[uint64]*Migration) func(string, os.FileInf
}

name := info.Name()
if s.direction != direction.Get(name) {
return nil
d := direction.Get(name)

if s.direction == direction.Unknown {

This comment has been minimized.

Copy link
@kaneshin

kaneshin Jun 14, 2020

Author Member

生成コマンドのときは Unknown パターンだったので、そのときは Up ケースのファイルネームをパースするように修正

// Collect filename of up in case of unknown direction.
if d != direction.Up {
return nil
}
} else {
// Collect filename of the same direction.
if s.direction != d {
return nil
}
}

fullname := filepath.Clean(filepath.Join(wd, path))
Expand Down Expand Up @@ -284,6 +294,8 @@ func (s *Service) NextMigration(name string) (up *Migration, down *Migration, er
v := latest.version + 1
up.version, down.version = v, v
}
_, file := filepath.Split(latest.name)
verFormat = version.Format(file)

This comment has been minimized.

Copy link
@kaneshin

kaneshin Jun 14, 2020

Author Member

verFormat が適切にパースされていなかった不具合を修正
※パースされていなくてもPrintfの仕様で問題は起きていない
ref: https://play.golang.org/p/qwtPgeCRU2F

}

// [ver]_[name]_[direction-suffix][.ext]
Expand Down
3 changes: 3 additions & 0 deletions internal/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func TestFormat(t *testing.T) {
{value: "", expected: "", message: ""},
{value: "foo", expected: "", message: ""},
{value: "foo_bar", expected: "", message: ""},
{value: "20200101150405_foo", expected: "%d", message: ""},
{value: "001_20200101150405_foo", expected: "%03d", message: ""},
{value: "999_20200101150405_foo", expected: "%d", message: ""},
}

for _, c := range candidates {
Expand Down
2 changes: 1 addition & 1 deletion kamimai.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Version represents kamimai's semantic version.
const Version = "v0.4.1"
const Version = "v0.4.2"

// Current returns the current migration version.
func Current(c *core.Config) (uint64, error) {
Expand Down

0 comments on commit 4abca7c

Please sign in to comment.