|
|
|
@ -775,9 +775,7 @@ async function updateSchema(instance) {
|
|
|
|
|
await updateLokiSchema(instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const LOKI_SCHEMA_VERSIONS = [
|
|
|
|
|
updateToLokiSchemaVersion2,
|
|
|
|
|
];
|
|
|
|
|
const LOKI_SCHEMA_VERSIONS = [updateToLokiSchemaVersion2];
|
|
|
|
|
|
|
|
|
|
async function updateToLokiSchemaVersion2(currentVersion, instance) {
|
|
|
|
|
if (currentVersion >= 2) {
|
|
|
|
@ -808,7 +806,9 @@ async function updateToLokiSchemaVersion2(currentVersion, instance) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function updateLokiSchema(instance) {
|
|
|
|
|
const result = await instance.get("SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema'");
|
|
|
|
|
const result = await instance.get(
|
|
|
|
|
"SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema'"
|
|
|
|
|
);
|
|
|
|
|
if (!result) {
|
|
|
|
|
await createLokiSchemaTable(instance);
|
|
|
|
|
}
|
|
|
|
@ -818,7 +818,11 @@ async function updateLokiSchema(instance) {
|
|
|
|
|
`Current loki schema version: ${lokiSchemaVersion};`,
|
|
|
|
|
`Most recent schema version: ${LOKI_SCHEMA_VERSIONS.length};`
|
|
|
|
|
);
|
|
|
|
|
for (let index = 0, max = LOKI_SCHEMA_VERSIONS.length; index < max; index += 1) {
|
|
|
|
|
for (
|
|
|
|
|
let index = 0, max = LOKI_SCHEMA_VERSIONS.length;
|
|
|
|
|
index < max;
|
|
|
|
|
index += 1
|
|
|
|
|
) {
|
|
|
|
|
const runSchemaUpdate = LOKI_SCHEMA_VERSIONS[index];
|
|
|
|
|
|
|
|
|
|
// Yes, we really want to do this asynchronously, in order
|
|
|
|
@ -828,7 +832,9 @@ async function updateLokiSchema(instance) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getLokiSchemaVersion(instance) {
|
|
|
|
|
const result = await instance.get('SELECT version FROM loki_schema WHERE version = (SELECT MAX(version) FROM loki_schema);');
|
|
|
|
|
const result = await instance.get(
|
|
|
|
|
'SELECT version FROM loki_schema WHERE version = (SELECT MAX(version) FROM loki_schema);'
|
|
|
|
|
);
|
|
|
|
|
if (!result.version) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1237,7 +1243,10 @@ async function getPairingAuthorisation(issuerPubKey, secondaryDevicePubKey) {
|
|
|
|
|
async function createOrUpdatePairingAuthorisation(data) {
|
|
|
|
|
const { issuerPubKey, secondaryDevicePubKey, signature } = data;
|
|
|
|
|
|
|
|
|
|
const existing = await getPairingAuthorisation(issuerPubKey, secondaryDevicePubKey);
|
|
|
|
|
const existing = await getPairingAuthorisation(
|
|
|
|
|
issuerPubKey,
|
|
|
|
|
secondaryDevicePubKey
|
|
|
|
|
);
|
|
|
|
|
// prevent adding duplicate entries
|
|
|
|
|
if (existing) {
|
|
|
|
|
return;
|
|
|
|
|