|
|
|
|
@ -15,6 +15,7 @@ enum PatchError: Error { |
|
|
|
|
enum Patch: String, CaseIterable { |
|
|
|
|
case alexisLeDu |
|
|
|
|
case importDataFromDevToProd |
|
|
|
|
case fixMissingMatches |
|
|
|
|
|
|
|
|
|
var id: String { |
|
|
|
|
return "padelclub.app.patch.\(self.rawValue)" |
|
|
|
|
@ -45,6 +46,7 @@ class Patcher { |
|
|
|
|
switch patch { |
|
|
|
|
case .alexisLeDu: self._patchAlexisLeDu() |
|
|
|
|
case .importDataFromDevToProd: try self._importDataFromDev() |
|
|
|
|
case .fixMissingMatches: self._patchMissingMatches() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -116,4 +118,47 @@ class Patcher { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate static func _patchMissingMatches() { |
|
|
|
|
|
|
|
|
|
guard let url = StoreCenter.main.synchronizationApiURL else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
guard url == "https://padelclub.app/roads/" else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
let services = Services(url: url) |
|
|
|
|
|
|
|
|
|
for tournament in DataStore.shared.tournaments { |
|
|
|
|
|
|
|
|
|
let store = tournament.tournamentStore |
|
|
|
|
let identifier = StoreIdentifier(value: tournament.id, parameterName: "tournament") |
|
|
|
|
|
|
|
|
|
Task { |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
// if nothing is online we upload the data |
|
|
|
|
let matches: [Match] = try await services.get(identifier: identifier) |
|
|
|
|
if matches.isEmpty { |
|
|
|
|
store.matches.insertAllIntoCurrentService() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let playerRegistrations: [PlayerRegistration] = try await services.get(identifier: identifier) |
|
|
|
|
if playerRegistrations.isEmpty { |
|
|
|
|
store.playerRegistrations.insertAllIntoCurrentService() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let teamScores: [TeamScore] = try await services.get(identifier: identifier) |
|
|
|
|
if teamScores.isEmpty { |
|
|
|
|
store.teamScores.insertAllIntoCurrentService() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|