feat: updated migration 33 to use a new migration style to prevent typing issues with future versions of libsession
parent
b00f7283e8
commit
b556d2bc54
@ -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<ConfigDumpRow>;
|
||||||
|
|
||||||
|
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 };
|
Loading…
Reference in New Issue