mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-08 11:46:25 -04:00
Centralise migrations
This commit is contained in:
parent
0bca3190fd
commit
94e552a8c6
@ -31,10 +31,7 @@ struct Kiwix: App {
|
|||||||
UNUserNotificationCenter.current().delegate = appDelegate
|
UNUserNotificationCenter.current().delegate = appDelegate
|
||||||
// MARK: - migrations
|
// MARK: - migrations
|
||||||
if !ProcessInfo.processInfo.arguments.contains("testing") {
|
if !ProcessInfo.processInfo.arguments.contains("testing") {
|
||||||
let migrations = MigrationService(migrations: [
|
_ = MigrationService().migrateAll()
|
||||||
Migrations.schemeToZIM(using: Database.shared.viewContext)
|
|
||||||
])
|
|
||||||
_ = migrations.migrateAll()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,10 +230,7 @@ struct RootView: View {
|
|||||||
}
|
}
|
||||||
// MARK: - migrations
|
// MARK: - migrations
|
||||||
if !ProcessInfo.processInfo.arguments.contains("testing") {
|
if !ProcessInfo.processInfo.arguments.contains("testing") {
|
||||||
let migrations = MigrationService(migrations: [
|
_ = MigrationService().migrateAll()
|
||||||
Migrations.schemeToZIM(using: Database.shared.viewContext)
|
|
||||||
])
|
|
||||||
_ = migrations.migrateAll()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.withHostingWindow { [windowTracker] hostWindow in
|
.withHostingWindow { [windowTracker] hostWindow in
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
enum Migrations {
|
extension Migrations {
|
||||||
|
|
||||||
/// Change the bookmarks articleURLs from "kiwix://..." to "zim://..."
|
/// Change the bookmarks articleURLs from "kiwix://..." to "zim://..."
|
||||||
/// - Parameter context: DataBase context
|
/// - Parameter context: DataBase context
|
||||||
/// - Returns: Migration - general struct
|
/// - Returns: Migration - general struct
|
||||||
|
@ -39,6 +39,10 @@ struct Migration {
|
|||||||
struct MigrationService {
|
struct MigrationService {
|
||||||
let migrations: [Migration]
|
let migrations: [Migration]
|
||||||
|
|
||||||
|
init(migrations: [Migration] = Migrations.all) {
|
||||||
|
self.migrations = migrations
|
||||||
|
}
|
||||||
|
|
||||||
func migrateAll(using userDefaults: UserDefaulting = UserDefaults.standard) -> Bool {
|
func migrateAll(using userDefaults: UserDefaulting = UserDefaults.standard) -> Bool {
|
||||||
var allSucceeded = true
|
var allSucceeded = true
|
||||||
for migration in migrations where migration.migrate(userDefaults) == false {
|
for migration in migrations where migration.migrate(userDefaults) == false {
|
||||||
|
25
Model/Migration/Migrations.swift
Normal file
25
Model/Migration/Migrations.swift
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// This file is part of Kiwix for iOS & macOS.
|
||||||
|
//
|
||||||
|
// Kiwix is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 3 of the License, or
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// Kiwix is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum Migrations {
|
||||||
|
|
||||||
|
/// A central place for all migrations
|
||||||
|
/// they will be executed in the order specified here
|
||||||
|
static let all: [Migration] = [
|
||||||
|
Self.schemeToZIM(using: Database.shared.viewContext)
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user