Only migrate if current version is higher (#349)
This commit is contained in:
parent
a3cfde1950
commit
2d046181b0
|
@ -30,11 +30,11 @@ public final class DefaultUpgradeManagerStrategy: UpgradeManagerStrategy {
|
|||
public init() {
|
||||
}
|
||||
|
||||
public func doMigrateStore(_ store: KeyValueStore, lastVersion: String?) {
|
||||
if let lastVersion {
|
||||
pp_log.debug("Upgrade from \(lastVersion)")
|
||||
} else {
|
||||
public func doMigrate(store: KeyValueStore, lastVersion: String?) {
|
||||
guard let lastVersion else {
|
||||
pp_log.debug("Fresh install")
|
||||
return
|
||||
}
|
||||
pp_log.debug("Upgrade from \(lastVersion)")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,10 +47,11 @@ public final class UpgradeManager: ObservableObject {
|
|||
self.strategy = strategy
|
||||
}
|
||||
|
||||
public func doMigrations(_ profileManager: ProfileManager) {
|
||||
strategy.doMigrateStore(store, lastVersion: lastVersion)
|
||||
lastVersion = Constants.Global.appVersionNumber
|
||||
|
||||
public func doMigrations(toVersion currentVersion: String, profileManager: ProfileManager) {
|
||||
if let lastVersion, currentVersion > lastVersion {
|
||||
strategy.doMigrate(store: store, lastVersion: lastVersion)
|
||||
}
|
||||
lastVersion = currentVersion
|
||||
isDoingMigrations = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,5 +27,5 @@ import Foundation
|
|||
import PassepartoutCore
|
||||
|
||||
public protocol UpgradeManagerStrategy {
|
||||
func doMigrateStore(_ store: KeyValueStore, lastVersion: String?)
|
||||
func doMigrate(store: KeyValueStore, lastVersion: String?)
|
||||
}
|
||||
|
|
|
@ -183,7 +183,10 @@ private extension OrganizerView.ProfilesList {
|
|||
|
||||
func performMigrationsIfNeeded() {
|
||||
Task { @MainActor in
|
||||
UpgradeManager.shared.doMigrations(profileManager)
|
||||
UpgradeManager.shared.doMigrations(
|
||||
toVersion: Constants.Global.appVersionNumber,
|
||||
profileManager: profileManager
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue