From da35ffada60281fce0d46e5a425e980d3df0af4a Mon Sep 17 00:00:00 2001 From: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Wed, 9 Aug 2023 09:33:43 -0700 Subject: [PATCH] In calls migration, skip old calls without a callId sooner --- ts/sql/migrations/87-calls-history-table.ts | 30 ++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ts/sql/migrations/87-calls-history-table.ts b/ts/sql/migrations/87-calls-history-table.ts index 23e26858c..68423d105 100644 --- a/ts/sql/migrations/87-calls-history-table.ts +++ b/ts/sql/migrations/87-calls-history-table.ts @@ -31,7 +31,7 @@ export default function updateToSchemaVersion87( db.transaction(() => { const ourUuid = getOurUuid(db); - const [modifySchema] = sql` + const [createTable] = sql` DROP TABLE IF EXISTS callsHistory; CREATE TABLE callsHistory ( @@ -58,21 +58,14 @@ export default function updateToSchemaVersion87( timestamp DESC, status ); - - DROP INDEX IF EXISTS messages_call; - - ALTER TABLE messages - DROP COLUMN callId; - ALTER TABLE messages - ADD COLUMN callId TEXT; - ALTER TABLE messages - DROP COLUMN callMode; `; - db.exec(modifySchema); + db.exec(createTable); const [selectQuery] = sql` - SELECT * FROM messages WHERE type = 'call-history'; + SELECT * FROM messages + WHERE type = 'call-history' + AND callId IS NOT NULL; -- Older messages don't have callId `; const rows = db.prepare(selectQuery).all(); @@ -202,6 +195,19 @@ export default function updateToSchemaVersion87( db.prepare(updateQuery).run(updateParams); } + const [updateMessagesTable] = sql` + DROP INDEX IF EXISTS messages_call; + + ALTER TABLE messages + DROP COLUMN callId; + ALTER TABLE messages + ADD COLUMN callId TEXT; + ALTER TABLE messages + DROP COLUMN callMode; + `; + + db.exec(updateMessagesTable); + db.pragma('user_version = 87'); })();