45 lines
1.4 KiB
Swift
45 lines
1.4 KiB
Swift
//
|
||
// Migrations.swift
|
||
// pocloud
|
||
//
|
||
// Created by Patrick McDonagh on 6/6/18.
|
||
// Copyright © 2018 patrickjmcd. All rights reserved.
|
||
//
|
||
|
||
import Foundation
|
||
import RealmSwift
|
||
|
||
class Migrations {
|
||
|
||
func checkSchema() {
|
||
let config = Realm.Configuration(
|
||
// Set the new schema version. This must be greater than the previously used
|
||
// version (if you've never set a schema version before, the version is 0).
|
||
schemaVersion: 1,
|
||
|
||
// Set the block which will be called automatically when opening a Realm with
|
||
// a schema version lower than the one set above
|
||
migrationBlock: { migration, oldSchemaVersion in
|
||
// We haven’t migrated anything yet, so oldSchemaVersion == 0
|
||
print(oldSchemaVersion)
|
||
switch oldSchemaVersion {
|
||
case 1:
|
||
break
|
||
default:
|
||
// Nothing to do!
|
||
self.zeroToOne(migration: migration)
|
||
}
|
||
})
|
||
Realm.Configuration.defaultConfiguration = config
|
||
print("Migration done")
|
||
}
|
||
|
||
func zeroToOne(migration : Migration) {
|
||
print("Performing migration from 0 to 1")
|
||
migration.enumerateObjects(ofType: Company.className(), { (oldObject, newObject) in
|
||
migration.delete(oldObject!)
|
||
})
|
||
}
|
||
|
||
}
|