Fix legacy call-history messages without a callId

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
Jamie Kyle 2023-08-16 17:11:09 -07:00 committed by Jamie Kyle
parent 6f0401b847
commit ef0a3de636
17 changed files with 831 additions and 426 deletions

View file

@ -17,9 +17,6 @@ import { objectToJSON, sql, sqlJoin } from '../../sql/util';
import { BodyRange } from '../../types/BodyRange';
import type { AciString } from '../../types/ServiceId';
import { generateAci } from '../../types/ServiceId';
import { callHistoryDetailsSchema } from '../../types/CallDisposition';
import { CallMode } from '../../types/Calling';
import type { MessageAttributesType } from '../../model-types.d';
import { updateToVersion } from './helpers';
const OUR_UUID = generateGuid();
@ -3565,162 +3562,4 @@ describe('SQL migrations test', () => {
);
});
});
describe('updateToSchemaVersion87', () => {
it('pulls out call history messages into the new table', () => {
updateToVersion(db, 86);
const message1Id = generateGuid();
const message2Id = generateGuid();
const conversationId = generateGuid();
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- using old types
const message1: MessageAttributesType & { callHistoryDetails: any } = {
id: message1Id,
type: 'call-history',
conversationId,
sent_at: Date.now() - 10,
received_at: Date.now() - 10,
timestamp: Date.now() - 10,
callHistoryDetails: {
callId: '123',
callMode: CallMode.Direct,
wasDeclined: false,
wasDeleted: false,
wasIncoming: false,
wasVideoCall: false,
acceptedTime: Date.now(),
endedTime: undefined,
},
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- using old types
const message2: MessageAttributesType & { callHistoryDetails: any } = {
id: message2Id,
type: 'call-history',
conversationId,
sent_at: Date.now(),
received_at: Date.now(),
timestamp: Date.now(),
callHistoryDetails: {
callMode: CallMode.Group,
creatorUuid: generateGuid(),
eraId: (0x123).toString(16),
startedTime: Date.now(),
},
};
const [insertQuery, insertParams] = sql`
INSERT INTO messages (
id,
conversationId,
type,
json
)
VALUES
(
${message1Id},
${conversationId},
${message1.type},
${JSON.stringify(message1)}
),
(
${message2Id},
${conversationId},
${message2.type},
${JSON.stringify(message2)}
);
`;
db.prepare(insertQuery).run(insertParams);
updateToVersion(db, 87);
const [selectHistoryQuery] = sql`
SELECT * FROM callsHistory;
`;
const rows = db.prepare(selectHistoryQuery).all();
for (const row of rows) {
callHistoryDetailsSchema.parse(row);
}
});
it('handles unique constraint violations', () => {
updateToVersion(db, 86);
const message1Id = generateGuid();
const message2Id = generateGuid();
const conversationId = generateGuid();
const callHistoryDetails = {
callId: '123',
callMode: CallMode.Direct,
wasDeclined: false,
wasDeleted: false,
wasIncoming: false,
wasVideoCall: false,
acceptedTime: Date.now(),
endedTime: undefined,
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- using old types
const message1: MessageAttributesType & { callHistoryDetails: any } = {
id: message1Id,
type: 'call-history',
conversationId,
sent_at: Date.now() - 10,
received_at: Date.now() - 10,
timestamp: Date.now() - 10,
callHistoryDetails,
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- using old types
const message2: MessageAttributesType & { callHistoryDetails: any } = {
id: message2Id,
type: 'call-history',
conversationId,
sent_at: Date.now(),
received_at: Date.now(),
timestamp: Date.now(),
callHistoryDetails,
};
const [insertQuery, insertParams] = sql`
INSERT INTO messages (
id,
conversationId,
type,
json
)
VALUES
(
${message1Id},
${conversationId},
${message1.type},
${JSON.stringify(message1)}
),
(
${message2Id},
${conversationId},
${message2.type},
${JSON.stringify(message2)}
);
`;
db.prepare(insertQuery).run(insertParams);
updateToVersion(db, 87);
const [selectHistoryQuery] = sql`
SELECT * FROM callsHistory;
`;
const rows = db.prepare(selectHistoryQuery).all();
for (const row of rows) {
callHistoryDetailsSchema.parse(row);
}
assert.strictEqual(rows.length, 1);
});
});
});