Fixed a few migration issues found when testing

pull/894/head
Morgan Pretty 11 months ago
parent bdbfe6c28e
commit d22c2cccf1

@ -79,7 +79,10 @@ enum _013_SessionUtilChanges: Migration {
}
// Insert into the new table, drop the old table and rename the new table to be the old one
let existingKeyPairs: [Row] = try Row.fetchAll(db, sql: "SELECT * FROM closedGroupKeyPair")
let existingKeyPairs: [Row] = try Row.fetchAll(db, sql: """
SELECT threadId, publicKey, secretKey, receivedTimestamp
FROM closedGroupKeyPair
""")
existingKeyPairs.forEach { row in
let threadId: String = row["threadId"]
let publicKey: Data = row["publicKey"]
@ -187,8 +190,7 @@ enum _013_SessionUtilChanges: Migration {
if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] == nil {
let threadExists: Bool? = try Bool.fetchOne(
db,
sql: "EXISTS (SELECT * FROM thread WHERE id = ?)",
arguments: [userSessionId.hexString]
sql: "SELECT EXISTS (SELECT * FROM thread WHERE id = '\(userSessionId.hexString)')"
)
if threadExists == false {

@ -77,7 +77,8 @@ enum _014_GenerateInitialUserConfigDumps: Migration {
return LibSession.hiddenPriority
}
return Int32(allThreads[userSessionId.hexString]?["pinnedPriority"] ?? 0)
let pinnedPriority: Int32? = allThreads[userSessionId.hexString]?["pinnedPriority"]
return (pinnedPriority ?? 0)
}(),
in: userProfileConfig
)
@ -155,7 +156,8 @@ enum _014_GenerateInitialUserConfigDumps: Migration {
return -1 // Hidden priority
}
return Int32(allThreads[contactId]?["pinnedPriority"] ?? 0)
let pinnedPriority: Int32? = allThreads[contactId]?["pinnedPriority"]
return (pinnedPriority ?? 0)
}(),
created: allThreads[contactId]?["creationDateTimestamp"]
)
@ -247,13 +249,16 @@ enum _014_GenerateInitialUserConfigDumps: Migration {
)
}
let markedAsUnread: Bool? = info["markedAsUnread"]
let timestampMs: Int64? = info["timestampMs"]
return LibSession.VolatileThreadInfo(
threadId: info["id"],
variant: variant,
openGroupUrlInfo: openGroupUrlInfo,
changes: [
.markedAsUnread(info["markedAsUnread"] ?? false),
.lastReadTimestampMs(info["timestampMs"] ?? 0)
.markedAsUnread(markedAsUnread ?? false),
.lastReadTimestampMs(timestampMs ?? 0)
]
)
},
@ -379,6 +384,7 @@ enum _014_GenerateInitialUserConfigDumps: Migration {
try LibSession.upsert(
communities: communityInfo.compactMap { info in
let threadId: String = info["threadId"]
let pinnedPriority: Int32? = allThreads[threadId]?["pinnedPriority"]
return LibSession.CommunityInfo(
urlInfo: LibSession.OpenGroupUrlInfo(
@ -387,7 +393,7 @@ enum _014_GenerateInitialUserConfigDumps: Migration {
roomToken: info["roomToken"],
publicKey: info["publicKey"]
),
priority: Int32(allThreads[threadId]?["pinnedPriority"] ?? 0)
priority: (pinnedPriority ?? 0)
)
},
in: userGroupsConfig

@ -132,7 +132,7 @@ enum _022_GroupsRebuildChanges: Migration {
)
VALUES (
'\(group.groupSessionId)',
\(group.name),
'\(group.name)',
\(group.joinedAt),
\(group.invited == false),
?,

@ -13,7 +13,10 @@ enum _007_SplitSnodeReceivedMessageInfo: Migration {
static func migrate(_ db: Database, using dependencies: Dependencies) throws {
/// Fetch the existing values and then drop the table
let existingValues: [Row] = try Row.fetchAll(db, sql: "SELECT * FROM snodeReceivedMessageInfo")
let existingValues: [Row] = try Row.fetchAll(db, sql: """
SELECT key, hash, expirationDateMs, wasDeletedOrInvalid
FROM snodeReceivedMessageInfo
""")
try db.drop(table: "snodeReceivedMessageInfo")
/// Create the new table
@ -93,6 +96,7 @@ enum _007_SplitSnodeReceivedMessageInfo: Migration {
return (Int(swarmPublicKeySplitComponents[1]) ?? SnodeAPI.Namespace.default.rawValue)
}()
let wasDeletedOrInvalid: Bool? = info["wasDeletedOrInvalid"]
return (
swarmPublicKey,
@ -100,7 +104,7 @@ enum _007_SplitSnodeReceivedMessageInfo: Migration {
targetNamespace,
info["hash"],
info["expirationDateMs"],
(info["wasDeletedOrInvalid"] == true)
(wasDeletedOrInvalid == true)
)
}

Loading…
Cancel
Save