mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
2.1 KiB
Swift
47 lines
2.1 KiB
Swift
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
import SessionUtilitiesKit
|
|
|
|
/// This migration updates the tiemstamps added to the `Profile` in earlier migrations to be nullable (having it not null
|
|
/// results in migration issues when a user jumps between multiple versions)
|
|
enum _016_MakeBrokenProfileTimestampsNullable: Migration {
|
|
static let target: TargetMigrations.Identifier = .messagingKit
|
|
static let identifier: String = "MakeBrokenProfileTimestampsNullable"
|
|
static let minExpectedRunDuration: TimeInterval = 0.1
|
|
static var requirements: [MigrationRequirement] = [.libSessionStateLoaded]
|
|
static let fetchedTables: [(TableRecord & FetchableRecord).Type] = []
|
|
static let createdOrAlteredTables: [(TableRecord & FetchableRecord).Type] = [Profile.self]
|
|
static let droppedTables: [(TableRecord & FetchableRecord).Type] = []
|
|
|
|
static func migrate(_ db: Database, using dependencies: Dependencies) throws {
|
|
try db.create(table: "tmpProfile") { t in
|
|
t.column("id", .text)
|
|
.notNull()
|
|
.primaryKey()
|
|
t.column("name", .text).notNull()
|
|
t.column("nickname", .text)
|
|
t.column("profilePictureUrl", .text)
|
|
t.column("profilePictureFileName", .text)
|
|
t.column("profileEncryptionKey", .blob)
|
|
t.column("lastNameUpdate", .integer).defaults(to: 0)
|
|
t.column("lastProfilePictureUpdate", .integer).defaults(to: 0)
|
|
t.column("blocksCommunityMessageRequests", .boolean)
|
|
t.column("lastBlocksCommunityMessageRequests", .integer).defaults(to: 0)
|
|
}
|
|
|
|
// Insert into the new table, drop the old table and rename the new table to be the old one
|
|
try db.execute(sql: """
|
|
INSERT INTO tmpProfile
|
|
SELECT profile.*
|
|
FROM profile
|
|
""")
|
|
|
|
try db.drop(table: "profile")
|
|
try db.rename(table: "tmpProfile", to: "profile")
|
|
|
|
Storage.update(progress: 1, for: self, in: target, using: dependencies)
|
|
}
|
|
}
|