github.com/dkishere/pop/v6@v6.103.1/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  	Direction string
    13  	Type      string
    14  }
    15  
    16  // ParseMigrationFilename parses a migration filename.
    17  func ParseMigrationFilename(filename string) (*Match, error) {
    18  
    19  	matches := mrx.FindAllStringSubmatch(filename, -1)
    20  	if len(matches) == 0 {
    21  		return nil, nil
    22  	}
    23  	m := matches[0]
    24  
    25  	var dbType string
    26  	if m[3] == "" {
    27  		dbType = "all"
    28  	} else {
    29  		dbType = normalizeSynonyms(m[3][1:])
    30  		if !DialectSupported(dbType) {
    31  			return nil, fmt.Errorf("unsupported dialect %s", dbType)
    32  		}
    33  	}
    34  
    35  	if m[5] == "fizz" && dbType != "all" {
    36  		return nil, fmt.Errorf("invalid database type %q, expected \"all\" because fizz is database type independent", dbType)
    37  	}
    38  
    39  	match := &Match{
    40  		Version:   m[1],
    41  		Name:      m[2],
    42  		DBType:    dbType,
    43  		Direction: m[4],
    44  		Type:      m[5],
    45  	}
    46  
    47  	return match, nil
    48  }