diff --git a/ts/node/migration/helpers/index.ts b/ts/node/migration/helpers/index.ts index fe2e15c94..b5b560289 100644 --- a/ts/node/migration/helpers/index.ts +++ b/ts/node/migration/helpers/index.ts @@ -13,9 +13,11 @@ Any helper functions that are exported from a helper file must have run checkTar /* eslint-enable max-len */ import { V31 } from './v31'; +import { V33 } from './v33'; const MIGRATION_HELPERS = { V31, + V33, }; export default MIGRATION_HELPERS; diff --git a/ts/node/migration/helpers/v33.ts b/ts/node/migration/helpers/v33.ts new file mode 100644 index 000000000..e3f7318f6 --- /dev/null +++ b/ts/node/migration/helpers/v33.ts @@ -0,0 +1,52 @@ +import * as BetterSqlite3 from '@signalapp/better-sqlite3'; +import { CONFIG_DUMP_TABLE, ConfigDumpRow } from '../../../types/sqlSharedTypes'; +import { checkTargetMigration } from '../utils'; + +const targetVersion = 33; + +function fetchUserConfigDump( + db: BetterSqlite3.Database, + version: number, + userPubkeyhex: string +): ConfigDumpRow | null { + checkTargetMigration(version, targetVersion); + + const userConfigWrapperDumps = db + .prepare( + `SELECT * FROM ${CONFIG_DUMP_TABLE} WHERE variant = $variant AND publicKey = $publicKey;` + ) + .all({ variant: 'UserConfig', publicKey: userPubkeyhex }) as Array; + + if (!userConfigWrapperDumps || !userConfigWrapperDumps.length) { + return null; + } + // we can only have one dump with the "UserConfig" variant and our pubkey + return userConfigWrapperDumps[0]; +} + +function writeUserConfigDump( + db: BetterSqlite3.Database, + version: number, + userPubkeyhex: string, + dump: Uint8Array +) { + checkTargetMigration(version, targetVersion); + + db.prepare( + `INSERT OR REPLACE INTO ${CONFIG_DUMP_TABLE} ( + publicKey, + variant, + data + ) values ( + $publicKey, + $variant, + $data + );` + ).run({ + publicKey: userPubkeyhex, + variant: 'UserConfig', + data: dump, + }); +} + +export const V33 = { fetchUserConfigDump, writeUserConfigDump }; diff --git a/ts/node/migration/sessionMigrations.ts b/ts/node/migration/sessionMigrations.ts index 570e6e395..4953abbab 100644 --- a/ts/node/migration/sessionMigrations.ts +++ b/ts/node/migration/sessionMigrations.ts @@ -12,7 +12,7 @@ import { ConversationAttributes, } from '../../models/conversationAttributes'; import { fromHexToArray } from '../../session/utils/String'; -import { CONFIG_DUMP_TABLE, ConfigDumpRow } from '../../types/sqlSharedTypes'; +import { CONFIG_DUMP_TABLE } from '../../types/sqlSharedTypes'; import { CLOSED_GROUP_V2_KEY_PAIRS_TABLE, CONVERSATIONS_TABLE, @@ -1598,41 +1598,6 @@ function updateToSessionSchemaVersion32(currentVersion: number, db: BetterSqlite console.log(`updateToSessionSchemaVersion${targetVersion}: success!`); } -function fetchUserConfigDump( - db: BetterSqlite3.Database, - userPubkeyhex: string -): ConfigDumpRow | null { - const userConfigWrapperDumps = db - .prepare( - `SELECT * FROM ${CONFIG_DUMP_TABLE} WHERE variant = $variant AND publicKey = $publicKey;` - ) - .all({ variant: 'UserConfig', publicKey: userPubkeyhex }) as Array; - - if (!userConfigWrapperDumps || !userConfigWrapperDumps.length) { - return null; - } - // we can only have one dump with the "UserConfig" variant and our pubkey - return userConfigWrapperDumps[0]; -} - -function writeUserConfigDump(db: BetterSqlite3.Database, userPubkeyhex: string, dump: Uint8Array) { - db.prepare( - `INSERT OR REPLACE INTO ${CONFIG_DUMP_TABLE} ( - publicKey, - variant, - data - ) values ( - $publicKey, - $variant, - $data - );` - ).run({ - publicKey: userPubkeyhex, - variant: 'UserConfig', - data: dump, - }); -} - function updateToSessionSchemaVersion33(currentVersion: number, db: BetterSqlite3.Database) { const targetVersion = 33; if (currentVersion >= targetVersion) { @@ -1654,7 +1619,11 @@ function updateToSessionSchemaVersion33(currentVersion: number, db: BetterSqlite const { privateEd25519, publicKeyHex } = loggedInUser.ourKeys; // Get existing config wrapper dump and update it - const userConfigWrapperDump = fetchUserConfigDump(db, publicKeyHex); + const userConfigWrapperDump = MIGRATION_HELPERS.V33.fetchUserConfigDump( + db, + targetVersion, + publicKeyHex + ); if (!userConfigWrapperDump) { writeSessionSchemaVersion(targetVersion, db); @@ -1669,7 +1638,12 @@ function updateToSessionSchemaVersion33(currentVersion: number, db: BetterSqlite if (isNil(blindedReqEnabled)) { // this change will be part of the next ConfSyncJob (one is always made on app startup) userProfileWrapper.setEnableBlindedMsgRequest(true); - writeUserConfigDump(db, publicKeyHex, userProfileWrapper.dump()); + MIGRATION_HELPERS.V33.writeUserConfigDump( + db, + targetVersion, + publicKeyHex, + userProfileWrapper.dump() + ); } blindedReqEnabled = userProfileWrapper.getEnableBlindedMsgRequest();