LocalData/Sources/LocalData/Protocols/StorageMigration.swift
Matt Bruce f3f42c7844 Update Audit, Helpers, Migrations (+4 more)
Summary:
- Sources: Audit, Helpers, Migrations, Models, Protocols (+2 more)

Stats:
- 27 files changed, 303 insertions(+), 12 deletions(-)
2026-01-18 14:53:31 -06:00

35 lines
1.5 KiB
Swift

import Foundation
/// Core migration protocol for moving data into a destination ``StorageKey``.
public protocol StorageMigration: Sendable {
/// The value type produced by the migration.
associatedtype Value: Codable & Sendable
/// The destination storage key where migrated data will be stored.
var destinationKey: StorageKey<Value> { get }
/// Determines whether the migration should run for the given context.
///
/// - Parameters:
/// - router: Storage router used to query state.
/// - context: Migration context for conditional checks.
/// - Returns: `true` when migration should proceed.
func shouldMigrate(using router: StorageRouter, context: MigrationContext) async throws -> Bool
/// Executes the migration and returns a result describing success or failure.
///
/// - Parameters:
/// - router: Storage router used to read/write values.
/// - context: Migration context for conditional checks.
/// - Returns: A ``MigrationResult`` describing the outcome.
func migrate(using router: StorageRouter, context: MigrationContext) async throws -> MigrationResult
}
/// Default behavior for storage migrations.
public extension StorageMigration {
/// Default conditional behavior that checks platform availability and existing data.
func shouldMigrate(using router: StorageRouter, context: MigrationContext) async throws -> Bool {
try await router.shouldAllowMigration(for: destinationKey, context: context)
}
}