mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 09:18:51 +02:00
chore: cont fa16f415
This commit is contained in:
@@ -5,22 +5,18 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/common"
|
||||
"github.com/yusing/go-proxy/pkg"
|
||||
)
|
||||
|
||||
var (
|
||||
HomepageJSONConfigPathOld = filepath.Join(common.ConfigDir, ".homepage.json")
|
||||
IconListCachePathOld = filepath.Join(common.ConfigDir, ".icon_list_cache.json")
|
||||
IconCachePathOld = filepath.Join(common.ConfigDir, ".icon_cache.json")
|
||||
homepageJSONConfigPathOld = filepath.Join(common.ConfigDir, ".homepage.json")
|
||||
iconListCachePathOld = filepath.Join(common.ConfigDir, ".icon_list_cache.json")
|
||||
iconCachePathOld = filepath.Join(common.ConfigDir, ".icon_cache.json")
|
||||
)
|
||||
|
||||
func m001_move_json_data() error {
|
||||
if version.IsOlderThan(pkg.Version{Major: 0, Minor: 11, Patch: 0}) {
|
||||
return errors.Join(
|
||||
mv(HomepageJSONConfigPathOld, common.HomepageJSONConfigPath),
|
||||
mv(IconListCachePathOld, common.IconListCachePath),
|
||||
mv(IconCachePathOld, common.IconCachePath),
|
||||
)
|
||||
}
|
||||
return nil
|
||||
return errors.Join(
|
||||
mv(homepageJSONConfigPathOld, common.HomepageJSONConfigPath),
|
||||
mv(iconListCachePathOld, common.IconListCachePath),
|
||||
mv(iconCachePathOld, common.IconCachePath),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,20 +2,29 @@ package migrations
|
||||
|
||||
import (
|
||||
"github.com/yusing/go-proxy/internal/gperr"
|
||||
"github.com/yusing/go-proxy/internal/logging"
|
||||
"github.com/yusing/go-proxy/pkg"
|
||||
)
|
||||
|
||||
func RunMigrations() error {
|
||||
if currentVersion.IsEqual(lastVersion) {
|
||||
return nil
|
||||
}
|
||||
logging.Info().Msg("running migrations...")
|
||||
errs := gperr.NewBuilder("migration error")
|
||||
for _, migration := range migrations {
|
||||
if err := migration(); err != nil {
|
||||
errs.Add(err)
|
||||
for _, m := range migrations {
|
||||
if !currentVersion.IsOlderThan(m.Since) {
|
||||
continue
|
||||
}
|
||||
if err := m.Run(); err != nil {
|
||||
errs.Add(gperr.PrependSubject(m.Name, err))
|
||||
}
|
||||
}
|
||||
return errs.Error()
|
||||
}
|
||||
|
||||
var version = pkg.GetVersion()
|
||||
var migrations = []func() error{
|
||||
m001_move_json_data,
|
||||
var currentVersion = pkg.GetVersion()
|
||||
var lastVersion = pkg.GetLastVersion()
|
||||
var migrations = []migration{
|
||||
{"move json data", m001_move_json_data, pkg.Ver(0, 11, 0)},
|
||||
}
|
||||
|
||||
9
migrations/migration.go
Normal file
9
migrations/migration.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package migrations
|
||||
|
||||
import "github.com/yusing/go-proxy/pkg"
|
||||
|
||||
type migration struct {
|
||||
Name string
|
||||
Run func() error
|
||||
Since pkg.Version
|
||||
}
|
||||
@@ -6,9 +6,13 @@ import (
|
||||
)
|
||||
|
||||
func mv(old, new string) error {
|
||||
if _, err := os.Stat(old); os.IsNotExist(err) {
|
||||
_, err := os.Stat(old)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(new), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user