If application has many database versions it becomes hard to handle a new one. Each new version will oblidge you to re-create every migration.
Solution
Soulution is progressive migration. It consists of a series of migration. And every new database version will require only one migration - from previous to the last.
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
github "badretdinov/Progression" ~> 1.0
CodoaPods
CocoaPods is a dependency manager for Cocoa projects.
pod 'Progression', '~> 1.0'
Usage
Create database version file
First create database version file by inheritancing from RawRepresentable(String) and DBVersion, define databaseName and each db version. Note that PDatabaseVersion is CaseIterable and order of cases is very important.
Optionally you can override migrationTypes. First version can be empty because database won’t be migrated to that version.
enum DatabaseVersion: String, PDatabaseVersion {
static var databaseName = "Model"
case version1 = "MM"
case version2 = "MM2"
case version3 = "MM3"
var migrationTypes: [PDatabaseMigrationType] {
switch self {
case .version1:
return []
case .version2:
return [.named("1_2")]
case .version3:
return [.named("2_3")]
}
}
}
Models can be combined. In this case framework will use the first successfully loaded model.
var migrationTypes: [PDatabaseMigrationType] {
return [.automatic, .named("1_to_2"), .inferred)]
}
Migration types
There are 3 migration types:
Automatic. The appropriate mapping model will be loaded automatically from the bundle.
Named. The model will be loaded from the filename you provided. Please note that you shouldn’t put extension into the filename.
Inferred. The model will be created as inferred.
Migrate persistent store
And then you need to init PMigrationManager with your database version and call migration method.
Progression
Progression is the core data framework which helps you to automate CoreData migration process. It based on progressive migration approach.
Progressive migration
Problem
If application has many database versions it becomes hard to handle a new one. Each new version will oblidge you to re-create every migration.
Solution
Soulution is progressive migration. It consists of a series of migration. And every new database version will require only one migration - from previous to the last.
Requirements
Installation
Swift Package Manager
The 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 Progression as a dependency is as easy as adding it to the
dependencies
value of yourPackage.swift
.Or using
Xcode
:https://github.com/badretdinov/Progression.git
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
CodoaPods
CocoaPods is a dependency manager for Cocoa projects.
Usage
Create database version file
First create database version file by inheritancing from
RawRepresentable(String)
andDBVersion
, definedatabaseName
and each db version. Note thatPDatabaseVersion
isCaseIterable
and order of cases is very important.Optionally you can override
migrationTypes
. First version can be empty because database won’t be migrated to that version.Models can be combined. In this case framework will use the first successfully loaded model.
Migration types
There are 3 migration types:
Migrate persistent store
And then you need to init
PMigrationManager
with your database version and call migration method.Here is NSPersistentContainer container usage:
License
Progression is released under the MIT license. See LICENSE for details.