Moved morph dependency to new repo (#19618)

```release-note
NONE
```

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
Agniva De Sarker
2022-02-23 20:11:12 +05:30
коммит произвёл GitHub
родитель 9534efe534
Коммит 2a59047d07
30 изменённых файлов: 329 добавлений и 242 удалений

58
vendor/github.com/mattermost/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/mattermost/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) + `)\.(.*)$`)