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

Function getVersionFromPath

backend/migrator/migrator.go:170–192  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

168}
169
170func getVersionFromPath(path string) (*semver.Version, error) {
171 // migration/3.5/0000##vcs.sql
172 s := strings.TrimPrefix(path, "migration/")
173 splits := strings.Split(s, "/")
174 if len(splits) != 2 {
175 return nil, errors.Errorf("invalid migration path %q", path)
176 }
177 splits2 := strings.Split(splits[1], "##")
178 if len(splits2) != 2 {
179 return nil, errors.Errorf("invalid migration path %q", path)
180 }
181 patch, err := strconv.ParseInt(splits2[0], 10, 64)
182 if err != nil {
183 return nil, errors.Wrapf(err, "migration filename prefix %q should be four digits integer such as '0000'", splits2[0])
184 }
185
186 v := fmt.Sprintf("%s.%d", splits[0], patch)
187 version, err := semver.Parse(v)
188 if err != nil {
189 return nil, errors.Wrapf(err, "invalid version %q", v)
190 }
191 return &version, nil
192}
193
194func executeMigration(ctx context.Context, conn *sql.Conn, statement string, version string) error {
195 // Get current database context for error reporting

Callers 1

getSortedVersionedFilesFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected