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 init() {
} }
public func doMigrateStore(_ store: KeyValueStore, lastVersion: String?) { public func doMigrate(store: KeyValueStore, lastVersion: String?) {
if let lastVersion { guard let lastVersion else {
pp_log.debug("Upgrade from \(lastVersion)")
} else {
pp_log.debug("Fresh install") 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 self.strategy = strategy
} }
public func doMigrations(_ profileManager: ProfileManager) { public func doMigrations(toVersion currentVersion: String, profileManager: ProfileManager) {
strategy.doMigrateStore(store, lastVersion: lastVersion) if let lastVersion, currentVersion > lastVersion {
lastVersion = Constants.Global.appVersionNumber strategy.doMigrate(store: store, lastVersion: lastVersion)
}
lastVersion = currentVersion
isDoingMigrations = false isDoingMigrations = false
} }
} }

View File

@ -27,5 +27,5 @@ import Foundation
import PassepartoutCore import PassepartoutCore
public protocol UpgradeManagerStrategy { 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() { func performMigrationsIfNeeded() {
Task { @MainActor in Task { @MainActor in
UpgradeManager.shared.doMigrations(profileManager) UpgradeManager.shared.doMigrations(
toVersion: Constants.Global.appVersionNumber,
profileManager: profileManager
)
} }
} }
} }