From 3a631a587f949e4a19250db975e33c567fc2fcbb Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:52:21 -0700 Subject: [PATCH] Update db user_version within transaction --- .../1000-mark-unread-call-history-messages-as-unseen.ts | 4 ++-- ts/sql/migrations/1020-self-merges.ts | 6 ++++-- ts/sql/migrations/1040-undownloaded-backed-up-media.ts | 4 ++-- .../migrations/1060-addressable-messages-and-sync-tasks.ts | 4 ++-- ts/sql/migrations/1070-attachment-backup.ts | 4 ++-- ts/sql/migrations/1080-nondisappearing-addressable.ts | 4 ++-- ts/sql/migrations/1090-message-delete-indexes.ts | 4 ++-- .../1100-optimize-mark-call-history-read-in-conversation.ts | 4 ++-- ts/sql/migrations/1110-sticker-local-key.ts | 4 ++-- ts/sql/migrations/1120-messages-foreign-keys-indexes.ts | 4 ++-- ts/sql/migrations/1130-isStory-index.ts | 4 ++-- ts/sql/migrations/1140-call-links-deleted-column.ts | 4 ++-- ts/sql/migrations/920-clean-more-keys.ts | 4 ++-- ts/sql/migrations/980-reaction-timestamp.ts | 4 ++-- ts/sql/migrations/990-phone-number-sharing.ts | 4 ++-- 15 files changed, 32 insertions(+), 30 deletions(-) diff --git a/ts/sql/migrations/1000-mark-unread-call-history-messages-as-unseen.ts b/ts/sql/migrations/1000-mark-unread-call-history-messages-as-unseen.ts index f9bef5a5f4a3..f673b5922ea3 100644 --- a/ts/sql/migrations/1000-mark-unread-call-history-messages-as-unseen.ts +++ b/ts/sql/migrations/1000-mark-unread-call-history-messages-as-unseen.ts @@ -52,9 +52,9 @@ export function updateToSchemaVersion1000( db.prepare(updateQuery).run(updateParams); } - })(); - db.pragma('user_version = 1000'); + db.pragma('user_version = 1000'); + })(); logger.info('updateToSchemaVersion1000: success!'); } diff --git a/ts/sql/migrations/1020-self-merges.ts b/ts/sql/migrations/1020-self-merges.ts index 031ccb019a5c..0ba57bc3930e 100644 --- a/ts/sql/migrations/1020-self-merges.ts +++ b/ts/sql/migrations/1020-self-merges.ts @@ -22,6 +22,7 @@ export function updateToSchemaVersion1020( if (ourAci == null) { logger.info('updateToSchemaVersion1020: not linked'); + db.pragma('user_version = 1020'); return; } @@ -32,6 +33,7 @@ export function updateToSchemaVersion1020( const ourConversationId = db.prepare(selectQuery).pluck().get(selectParams); if (ourConversationId == null) { logger.error('updateToSchemaVersion1020: no conversation'); + db.pragma('user_version = 1020'); return; } @@ -45,9 +47,9 @@ export function updateToSchemaVersion1020( if (changes !== 0) { logger.warn(`updateToSchemaVersion1020: removed ${changes} self merges`); } - })(); - db.pragma('user_version = 1020'); + db.pragma('user_version = 1020'); + })(); logger.info('updateToSchemaVersion1020: success!'); } diff --git a/ts/sql/migrations/1040-undownloaded-backed-up-media.ts b/ts/sql/migrations/1040-undownloaded-backed-up-media.ts index 77687e3cd0a4..5bad63672d8e 100644 --- a/ts/sql/migrations/1040-undownloaded-backed-up-media.ts +++ b/ts/sql/migrations/1040-undownloaded-backed-up-media.ts @@ -200,9 +200,9 @@ export function updateToSchemaVersion1040( existingJobs.length - numTransferred }` ); - })(); - db.pragma('user_version = 1040'); + db.pragma('user_version = 1040'); + })(); logger.info('updateToSchemaVersion1040: success!'); } diff --git a/ts/sql/migrations/1060-addressable-messages-and-sync-tasks.ts b/ts/sql/migrations/1060-addressable-messages-and-sync-tasks.ts index c18dc785d2db..bbcd61ef4122 100644 --- a/ts/sql/migrations/1060-addressable-messages-and-sync-tasks.ts +++ b/ts/sql/migrations/1060-addressable-messages-and-sync-tasks.ts @@ -48,9 +48,9 @@ export function updateToSchemaVersion1060( createdAt, sentAt, id ) `); - })(); - db.pragma('user_version = 1060'); + db.pragma('user_version = 1060'); + })(); logger.info('updateToSchemaVersion1060: success!'); } diff --git a/ts/sql/migrations/1070-attachment-backup.ts b/ts/sql/migrations/1070-attachment-backup.ts index ae37cee519d1..9faae2103d1d 100644 --- a/ts/sql/migrations/1070-attachment-backup.ts +++ b/ts/sql/migrations/1070-attachment-backup.ts @@ -47,9 +47,9 @@ export function updateToSchemaVersion1070( sizeOnBackupCdn INTEGER ) STRICT; `); - })(); - db.pragma('user_version = 1070'); + db.pragma('user_version = 1070'); + })(); logger.info('updateToSchemaVersion1070: success!'); } diff --git a/ts/sql/migrations/1080-nondisappearing-addressable.ts b/ts/sql/migrations/1080-nondisappearing-addressable.ts index e8702bb412c3..f04f80446b25 100644 --- a/ts/sql/migrations/1080-nondisappearing-addressable.ts +++ b/ts/sql/migrations/1080-nondisappearing-addressable.ts @@ -23,9 +23,9 @@ export function updateToSchemaVersion1080( conversationId, isAddressableMessage, received_at, sent_at ) WHERE expireTimer IS NULL; `); - })(); - db.pragma('user_version = 1080'); + db.pragma('user_version = 1080'); + })(); logger.info('updateToSchemaVersion1080: success!'); } diff --git a/ts/sql/migrations/1090-message-delete-indexes.ts b/ts/sql/migrations/1090-message-delete-indexes.ts index cb1b1aee7188..80ed30e89021 100644 --- a/ts/sql/migrations/1090-message-delete-indexes.ts +++ b/ts/sql/migrations/1090-message-delete-indexes.ts @@ -24,9 +24,9 @@ export function updateToSchemaVersion1090( CREATE INDEX storyReads_storyId ON storyReads (storyId); `); - })(); - db.pragma('user_version = 1090'); + db.pragma('user_version = 1090'); + })(); logger.info('updateToSchemaVersion1090: success!'); } diff --git a/ts/sql/migrations/1100-optimize-mark-call-history-read-in-conversation.ts b/ts/sql/migrations/1100-optimize-mark-call-history-read-in-conversation.ts index 4cbb3cb02509..53ad83feb0f2 100644 --- a/ts/sql/migrations/1100-optimize-mark-call-history-read-in-conversation.ts +++ b/ts/sql/migrations/1100-optimize-mark-call-history-read-in-conversation.ts @@ -55,9 +55,9 @@ export function updateToSchemaVersion1100( `; db.exec(query); - })(); - db.pragma('user_version = 1100'); + db.pragma('user_version = 1100'); + })(); logger.info('updateToSchemaVersion1100: success!'); } diff --git a/ts/sql/migrations/1110-sticker-local-key.ts b/ts/sql/migrations/1110-sticker-local-key.ts index a9db72535b7d..46e1d6be7261 100644 --- a/ts/sql/migrations/1110-sticker-local-key.ts +++ b/ts/sql/migrations/1110-sticker-local-key.ts @@ -27,9 +27,9 @@ export function updateToSchemaVersion1110( ALTER TABLE stickers ADD COLUMN size INTEGER; `); - })(); - db.pragma('user_version = 1110'); + db.pragma('user_version = 1110'); + })(); logger.info('updateToSchemaVersion1110: success!'); } diff --git a/ts/sql/migrations/1120-messages-foreign-keys-indexes.ts b/ts/sql/migrations/1120-messages-foreign-keys-indexes.ts index dc78f7f37dcc..58036802d966 100644 --- a/ts/sql/migrations/1120-messages-foreign-keys-indexes.ts +++ b/ts/sql/migrations/1120-messages-foreign-keys-indexes.ts @@ -25,9 +25,9 @@ export function updateToSchemaVersion1120( CREATE INDEX mentions_messageId ON mentions(messageId); `); - })(); - db.pragma('user_version = 1120'); + db.pragma('user_version = 1120'); + })(); logger.info('updateToSchemaVersion1120: success!'); } diff --git a/ts/sql/migrations/1130-isStory-index.ts b/ts/sql/migrations/1130-isStory-index.ts index 103dd6531a77..28743a8990a5 100644 --- a/ts/sql/migrations/1130-isStory-index.ts +++ b/ts/sql/migrations/1130-isStory-index.ts @@ -23,9 +23,9 @@ export function updateToSchemaVersion1130( ON messages(received_at, sent_at) WHERE isStory = 1; `); - })(); - db.pragma('user_version = 1130'); + db.pragma('user_version = 1130'); + })(); logger.info('updateToSchemaVersion1130: success!'); } diff --git a/ts/sql/migrations/1140-call-links-deleted-column.ts b/ts/sql/migrations/1140-call-links-deleted-column.ts index 528cc3137b52..943d9464cec8 100644 --- a/ts/sql/migrations/1140-call-links-deleted-column.ts +++ b/ts/sql/migrations/1140-call-links-deleted-column.ts @@ -24,8 +24,8 @@ export function updateToSchemaVersion1140( CREATE INDEX callLinks_deleted ON callLinks (deleted, roomId); `); - })(); - db.pragma('user_version = 1140'); + db.pragma('user_version = 1140'); + })(); logger.info('updateToSchemaVersion1140: success!'); } diff --git a/ts/sql/migrations/920-clean-more-keys.ts b/ts/sql/migrations/920-clean-more-keys.ts index b782161284f6..9dad04d59e2f 100644 --- a/ts/sql/migrations/920-clean-more-keys.ts +++ b/ts/sql/migrations/920-clean-more-keys.ts @@ -41,9 +41,9 @@ export function updateToSchemaVersion920( ); logger.info('updateToSchemaVersion920: Done with deletions'); - })(); - db.pragma('user_version = 920'); + db.pragma('user_version = 920'); + })(); logger.info( 'updateToSchemaVersion920: user_version set to 920. Starting vacuum...' diff --git a/ts/sql/migrations/980-reaction-timestamp.ts b/ts/sql/migrations/980-reaction-timestamp.ts index e1276c580c6c..07878ae7f1c5 100644 --- a/ts/sql/migrations/980-reaction-timestamp.ts +++ b/ts/sql/migrations/980-reaction-timestamp.ts @@ -24,9 +24,9 @@ export function updateToSchemaVersion980( ON reactions (fromId, timestamp); `); - })(); - db.pragma('user_version = 980'); + db.pragma('user_version = 980'); + })(); logger.info('updateToSchemaVersion980: success!'); } diff --git a/ts/sql/migrations/990-phone-number-sharing.ts b/ts/sql/migrations/990-phone-number-sharing.ts index 979f4f8859a3..59d4ec1fdd85 100644 --- a/ts/sql/migrations/990-phone-number-sharing.ts +++ b/ts/sql/migrations/990-phone-number-sharing.ts @@ -37,9 +37,9 @@ export function updateToSchemaVersion990( -- to do anything if the field wasn't present. WHERE json ->> '$.notSharingPhoneNumber' IS NOT NULL; `); - })(); - db.pragma('user_version = 990'); + db.pragma('user_version = 990'); + })(); logger.info('updateToSchemaVersion990: success!'); }