Simplify database migrations

This commit is contained in:
Fedor Indutny 2025-08-06 10:32:08 -07:00 committed by GitHub
commit e6809c95db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
106 changed files with 4661 additions and 6814 deletions

View file

@ -3,38 +3,22 @@
import type { Database } from '@signalapp/sqlcipher';
import type { LoggerType } from '../../types/Logging';
export default function updateToSchemaVersion46(db: Database): void {
db.exec(
`
--- Add column to messages table
export default function updateToSchemaVersion46(
currentVersion: number,
db: Database,
logger: LoggerType
): void {
if (currentVersion >= 46) {
return;
}
ALTER TABLE messages
ADD COLUMN
isStory INTEGER
GENERATED ALWAYS
AS (type = 'story');
db.transaction(() => {
db.exec(
`
--- Add column to messages table
--- Update important message indices
ALTER TABLE messages
ADD COLUMN
isStory INTEGER
GENERATED ALWAYS
AS (type = 'story');
--- Update important message indices
DROP INDEX messages_conversation;
CREATE INDEX messages_conversation ON messages
(conversationId, isStory, storyId, received_at, sent_at);
`
);
db.pragma('user_version = 46');
})();
logger.info('updateToSchemaVersion46: success!');
DROP INDEX messages_conversation;
CREATE INDEX messages_conversation ON messages
(conversationId, isStory, storyId, received_at, sent_at);
`
);
}