MCPcopy Create free account
hub / github.com/bytebase/bytebase / getSortedVersionedFiles

Function getSortedVersionedFiles

backend/migrator/migrator.go:134–168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

132}
133
134func getSortedVersionedFiles() ([]versionedFile, error) {
135 var files []versionedFile
136 if err := fs.WalkDir(migrationFS, ".", func(path string, d fs.DirEntry, err error) error {
137 if err != nil {
138 return err
139 }
140 if d.IsDir() {
141 return nil
142 }
143 if path == latestSchemaFileName {
144 return nil
145 }
146
147 v, err := getVersionFromPath(path)
148 if err != nil {
149 return err
150 }
151 files = append(files, versionedFile{
152 version: v,
153 path: path,
154 })
155 return nil
156 }); err != nil {
157 return nil, err
158 }
159 slices.SortFunc(files, func(a, b versionedFile) int {
160 if a.version.LT(*b.version) {
161 return -1
162 } else if a.version.GT(*b.version) {
163 return 1
164 }
165 return 0
166 })
167 return files, nil
168}
169
170func getVersionFromPath(path string) (*semver.Version, error) {
171 // migration/3.5/0000##vcs.sql

Callers 3

TestLatestVersionFunction · 0.85
TestVersionUniqueFunction · 0.85
MigrateSchemaFunction · 0.85

Calls 1

getVersionFromPathFunction · 0.85

Tested by 2

TestLatestVersionFunction · 0.68
TestVersionUniqueFunction · 0.68