LocalData/Sources/LocalData/Utilities/MigrationUtils.swift
Matt Bruce ac486a38bc Update Audit, Configuration, Migrations (+4 more)
Summary:
- Sources: Audit, Configuration, Migrations, Models, Protocols (+2 more)

Stats:
- 37 files changed, 256 insertions(+), 22 deletions(-)
2026-01-18 14:53:30 -06:00

30 lines
1.1 KiB
Swift

import Foundation
/// Utilities for common migration operations.
public enum MigrationUtils {
/// Returns `true` if a value can be transformed between the given types.
public static func canTransform<T, U>(from: T.Type, to: U.Type) -> Bool {
if T.self is U.Type { return true }
return T.self == String.self || U.self == String.self
}
/// Estimates the size of a data payload in bytes.
public static func estimatedSize(for data: Data) -> UInt64 {
UInt64(data.count)
}
/// Validates that source and destination descriptors are compatible.
public static func validateCompatibility(
source: StorageKeyDescriptor,
destination: StorageKeyDescriptor
) throws {
if source.name == destination.name && source.domain == destination.domain {
throw MigrationError.validationFailed("Source and destination are identical")
}
if source.valueType != destination.valueType {
throw MigrationError.incompatibleTypes("\(source.valueType) -> \(destination.valueType)")
}
}
}