extra sync consistency check for extra sync rows

This commit is contained in:
azivner 2017-12-15 22:16:28 -05:00
parent 3132daa466
commit 0fbb3f08e5
4 changed files with 26 additions and 10 deletions

View File

@ -0,0 +1,13 @@
DELETE FROM recent_notes;
DELETE FROM sync;
INSERT OR IGNORE INTO sync (entity_name, entity_id, sync_date, source_id)
SELECT 'notes', note_id, strftime('%Y-%m-%dT%H:%M:%S.000Z', 'now'), 'IMPORT' FROM notes;
INSERT OR IGNORE INTO sync (entity_name, entity_id, sync_date, source_id)
SELECT 'notes_tree', note_tree_id, strftime('%Y-%m-%dT%H:%M:%S.000Z', 'now'), 'IMPORT' FROM notes_tree;
INSERT OR IGNORE INTO sync (entity_name, entity_id, sync_date, source_id)
SELECT 'notes_history', note_history_id, strftime('%Y-%m-%dT%H:%M:%S.000Z', 'now'), 'IMPORT' FROM notes_history;
UPDATE options SET opt_value = (SELECT MAX(id) FROM sync) WHERE opt_name IN ('last_synced_push', 'last_synced_pull');

View File

@ -3,7 +3,7 @@
const build = require('./build');
const packageJson = require('../package');
const APP_DB_VERSION = 55;
const APP_DB_VERSION = 56;
module.exports = {
app_version: packageJson.version,

View File

@ -15,9 +15,12 @@ async function runCheck(query, errorText, errorList) {
}
}
async function runMissingSyncRowCheck(table, key, errorList) {
await runCheck("SELECT " + key + " FROM " + table + " LEFT JOIN sync ON sync.entity_name = '" + table + "' AND entity_id = " + key + " WHERE sync.id IS NULL",
"Missing sync records for " + key + " in table " + table, errorList);
async function runSyncRowChecks(table, key, errorList) {
await runCheck(`SELECT ${key} FROM ${table} LEFT JOIN sync ON sync.entity_name = '${table}' AND entity_id = ${key} WHERE sync.id IS NULL`,
`Missing sync records for ${key} in table ${table}`, errorList);
await runCheck(`SELECT entity_id FROM sync LEFT JOIN ${table} ON entity_id = ${key} WHERE sync.entity_name = '${table}' AND ${key} IS NULL`,
`Missing ${table} records for existing sync rows`, errorList);
}
async function runChecks() {
@ -38,10 +41,10 @@ async function runChecks() {
await runCheck("SELECT note_history_id || ' > ' || notes_history.note_id FROM notes_history LEFT JOIN notes USING(note_id) WHERE notes.note_id IS NULL",
"Missing notes records for following note history ID > note ID", errorList);
await runMissingSyncRowCheck("notes", "note_id", errorList);
await runMissingSyncRowCheck("notes_history", "note_history_id", errorList);
await runMissingSyncRowCheck("notes_tree", "note_tree_id", errorList);
await runMissingSyncRowCheck("recent_notes", "note_tree_id", errorList);
await runSyncRowChecks("notes", "note_id", errorList);
await runSyncRowChecks("notes_history", "note_history_id", errorList);
await runSyncRowChecks("notes_tree", "note_tree_id", errorList);
await runSyncRowChecks("recent_notes", "note_tree_id", errorList);
if (errorList.length > 0) {
messaging.sendMessage({type: 'consistency-checks-failed'});

View File

@ -128,7 +128,7 @@ async function pullSync(syncContext) {
const resp = await syncRequest(syncContext, 'GET', "/api/sync/" + sync.entity_name + "/" + encodeURIComponent(sync.entity_id));
if (!resp || !resp.entity) {
log.error("Empty response to pull for " + sync.entity_name + ", id=" + sync.entity_id);
log.error(`Empty response to pull for sync #${sync.id} ${sync.entity_name}, id=${sync.entity_id}`);
}
else if (sync.entity_name === 'notes') {
await syncUpdate.updateNote(resp.entity, syncContext.sourceId);
@ -149,7 +149,7 @@ async function pullSync(syncContext) {
await syncUpdate.updateRecentNotes(resp, syncContext.sourceId);
}
else {
throw new Error("Unrecognized entity type " + sync.entity_name);
throw new Error(`Unrecognized entity type ${sync.entity_name} in sync #${sync.id}`);
}
await setLastSyncedPull(sync.id);