mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-08-03 12:37:15 -04:00
Centralise migrations
This commit is contained in:
parent
0bca3190fd
commit
94e552a8c6
@ -31,10 +31,7 @@ struct Kiwix: App {
|
||||
UNUserNotificationCenter.current().delegate = appDelegate
|
||||
// MARK: - migrations
|
||||
if !ProcessInfo.processInfo.arguments.contains("testing") {
|
||||
let migrations = MigrationService(migrations: [
|
||||
Migrations.schemeToZIM(using: Database.shared.viewContext)
|
||||
])
|
||||
_ = migrations.migrateAll()
|
||||
_ = MigrationService().migrateAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,10 +230,7 @@ struct RootView: View {
|
||||
}
|
||||
// MARK: - migrations
|
||||
if !ProcessInfo.processInfo.arguments.contains("testing") {
|
||||
let migrations = MigrationService(migrations: [
|
||||
Migrations.schemeToZIM(using: Database.shared.viewContext)
|
||||
])
|
||||
_ = migrations.migrateAll()
|
||||
_ = MigrationService().migrateAll()
|
||||
}
|
||||
}
|
||||
.withHostingWindow { [windowTracker] hostWindow in
|
||||
|
@ -16,8 +16,7 @@
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
enum Migrations {
|
||||
|
||||
extension Migrations {
|
||||
/// Change the bookmarks articleURLs from "kiwix://..." to "zim://..."
|
||||
/// - Parameter context: DataBase context
|
||||
/// - Returns: Migration - general struct
|
||||
|
@ -39,6 +39,10 @@ struct Migration {
|
||||
struct MigrationService {
|
||||
let migrations: [Migration]
|
||||
|
||||
init(migrations: [Migration] = Migrations.all) {
|
||||
self.migrations = migrations
|
||||
}
|
||||
|
||||
func migrateAll(using userDefaults: UserDefaulting = UserDefaults.standard) -> Bool {
|
||||
var allSucceeded = true
|
||||
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