Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-01-08 11:16:07 +03:00
коммит произвёл GitHub
родитель c8198fbefe
Коммит 6595b31f23
406 изменённых файлов: 16617 добавлений и 6957 удалений

58
vendor/github.com/go-morph/morph/models/migration.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,58 @@
package models
import (
"bytes"
"fmt"
"io"
"strconv"
)
type Migration struct {
Bytes io.ReadCloser
Name string
RawName string
Version uint32
Direction Direction
}
func NewMigration(migrationBytes io.ReadCloser, fileName string) (*Migration, error) {
m := Regex.FindStringSubmatch(fileName)
var (
versionUint64 uint64
direction Direction
identifier string
err error
)
if len(m) == 5 {
versionUint64, err = strconv.ParseUint(m[1], 10, 64)
if err != nil {
return nil, err
}
identifier = m[2]
direction = Direction(m[3])
} else {
return nil, fmt.Errorf("could not parse file: %s", fileName)
}
return &Migration{
Version: uint32(versionUint64),
Name: identifier,
RawName: fileName,
Bytes: migrationBytes,
Direction: direction,
}, nil
}
func (m *Migration) Query() (string, error) {
buf := new(bytes.Buffer)
if _, err := buf.ReadFrom(m.Bytes); err != nil {
return "", err
}
return buf.String(), nil
}
func (m *Migration) Close() error {
return m.Bytes.Close()
}

23
vendor/github.com/go-morph/morph/models/parse.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,23 @@
package models
import (
"fmt"
"regexp"
)
// Direction is either up or down.
type Direction string
const (
Down Direction = "down"
Up Direction = "up"
)
var (
ErrParse = fmt.Errorf("no match")
)
// Regex matches the following pattern:
// 123_name.up.ext
// 123_name.down.ext
var Regex = regexp.MustCompile(`^([0-9]+)_(.*)\.(` + string(Down) + `|` + string(Up) + `)\.(.*)$`)