This repository has been archived on 2026-09-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
sqaffold/migrate.go
T

48 lines
885 B
Go
Raw Normal View History

2026-09-01 00:13:01 +01:00
package sqaffold
import (
"code.aneur.in/go/version"
)
func (s *Scaffold) Migrate() error {
if err := s.migrateApp("sqaffold", s.migration()); err != nil {
return Err(err)
}
for appName, migration := range s.apps {
if err := s.migrateApp(appName, migration); err != nil {
return Err(err)
}
}
return nil
}
func (s *Scaffold) migrateApp(appName string, migration version.Migration) error {
currentVersion, err := s.GetVersion(appName)
if err != nil {
return err
}
required, err := migration.Match(&version.Constraint{Gt: currentVersion})
if err != nil {
return err
}
versions, _ := required.Versions()
if len(versions) == 0 {
return nil
}
var updateVersion *version.Version
err = migration.Up(func(applied, next *version.Version) {
updateVersion = applied
})
if updateVersion != nil {
s.setVersion(appName, updateVersion)
}
return err
}