Skip to content

Commit

Permalink
Extra logging for GV2 UUID migration
Browse files Browse the repository at this point in the history
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and indutny-signal committed Nov 3, 2021
1 parent 7f9708f commit 32c1d88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions ts/sql/migrations/43-gv2-uuid.ts
Expand Up @@ -37,6 +37,7 @@ export default function updateToSchemaVersion43(

type LegacyConversationType = {
id: string;
groupId: string;
membersV2?: Array<{
conversationId: string;
}>;
Expand Down Expand Up @@ -78,6 +79,8 @@ export default function updateToSchemaVersion43(
const legacy = (convo as unknown) as LegacyConversationType;
let result = convo;

const logId = `(${legacy.id}) groupv2(${legacy.groupId})`;

const memberKeys: Array<keyof LegacyConversationType> = [
'membersV2',
'pendingMembersV2',
Expand All @@ -98,7 +101,7 @@ export default function updateToSchemaVersion43(
});
if (!uuid) {
logger.warn(
`updateToSchemaVersion43: ${legacy.id}.${key} UUID not found ` +
`updateToSchemaVersion43: ${logId}.${key} UUID not found ` +
`for ${member.conversationId}`
);
return undefined;
Expand Down Expand Up @@ -141,14 +144,14 @@ export default function updateToSchemaVersion43(
if (oldValue.length !== 0) {
logger.info(
`updateToSchemaVersion43: migrated ${oldValue.length} ${key} ` +
`entries to ${newValue.length} for ${legacy.id}`
`entries to ${newValue.length} for ${logId}`
);
}

if (addedByCount > 0) {
logger.info(
`updateToSchemaVersion43: migrated ${addedByCount} addedByUserId ` +
`in ${key} for ${legacy.id}`
`in ${key} for ${logId}`
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions ts/test-node/sql_migrations_test.ts
Expand Up @@ -626,8 +626,12 @@ describe('SQL migrations test', () => {
const UUID_B = generateGuid();
const UUID_C = generateGuid();

const rawConvoA = { id: 'a', groupId: 'gv2a', uuid: UUID_A };
const rawConvoB = { id: 'b', groupId: 'gv2b', uuid: UUID_B };

const rawConvoC = {
id: 'c',
groupId: 'gv2c',
uuid: UUID_C,
membersV2: [
{ conversationId: 'a', joinedAtVersion: 1 },
Expand Down Expand Up @@ -668,8 +672,8 @@ describe('SQL migrations test', () => {
INSERT INTO conversations
(id, uuid, json)
VALUES
('a', '${UUID_A}', '${JSON.stringify({ id: 'a', uuid: UUID_A })}'),
('b', '${UUID_B}', '${JSON.stringify({ id: 'b', uuid: UUID_B })}'),
('a', '${UUID_A}', '${JSON.stringify(rawConvoA)}'),
('b', '${UUID_B}', '${JSON.stringify(rawConvoB)}'),
('c', '${UUID_C}', '${JSON.stringify(rawConvoC)}');
INSERT INTO messages
Expand Down Expand Up @@ -714,6 +718,7 @@ describe('SQL migrations test', () => {
assert.strictEqual(members, `${UUID_A} ${UUID_B}`);
assert.deepStrictEqual(JSON.parse(convoJSON), {
id: 'c',
groupId: 'gv2c',
uuid: UUID_C,
membersV2: [
{ uuid: UUID_A, joinedAtVersion: 1 },
Expand Down

0 comments on commit 32c1d88

Please sign in to comment.