From e50f76a909bbe1cb70ae84d1d63b06386f230289 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 9 Nov 2021 18:31:41 +0100 Subject: [PATCH] Reduce amount of logging in 41st migration --- ts/sql/migrations/41-uuid-keys.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ts/sql/migrations/41-uuid-keys.ts b/ts/sql/migrations/41-uuid-keys.ts index 6a9e16bf68..199bebfd29 100644 --- a/ts/sql/migrations/41-uuid-keys.ts +++ b/ts/sql/migrations/41-uuid-keys.ts @@ -79,23 +79,23 @@ export default function updateToSchemaVersion41( return aStats.active_at - bStats.active_at; }; - const clearSessionsAndKeys = () => { + const clearSessionsAndKeys = (): number => { // ts/background.ts will ask user to relink so all that matters here is // to maintain an invariant: // // After this migration all sessions and keys are prefixed by // "uuid:". - db.exec( - ` - DELETE FROM senderKeys; - DELETE FROM sessions; - DELETE FROM signedPreKeys; - DELETE FROM preKeys; - ` - ); + const keyCount = [ + db.prepare('DELETE FROM senderKeys').run().changes, + db.prepare('DELETE FROM sessions').run().changes, + db.prepare('DELETE FROM signedPreKeys').run().changes, + db.prepare('DELETE FROM preKeys').run().changes, + ].reduce((a: number, b: number): number => a + b); assertSync(removeById(db, 'items', 'identityKey')); assertSync(removeById(db, 'items', 'registrationId')); + + return keyCount; }; const moveIdentityKeyToMap = (ourUuid: string) => { @@ -422,11 +422,14 @@ export default function updateToSchemaVersion41( const ourUuid = getOurUuid(db); if (!isValidUuid(ourUuid)) { - logger.error( - 'updateToSchemaVersion41: no uuid is available clearing sessions' - ); + const deleteCount = clearSessionsAndKeys(); - clearSessionsAndKeys(); + if (deleteCount > 0) { + logger.error( + 'updateToSchemaVersion41: no uuid is available, ' + + `erased ${deleteCount} sessions/keys` + ); + } db.pragma('user_version = 41'); return;