github.com/friesencr/pop/v6@v6.1.6/match.go (about)

     1  package pop
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // Match holds the information parsed from a migration filename.
     8  type Match struct {
     9  	Version       string
    10  	Name          string
    11  	DBType        string
    12  	NoTransaction bool
    13  	Direction     string
    14  	Type          string
    15  }
    16  
    17  // ParseMigrationFilename parses a migration filename.
    18  func ParseMigrationFilename(filename string) (*Match, error) {
    19  
    20  	matches := mrx.FindAllStringSubmatch(filename, -1)
    21  	if len(matches) == 0 {
    22  		return nil, nil
    23  	}
    24  	m := matches[0]
    25  
    26  	var dbType string
    27  	if m[3] == "" {
    28  		dbType = "all"
    29  	} else {
    30  		dbType = CanonicalDialect(m[3][1:])
    31  		if !DialectSupported(dbType) {
    32  			return nil, fmt.Errorf("unsupported dialect %s", dbType)
    33  		}
    34  	}
    35  
    36  	if m[6] == "fizz" && dbType != "all" {
    37  		return nil, fmt.Errorf("invalid database type %q, expected \"all\" because fizz is database type independent", dbType)
    38  	}
    39  
    40  	match := &Match{
    41  		Version:       m[1],
    42  		Name:          m[2],
    43  		DBType:        dbType,
    44  		NoTransaction: m[4] == ".notx",
    45  		Direction:     m[5],
    46  		Type:          m[6],
    47  	}
    48  
    49  	return match, nil
    50  }