diff --git a/migrations/0053__cleanup_inconsistencies.sql b/migrations/0053__cleanup_inconsistencies.sql new file mode 100644 index 000000000..7bea5ea94 --- /dev/null +++ b/migrations/0053__cleanup_inconsistencies.sql @@ -0,0 +1,18 @@ +delete from notes where note_id in ('FfZylYxt','HqzAEsR2fFEZ','KgTQDh67+1Mh','TKMbAYl0AFyQ','W+bGM185c6gw', + 'YXBdhv4dYKMy','aF4/6p1zTpIS','nsLnrrDktl/s','wkhFImoPuxky'); + +delete from notes_tree where note_tree_id in ('TTy5N2y2S6JP','TTkL3rWDexpp','TTEhtomZekUk','TTvP7zW01zwg','TTuYmMTZyKRt' + ,'TToaClamxbBF','TTKvNCe5X2dj','TTE7jFx5A0zW','TTc79bscyrHX','TTcw8ZyDy2Cc','TTdFzAOWA9hZ','TTUyVLqyIvVg','TTy85NKSBDyO' + ,'TTCyuireAWBv','TTDpVyuzbj1a','TTYznrYvAeIs','TTocvv15VMyu','TTjtxQkBT5vj','TToyyRzbBF0T','TTFt8NE9vSyZ','TTfzFZOuuDqv' + ,'TT2e2oUYcxG6','TToXselUpPAy','TTEM68gGukg0','TTkZxxwtUOzW','TTAZNxBtgmmh','TTK1YErdBE3x','TTzjKiEf54o6','TTPWd5Ou1xET' + ,'TTxQtjf22rTL','TTJAGaI4c89V','TTUQmsxSTdV3','TTGAOf5Lvr6b','TTECSDRN4ZPW','TTZZXLiGNWv4','TTxSLphulRct','TT8vld7x0qWF' + ,'TTuuxXnv2Kpw','TT3RkLZ9AI6t','TTuEbI4Cj3qC','TT4CXXRyWRqm','TTQCuFgnMqxX','TTxnDEMz1bd4','TTMOnqhBesjs','TTHblx55gRHN' + ,'TTMHW8HIGCjR','TTxzg3qqyLjw','TTluvD7yS8Rv','TT88qK2j3ggk','TTF7oHhS5ANF','TTOH275JiUSy','TToIt2dQ5tYH','TTBPgixQgbAq' + ,'TTeN46707CJl','TTDb3GC2y6nN','TTlIXFwpICko','TTE6M9AxLh2U','TTjqhB8zXjD6','TT9NPeLg4FjK','TTj12jDX7TM3','TTPRjf7EdvDX' + ,'TTBnu09pxOmn','TTZxyAkJQ9Cf','TTlvqeof2IBS','TT5R5xtIqRQf','TTiiD6hFjlVH','TTNVjGHSqNgo','TTrORSHCsAVQ','TT5Ei5fngqkv' + ,'TTQ4hdpcIX3C','TTQgxq4CoiHU','TTJayLjI6BSE','TTYyraNy0CVT','TTnAJ3AK3wHz','TTJwKcgs1s0X','TT4FiatgbLEs','TTEdp5Zx1n5F'); + +update notes_tree set is_deleted = 1 where note_tree_id in ('TTiaU9xqnrca','TTQAy9c1vDId','TTHXWBJB2Y24','TTDV8DUK2IZA' + ,'TTI5JHODZYV5','TTBEZ8TMSJV4','TT1MDWZXE8ZI','TTJV7ZOA8907','TTUGE6N99QSO','TTN0OS17T0KM'); + +delete from notes_history where note_history_id in ('KHAp5viTrrOfugzQ', 'xmhaS76piZn0QGzn', '25aL96ke8xmud9Bt'); \ No newline at end of file diff --git a/public/javascripts/messaging.js b/public/javascripts/messaging.js index 5a81c3d71..18a655cb6 100644 --- a/public/javascripts/messaging.js +++ b/public/javascripts/messaging.js @@ -45,6 +45,9 @@ const messaging = (function() { else if (message.type === 'sync-hash-check-failed') { showError("Sync check failed!", 60000); } + else if (message.type === 'consistency-checks-failed') { + showError("Consistency checks failed! See logs for details.", 50 * 60000); + } } function connectWebSocket() { diff --git a/services/app_info.js b/services/app_info.js index cdf1e0b58..75e018439 100644 --- a/services/app_info.js +++ b/services/app_info.js @@ -3,7 +3,7 @@ const build = require('./build'); const packageJson = require('../package'); -const APP_DB_VERSION = 52; +const APP_DB_VERSION = 53; module.exports = { app_version: packageJson.version, diff --git a/services/consistency_checks.js b/services/consistency_checks.js index 163e6a017..082e78ccd 100644 --- a/services/consistency_checks.js +++ b/services/consistency_checks.js @@ -2,6 +2,7 @@ const sql = require('./sql'); const log = require('./log'); +const messaging = require('./messaging'); async function runCheck(query, errorText, errorList) { const result = await sql.getFlattenedResults(query); @@ -25,8 +26,8 @@ async function runChecks() { await runCheck("SELECT note_id FROM notes LEFT JOIN notes_tree USING(note_id) WHERE notes_tree.note_tree_id IS NULL", "Missing notes_tree records for following note IDs", errorList); - await runCheck("SELECT note_tree_id FROM notes_tree LEFT JOIN notes USING(note_id) WHERE notes.note_id IS NULL", - "Missing notes records for following note tree IDs", errorList); + await runCheck("SELECT note_tree_id || ' > ' || notes_tree.note_id FROM notes_tree LEFT JOIN notes USING(note_id) WHERE notes.note_id IS NULL", + "Missing notes records for following note tree ID > note ID", errorList); await runCheck("SELECT note_tree_id FROM notes_tree JOIN notes USING(note_id) WHERE notes.is_deleted = 1 AND notes_tree.is_deleted = 0", "Note tree is not deleted even though main note is deleted for following note tree IDs", errorList); @@ -41,13 +42,17 @@ async function runChecks() { await runMissingSyncRowCheck("notes_history", "note_history_id", errorList); await runMissingSyncRowCheck("notes_tree", "note_tree_id", errorList); await runMissingSyncRowCheck("recent_notes", "note_tree_id", errorList); + + if (errorList.length > 0) { + messaging.sendMessage({type: 'consistency-checks-failed'}); + } } sql.dbReady.then(() => { setInterval(runChecks, 60 * 60 * 1000); // kickoff backup immediately - setTimeout(runChecks, 5000); + setTimeout(runChecks, 10000); }); module.exports = {