Support date-based versions

This commit is contained in:
Arturo Guzman 2017-04-13 20:57:22 -04:00
parent b83285bd59
commit d789d50bd6
2 changed files with 11 additions and 1 deletions

View File

@ -24,7 +24,7 @@ var Regex = regexp.MustCompile(`^([0-9]+)_(.*)\.(` + string(Down) + `|` + string
func Parse(raw string) (*Migration, error) { func Parse(raw string) (*Migration, error) {
m := Regex.FindStringSubmatch(raw) m := Regex.FindStringSubmatch(raw)
if len(m) == 5 { if len(m) == 5 {
versionUint64, err := strconv.ParseUint(m[1], 10, 32) versionUint64, err := strconv.ParseUint(m[1], 10, 64)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -50,6 +50,16 @@ func TestParse(t *testing.T) {
Raw: "1485385885_foobar.up.sql", Raw: "1485385885_foobar.up.sql",
}, },
}, },
{
name: "20170412214116_date_foobar.up.sql",
expectErr: nil,
expectMigration: &Migration{
Version: 20170412214116,
Identifier: "date_foobar",
Direction: Up,
Raw: "20170412214116_date_foobar.up.sql",
},
},
{ {
name: "-1_foobar.up.sql", name: "-1_foobar.up.sql",
expectErr: ErrParse, expectErr: ErrParse,