Introduce incrementMessagesMigrationAttempts query

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
Fedor Indutny 2024-08-22 11:12:00 -07:00 committed by GitHub
parent 7db33a6708
commit 67252866cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 113 additions and 14 deletions

View file

@ -445,6 +445,7 @@ export const DataWriter: ServerWritableInterface = {
migrateConversationMessages,
saveEditedMessage,
saveEditedMessages,
incrementMessagesMigrationAttempts,
removeSyncTaskById,
saveSyncTasks,
@ -6370,6 +6371,29 @@ function getMessagesNeedingUpgrade(
return rows.map(row => jsonToObject(row.json));
}
// Exported for tests
export function incrementMessagesMigrationAttempts(
db: WritableDB,
messageIds: ReadonlyArray<string>
): void {
batchMultiVarQuery(db, messageIds, (batch: ReadonlyArray<string>): void => {
const idSet = sqlJoin(batch);
const [sqlQuery, sqlParams] = sql`
UPDATE
messages
SET
json = json_set(
json,
'$.schemaMigrationAttempts',
IFNULL(json -> '$.schemaMigrationAttempts', 0) + 1
)
WHERE
id IN (${idSet})
`;
db.prepare(sqlQuery).run(sqlParams);
});
}
function getMessagesWithVisualMediaAttachments(
db: ReadableDB,
conversationId: string,