Only migrate if current version is higher (#349)

This commit is contained in:
Davide De Rosa 2023-09-08 22:45:04 +02:00 committed by GitHub
parent a3cfde1950
commit 2d046181b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 10 deletions

View File

@ -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)")
}
}

View File

@ -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
}
}

View File

@ -27,5 +27,5 @@ import Foundation
import PassepartoutCore
public protocol UpgradeManagerStrategy {
func doMigrateStore(_ store: KeyValueStore, lastVersion: String?)
func doMigrate(store: KeyValueStore, lastVersion: String?)
}

View File

@ -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
)
}
}
}