Update db user_version within transaction

This commit is contained in:
Fedor Indutny 2024-08-13 10:52:21 -07:00 committed by GitHub
parent 36db532f31
commit 3a631a587f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 32 additions and 30 deletions

View file

@ -52,9 +52,9 @@ export function updateToSchemaVersion1000(
db.prepare(updateQuery).run(updateParams); db.prepare(updateQuery).run(updateParams);
} }
})();
db.pragma('user_version = 1000'); db.pragma('user_version = 1000');
})();
logger.info('updateToSchemaVersion1000: success!'); logger.info('updateToSchemaVersion1000: success!');
} }

View file

@ -22,6 +22,7 @@ export function updateToSchemaVersion1020(
if (ourAci == null) { if (ourAci == null) {
logger.info('updateToSchemaVersion1020: not linked'); logger.info('updateToSchemaVersion1020: not linked');
db.pragma('user_version = 1020');
return; return;
} }
@ -32,6 +33,7 @@ export function updateToSchemaVersion1020(
const ourConversationId = db.prepare(selectQuery).pluck().get(selectParams); const ourConversationId = db.prepare(selectQuery).pluck().get(selectParams);
if (ourConversationId == null) { if (ourConversationId == null) {
logger.error('updateToSchemaVersion1020: no conversation'); logger.error('updateToSchemaVersion1020: no conversation');
db.pragma('user_version = 1020');
return; return;
} }
@ -45,9 +47,9 @@ export function updateToSchemaVersion1020(
if (changes !== 0) { if (changes !== 0) {
logger.warn(`updateToSchemaVersion1020: removed ${changes} self merges`); logger.warn(`updateToSchemaVersion1020: removed ${changes} self merges`);
} }
})();
db.pragma('user_version = 1020'); db.pragma('user_version = 1020');
})();
logger.info('updateToSchemaVersion1020: success!'); logger.info('updateToSchemaVersion1020: success!');
} }

View file

@ -200,9 +200,9 @@ export function updateToSchemaVersion1040(
existingJobs.length - numTransferred existingJobs.length - numTransferred
}` }`
); );
})();
db.pragma('user_version = 1040'); db.pragma('user_version = 1040');
})();
logger.info('updateToSchemaVersion1040: success!'); logger.info('updateToSchemaVersion1040: success!');
} }

View file

@ -48,9 +48,9 @@ export function updateToSchemaVersion1060(
createdAt, sentAt, id createdAt, sentAt, id
) )
`); `);
})();
db.pragma('user_version = 1060'); db.pragma('user_version = 1060');
})();
logger.info('updateToSchemaVersion1060: success!'); logger.info('updateToSchemaVersion1060: success!');
} }

View file

@ -47,9 +47,9 @@ export function updateToSchemaVersion1070(
sizeOnBackupCdn INTEGER sizeOnBackupCdn INTEGER
) STRICT; ) STRICT;
`); `);
})();
db.pragma('user_version = 1070'); db.pragma('user_version = 1070');
})();
logger.info('updateToSchemaVersion1070: success!'); logger.info('updateToSchemaVersion1070: success!');
} }

View file

@ -23,9 +23,9 @@ export function updateToSchemaVersion1080(
conversationId, isAddressableMessage, received_at, sent_at conversationId, isAddressableMessage, received_at, sent_at
) WHERE expireTimer IS NULL; ) WHERE expireTimer IS NULL;
`); `);
})();
db.pragma('user_version = 1080'); db.pragma('user_version = 1080');
})();
logger.info('updateToSchemaVersion1080: success!'); logger.info('updateToSchemaVersion1080: success!');
} }

View file

@ -24,9 +24,9 @@ export function updateToSchemaVersion1090(
CREATE INDEX storyReads_storyId CREATE INDEX storyReads_storyId
ON storyReads (storyId); ON storyReads (storyId);
`); `);
})();
db.pragma('user_version = 1090'); db.pragma('user_version = 1090');
})();
logger.info('updateToSchemaVersion1090: success!'); logger.info('updateToSchemaVersion1090: success!');
} }

View file

@ -55,9 +55,9 @@ export function updateToSchemaVersion1100(
`; `;
db.exec(query); db.exec(query);
})();
db.pragma('user_version = 1100'); db.pragma('user_version = 1100');
})();
logger.info('updateToSchemaVersion1100: success!'); logger.info('updateToSchemaVersion1100: success!');
} }

View file

@ -27,9 +27,9 @@ export function updateToSchemaVersion1110(
ALTER TABLE stickers ALTER TABLE stickers
ADD COLUMN size INTEGER; ADD COLUMN size INTEGER;
`); `);
})();
db.pragma('user_version = 1110'); db.pragma('user_version = 1110');
})();
logger.info('updateToSchemaVersion1110: success!'); logger.info('updateToSchemaVersion1110: success!');
} }

View file

@ -25,9 +25,9 @@ export function updateToSchemaVersion1120(
CREATE INDEX mentions_messageId CREATE INDEX mentions_messageId
ON mentions(messageId); ON mentions(messageId);
`); `);
})();
db.pragma('user_version = 1120'); db.pragma('user_version = 1120');
})();
logger.info('updateToSchemaVersion1120: success!'); logger.info('updateToSchemaVersion1120: success!');
} }

View file

@ -23,9 +23,9 @@ export function updateToSchemaVersion1130(
ON messages(received_at, sent_at) ON messages(received_at, sent_at)
WHERE isStory = 1; WHERE isStory = 1;
`); `);
})();
db.pragma('user_version = 1130'); db.pragma('user_version = 1130');
})();
logger.info('updateToSchemaVersion1130: success!'); logger.info('updateToSchemaVersion1130: success!');
} }

View file

@ -24,8 +24,8 @@ export function updateToSchemaVersion1140(
CREATE INDEX callLinks_deleted CREATE INDEX callLinks_deleted
ON callLinks (deleted, roomId); ON callLinks (deleted, roomId);
`); `);
})();
db.pragma('user_version = 1140'); db.pragma('user_version = 1140');
})();
logger.info('updateToSchemaVersion1140: success!'); logger.info('updateToSchemaVersion1140: success!');
} }

View file

@ -41,9 +41,9 @@ export function updateToSchemaVersion920(
); );
logger.info('updateToSchemaVersion920: Done with deletions'); logger.info('updateToSchemaVersion920: Done with deletions');
})();
db.pragma('user_version = 920'); db.pragma('user_version = 920');
})();
logger.info( logger.info(
'updateToSchemaVersion920: user_version set to 920. Starting vacuum...' 'updateToSchemaVersion920: user_version set to 920. Starting vacuum...'

View file

@ -24,9 +24,9 @@ export function updateToSchemaVersion980(
ON reactions ON reactions
(fromId, timestamp); (fromId, timestamp);
`); `);
})();
db.pragma('user_version = 980'); db.pragma('user_version = 980');
})();
logger.info('updateToSchemaVersion980: success!'); logger.info('updateToSchemaVersion980: success!');
} }

View file

@ -37,9 +37,9 @@ export function updateToSchemaVersion990(
-- to do anything if the field wasn't present. -- to do anything if the field wasn't present.
WHERE json ->> '$.notSharingPhoneNumber' IS NOT NULL; WHERE json ->> '$.notSharingPhoneNumber' IS NOT NULL;
`); `);
})();
db.pragma('user_version = 990'); db.pragma('user_version = 990');
})();
logger.info('updateToSchemaVersion990: success!'); logger.info('updateToSchemaVersion990: success!');
} }