signal-desktop/ts/sql/migrations/90-delete-story-reply-screenshot.ts

35 lines
1,019 B
TypeScript
Raw Normal View History

2023-08-21 15:36:58 -04:00
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2025-03-12 14:45:54 -07:00
import type { Database } from '@signalapp/sqlcipher';
2023-08-21 15:36:58 -04:00
import type { LoggerType } from '../../types/Logging.js';
import { sql } from '../util.js';
2023-08-21 15:36:58 -04:00
export default function updateToSchemaVersion90(
db: Database,
logger: LoggerType
): void {
let numChanges = 0;
2025-08-06 10:32:08 -07:00
const [updateQuery, updateParams] = sql`
UPDATE messages
SET json = json_remove(json, '$.storyReplyContext.attachment.screenshotData')
WHERE isStory = 0
2023-08-21 15:36:58 -04:00
2025-08-06 10:32:08 -07:00
/* we want to find all messages with a non-null storyId, but using string
comparison (instead of a non-null check) here causes Sqlite to use the
storyId index */
AND storyId > '0'
2023-08-21 15:36:58 -04:00
2025-08-06 10:32:08 -07:00
AND json->'$.storyReplyContext.attachment.screenshotData' IS NOT NULL;
`;
2023-08-21 15:36:58 -04:00
2025-08-06 10:32:08 -07:00
const info = db.prepare(updateQuery).run(updateParams);
numChanges = info.changes;
2023-08-21 15:36:58 -04:00
logger.info(
2025-08-06 10:32:08 -07:00
`removed screenshotData from ${numChanges} ` +
2023-08-21 15:36:58 -04:00
`message${numChanges > 1 ? 's' : ''}`
);
}