mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
extra sync consistency check for extra sync rows
This commit is contained in:
parent
3132daa466
commit
0fbb3f08e5
13
migrations/0056__fill_sync_again.sql
Normal file
13
migrations/0056__fill_sync_again.sql
Normal 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');
|
@ -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,
|
||||
|
@ -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'});
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user