Home

Awesome

Migrator

Build & Test Coverage Swift Package Manager compatible


Migrator is a versatile Swift Package designed to streamline the execution of asynchronous tasks with dependency management on all Apple platforms. It provides a robust solution for orchestrating tasks with complex dependencies, ensuring that each task is executed in the correct order, respecting the dependencies defined between them. With built-in error handling and retry capabilities, it significantly simplifies error recovery and enhances the reliability of task execution processes.

Features

Use Cases

Semantic Version 2.0.0 and Swift Macro

A standout feature of the Package is its integrated support for Semantic Versioning (SemVer 2.0.0). This functionality is encapsulated within a dedicated struct that allows you to describe, parse, compare and manipulate version numbers. The Package introduces a compile-time check through a Swift macro, enabling to validate semantic version strings directly within the Xcode environment which prevents common versioning errors before runtime.

let version1 = SemanticVersion("1.0.1")
let version2 = SemanticVersion("2.0.0-0.alpha-1")

if let version1, let version2 {
    print(version1.major)
    print(version1.minor)
    print(version1.patch)
    print(version1.prereleaseIdentifiers)
    print(version1.buildMetadataIdentifiers)
            
    print(version1 > version2)
}

or use corressponding Swift Macro to do compile time version validation

<img width="719" alt="Screenshot 2024-02-23 at 23 03 47" src="https://github.com/narek-sv/Migrator/assets/23353201/b25dbc55-ab5b-406d-8077-999adf57f6dc">

Getting Started

// Create the migrator
let migrator = Migrator()

// Then register all the tasks, providing a unique task ID, an optional app version range for execution, any dependencies on other tasks, and the number of retry attempts for the next app session in case of failure.
        
await migrator.registerTask(with: "task1",
                            from: #SemanticVersion("1.0.0"),
                            to: #SemanticVersion("3.0.0"),
                            dependencies: ["task2"],
                            task: { /* do any async throwing work something */ })
        
await migrator.registerTask(with: "task2",
                            to: #SemanticVersion("4.0.0"),
                            dependencies: ["task3"],
                            task: { /* do any async throwing work something */ })
        
await migrator.registerTask(with: "task3",
                            from: #SemanticVersion("1.0.0"),
                            maxAttempts: 3,
                            task: { /* do any async throwing work something */ })

// Finally call the start method
let results = try await migrator.start()

The start method initiates the validation of registered tasks, ensuring there are no inconsistencies. If any discrepancies are found, the following errors may be thrown:

Upon successful validation, the method proceeds to execute all tasks. Independant tasks are executed in parallel, enhancing efficiency. Upon completion, it provides detailed statuses for each task, including execution outcomes and reasons for any failures.


Supported Platforms

iOSmacOSwatchOStvOSmacCatalyst
13.0+10.15+6.0+13.0+13.0+

Installation

Swift Package Manager

Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding Migrator as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/narek-sv/Migrator.git", .upToNextMajor(from: "1.0.0"))
]

or

In any file you'd like to use KeyValueStorage in, don't forget to import the framework with import Migrator.


License

See License.md for more information.