2024-04-12 10:07:57 -07:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2025-03-12 14:45:54 -07:00
|
|
|
import type { Database } from '@signalapp/sqlcipher';
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-09-16 17:39:03 -07:00
|
|
|
import { sql, sqlFragment } from '../util.js';
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
export default function updateToSchemaVersion1030(db: Database): void {
|
|
|
|
// From migration 81
|
|
|
|
const shouldAffectActivityOrPreview = sqlFragment`
|
|
|
|
type IS NULL
|
|
|
|
OR
|
|
|
|
type NOT IN (
|
|
|
|
'change-number-notification',
|
|
|
|
'contact-removed-notification',
|
|
|
|
'conversation-merge',
|
|
|
|
'group-v1-migration',
|
|
|
|
'keychange',
|
|
|
|
'message-history-unsynced',
|
|
|
|
'profile-change',
|
|
|
|
'story',
|
|
|
|
'universal-timer-notification',
|
|
|
|
'verified-change'
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
type IS 'message-request-response-event'
|
|
|
|
AND json_extract(json, '$.messageRequestResponseEvent') IN ('ACCEPT', 'BLOCK', 'UNBLOCK')
|
|
|
|
)
|
|
|
|
`;
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
const [updateShouldAffectPreview] = sql`
|
|
|
|
--- These will be re-added below
|
|
|
|
DROP INDEX messages_preview;
|
|
|
|
DROP INDEX messages_preview_without_story;
|
|
|
|
DROP INDEX messages_activity;
|
|
|
|
DROP INDEX message_user_initiated;
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
--- These will also be re-added below
|
|
|
|
ALTER TABLE messages DROP COLUMN shouldAffectActivity;
|
|
|
|
ALTER TABLE messages DROP COLUMN shouldAffectPreview;
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
--- (change: added message-request-response-event->ACCEPT/BLOCK/UNBLOCK)
|
|
|
|
ALTER TABLE messages
|
|
|
|
ADD COLUMN shouldAffectPreview INTEGER
|
|
|
|
GENERATED ALWAYS AS (${shouldAffectActivityOrPreview});
|
|
|
|
ALTER TABLE messages
|
|
|
|
ADD COLUMN shouldAffectActivity INTEGER
|
|
|
|
GENERATED ALWAYS AS (${shouldAffectActivityOrPreview});
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
--- From migration 88
|
|
|
|
CREATE INDEX messages_preview ON messages
|
|
|
|
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther,
|
|
|
|
received_at, sent_at);
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
--- From migration 88
|
|
|
|
CREATE INDEX messages_preview_without_story ON messages
|
|
|
|
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther,
|
|
|
|
received_at, sent_at) WHERE storyId IS NULL;
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
--- From migration 88
|
|
|
|
CREATE INDEX messages_activity ON messages
|
|
|
|
(conversationId, shouldAffectActivity, isTimerChangeFromSync,
|
|
|
|
isGroupLeaveEventFromOther, received_at, sent_at);
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
--- From migration 81
|
|
|
|
CREATE INDEX message_user_initiated ON messages (conversationId, isUserInitiatedMessage);
|
|
|
|
`;
|
2024-04-12 10:07:57 -07:00
|
|
|
|
2025-08-06 10:32:08 -07:00
|
|
|
db.exec(updateShouldAffectPreview);
|
2024-04-12 10:07:57 -07:00
|
|
|
}
|