-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
match.go
48 lines (40 loc) · 951 Bytes
/
match.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
47
48
package pop
import (
"fmt"
)
// Match holds the information parsed from a migration filename.
type Match struct {
Version string
Name string
DBType string
Direction string
Type string
}
// ParseMigrationFilename parses a migration filename.
func ParseMigrationFilename(filename string) (*Match, error) {
matches := mrx.FindAllStringSubmatch(filename, -1)
if len(matches) == 0 {
return nil, nil
}
m := matches[0]
var dbType string
if m[3] == "" {
dbType = "all"
} else {
dbType = CanonicalDialect(m[3][1:])
if !DialectSupported(dbType) {
return nil, fmt.Errorf("unsupported dialect %s", dbType)
}
}
if m[5] == "fizz" && dbType != "all" {
return nil, fmt.Errorf("invalid database type %q, expected \"all\" because fizz is database type independent", dbType)
}
match := &Match{
Version: m[1],
Name: m[2],
DBType: dbType,
Direction: m[4],
Type: m[5],
}
return match, nil
}