Refactoring
This commit is contained in:
parent
2c9a69f8f6
commit
40d266ad26
|
@ -25,7 +25,7 @@ public struct ContentDatabase {
|
|||
databaseWriter = try DatabasePool(path: path, configuration: configuration)
|
||||
}
|
||||
|
||||
try migrate()
|
||||
try migrator.migrate(databaseWriter)
|
||||
clean()
|
||||
}
|
||||
}
|
||||
|
@ -278,8 +278,7 @@ private extension ContentDatabase {
|
|||
try FileManager.default.databaseDirectoryURL(name: identityID.uuidString)
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func migrate() throws {
|
||||
private var migrator: DatabaseMigrator {
|
||||
var migrator = DatabaseMigrator()
|
||||
|
||||
migrator.registerMigration("0.1.0") { db in
|
||||
|
@ -393,7 +392,7 @@ private extension ContentDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
try migrator.migrate(databaseWriter)
|
||||
return migrator
|
||||
}
|
||||
|
||||
func clean() {
|
||||
|
|
|
@ -28,7 +28,7 @@ public struct IdentityDatabase {
|
|||
databaseWriter = try DatabasePool(path: path, configuration: configuration)
|
||||
}
|
||||
|
||||
try migrate()
|
||||
try migrator.migrate(databaseWriter)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ public extension IdentityDatabase {
|
|||
}
|
||||
|
||||
private extension IdentityDatabase {
|
||||
static let name = "Identity"
|
||||
static let name = "identity"
|
||||
|
||||
static func writePreferences(_ preferences: Identity.Preferences, id: UUID) -> (Database) throws -> Void {
|
||||
{
|
||||
|
@ -226,10 +226,10 @@ private extension IdentityDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
func migrate() throws {
|
||||
private var migrator: DatabaseMigrator {
|
||||
var migrator = DatabaseMigrator()
|
||||
|
||||
migrator.registerMigration("createIdentities") { db in
|
||||
migrator.registerMigration("0.1.0") { db in
|
||||
try db.create(table: "instance", ifNotExists: true) { t in
|
||||
t.column("uri", .text).notNull().primaryKey(onConflict: .replace)
|
||||
t.column("streamingAPI", .text)
|
||||
|
@ -265,6 +265,6 @@ private extension IdentityDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
try migrator.migrate(databaseWriter)
|
||||
return migrator
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue