mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-16 10:21:16 -06:00
## Summary When a server is deleted, we now update the identifiers of any locally-defined actions or complications to point to the first server. We want to avoid ever having a server identifier pointing to a deleted server so we can trust the identifiers more. ## Any other notes Deleting in this case would be bad as it's an unexpected data loss. I can imagine someone deletes and re-adds the server (potentially the last one, too), or other maintenance tasks.
30 lines
884 B
Swift
30 lines
884 B
Swift
import Foundation
|
|
import HAKit
|
|
import RealmSwift
|
|
|
|
protocol UpdatableModel {
|
|
associatedtype Source: UpdatableModelSource
|
|
|
|
static func didUpdate(objects: [Self], server: Server, realm: Realm)
|
|
static func willDelete(objects: [Self], server: Server?, realm: Realm)
|
|
|
|
static func primaryKey() -> String? // from realm, we use
|
|
static func serverIdentifierKey() -> String
|
|
static var updateEligiblePredicate: NSPredicate { get }
|
|
|
|
static func primaryKey(sourceIdentifier: String, serverIdentifier: String) -> String
|
|
func update(with object: Source, server: Server, using realm: Realm) -> Bool
|
|
}
|
|
|
|
extension UpdatableModel {
|
|
static var updateEligiblePredicate: NSPredicate { NSPredicate(value: true) }
|
|
}
|
|
|
|
protocol UpdatableModelSource {
|
|
var primaryKey: String { get }
|
|
}
|
|
|
|
extension HAEntity: UpdatableModelSource {
|
|
var primaryKey: String { entityId }
|
|
}
|