Clear old conversation merges on Note to Self
This commit is contained in:
parent
6e2d5dc516
commit
ddb201b9ae
3 changed files with 143 additions and 2 deletions
54
ts/sql/migrations/1020-self-merges.ts
Normal file
54
ts/sql/migrations/1020-self-merges.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import { sql } from '../util';
|
||||
import { getOurUuid } from './41-uuid-keys';
|
||||
|
||||
export const version = 1020;
|
||||
|
||||
export function updateToSchemaVersion1020(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1020) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
const ourAci = getOurUuid(db);
|
||||
|
||||
if (ourAci == null) {
|
||||
logger.info('updateToSchemaVersion1020: not linked');
|
||||
return;
|
||||
}
|
||||
|
||||
const [selectQuery, selectParams] = sql`
|
||||
SELECT id FROM conversations
|
||||
WHERE serviceId IS ${ourAci}
|
||||
`;
|
||||
const ourConversationId = db.prepare(selectQuery).pluck().get(selectParams);
|
||||
if (ourConversationId == null) {
|
||||
logger.error('updateToSchemaVersion1020: no conversation');
|
||||
return;
|
||||
}
|
||||
|
||||
const [deleteQuery, deleteParams] = sql`
|
||||
DELETE FROM messages
|
||||
WHERE
|
||||
conversationId IS ${ourConversationId} AND
|
||||
type IS 'conversation-merge'
|
||||
`;
|
||||
const { changes } = db.prepare(deleteQuery).run(deleteParams);
|
||||
if (changes !== 0) {
|
||||
logger.warn(`updateToSchemaVersion1020: removed ${changes} self merges`);
|
||||
}
|
||||
})();
|
||||
|
||||
db.pragma('user_version = 1020');
|
||||
|
||||
logger.info('updateToSchemaVersion1020: success!');
|
||||
}
|
|
@ -76,10 +76,11 @@ import { updateToSchemaVersion970 } from './970-fts5-optimize';
|
|||
import { updateToSchemaVersion980 } from './980-reaction-timestamp';
|
||||
import { updateToSchemaVersion990 } from './990-phone-number-sharing';
|
||||
import { updateToSchemaVersion1000 } from './1000-mark-unread-call-history-messages-as-unseen';
|
||||
import { updateToSchemaVersion1010 } from './1010-call-links-table';
|
||||
import {
|
||||
version as MAX_VERSION,
|
||||
updateToSchemaVersion1010,
|
||||
} from './1010-call-links-table';
|
||||
updateToSchemaVersion1020,
|
||||
} from './1020-self-merges';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2023,6 +2024,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion990,
|
||||
updateToSchemaVersion1000,
|
||||
updateToSchemaVersion1010,
|
||||
updateToSchemaVersion1020,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue