Improve DOE behavior for poll messages

This commit is contained in:
trevor-signal
2025-11-24 16:47:50 -05:00
committed by GitHub
parent 89caa70824
commit d5ca3d4631
4 changed files with 110 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { LoggerType } from '../../types/Logging.std.js';
import type { WritableDB } from '../Interface.std.js';
import { sql } from '../util.std.js';
// This migration was backported to earlier branches as 1541 and 1551
export default function updateToSchemaVersion1561(
db: WritableDB,
logger: LoggerType
): void {
const [query, params] = sql`
UPDATE messages
SET
json = json_remove(json, '$.poll'),
hasUnreadPollVotes = 0
WHERE isErased = 1 AND (
json->'poll' IS NOT NULL OR
hasUnreadPollVotes IS NOT 0
)
`;
const result = db.prepare(query).run(params);
logger.info(`Updated ${result.changes} poll messages`);
}

View File

@@ -132,6 +132,7 @@ import updateToSchemaVersion1530 from './1530-update-expiring-index.std.js';
import updateToSchemaVersion1540 from './1540-partial-expiring-index.std.js';
import updateToSchemaVersion1550 from './1550-has-link-preview.std.js';
import updateToSchemaVersion1560 from './1560-pinned-messages.std.js';
import updateToSchemaVersion1561 from './1561-cleanup-polls.std.js';
import { DataWriter } from '../Server.node.js';
@@ -1622,6 +1623,8 @@ export const SCHEMA_VERSIONS: ReadonlyArray<SchemaUpdateType> = [
{ version: 1540, update: updateToSchemaVersion1540 },
{ version: 1550, update: updateToSchemaVersion1550 },
{ version: 1560, update: updateToSchemaVersion1560 },
// 1561, 1551, and 1541 all refer to the same migration
{ version: 1561, update: updateToSchemaVersion1561 },
];
export class DBVersionFromFutureError extends Error {