yay/pkg/settings/migrations.go
Jo 8916cd174b
refactor(yay): move cfg inside of runtime (#2259)
* rework relationship between runtime and cfg

* separate runtime from cfg

* simplify instantiation logic

* move installer to appropriate package

* move operator to sync package

* add tests for srcinfo service

* consolidate srcinfo service in sync

* add logger to srcinfo

* add logger to preparer

* remove unused text functions

* remove remaining text.* from srcinfo

* remove global logger parts

* remove global org method exports

* remove global logger

* move text->input

* add rule to prevent fmt.Print

* update golangci go version

* remove outdated FAQs

* remove outdated FAQs
2023-08-06 21:39:41 +02:00

70 lines
1.4 KiB
Go

package settings
import (
"fmt"
"github.com/Jguer/yay/v12/pkg/db"
"github.com/Jguer/yay/v12/pkg/text"
"github.com/leonelquinteros/gotext"
)
type configMigration interface {
// Description of what the migration does
fmt.Stringer
// return true if migration was done
Do(config *Configuration) bool
// Target version of the migration (e.g. "11.2.1")
// Should match the version of yay releasing this migration
TargetVersion() string
}
type configProviderMigration struct{}
func (migration *configProviderMigration) String() string {
return gotext.Get("Disable 'provides' setting by default")
}
func (migration *configProviderMigration) Do(config *Configuration) bool {
if config.Provides {
config.Provides = false
return true
}
return false
}
func (migration *configProviderMigration) TargetVersion() string {
return "11.2.1"
}
func DefaultMigrations() []configMigration {
return []configMigration{
&configProviderMigration{},
}
}
func (c *Configuration) RunMigrations(logger *text.Logger, migrations []configMigration,
configPath, newVersion string,
) error {
saveConfig := false
for _, migration := range migrations {
if db.VerCmp(migration.TargetVersion(), c.Version) > 0 {
if migration.Do(c) {
logger.Infoln("Config migration executed (",
migration.TargetVersion(), "):", migration)
saveConfig = true
}
}
}
if saveConfig {
return c.Save(configPath, newVersion)
}
return nil
}