Summary: - Sources: Audit, Helpers, Services - Tests: StorageCatalogTests.swift - Docs: Design, Migration, Testing - Added symbols: struct MyNewKey, func setupSession, func handleReceivedContext, class SessionDelegateProxy, func session, func sessionDidBecomeInactive (+2 more) Stats: - 10 files changed, 181 insertions(+), 1 deletion(-)
1.2 KiB
1.2 KiB
LocalData Migration Guide
Overview
LocalData provides built-in support for migrating data from legacy storage locations or keys to modern StorageKey definitions.
Automatic Migration
When calling get(_:) on a key, the StorageRouter automatically:
- Checks the primary location.
- If not found, iterates through
migrationSourcesdefined on the key. - If data is found in a source:
- Unsecures it using the source's old policy.
- Re-secures it using the new key's policy.
- Stores it in the new location.
- Deletes the legacy data.
- Returns the value.
Proactive Migration (Sweep)
You can trigger a sweep of all registered keys at app launch:
try await StorageRouter.shared.registerCatalog(MyCatalog.self, migrateImmediately: true)
This iterates through all keys in the catalog and calls migrate(for:) on each, ensuring all legacy data is consolidated.
Defining Migration Sources
When defining a StorageKey, add legacy descriptors to the migrationSources array:
struct MyNewKey: StorageKey {
// ...
var migrationSources: [AnyStorageKey] {
[
.key(LegacyKey(name: "old_key_name", domain: .userDefaults(suite: nil)))
]
}
}