added demo document SQL scripts

This commit is contained in:
azivner
2017-12-23 13:16:18 -05:00
parent 8bc12a2654
commit cf8334607e
7 changed files with 182 additions and 58 deletions

View File

@@ -6,6 +6,7 @@ const sql = require('../../services/sql');
const utils = require('../../services/utils');
const sync_table = require('../../services/sync_table');
const auth = require('../../services/auth');
const log = require('../../services/log');
router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, next) => {
await sql.doInTransaction(async () => {
@@ -14,8 +15,6 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, n
.map(noteId => "'" + utils.sanitizeSql(noteId) + "'")
.join(', ');
console.log("Note IDS for deletion", noteIdsSql);
await sql.execute(`DELETE FROM event_log WHERE note_id IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM notes_history WHERE note_id IN (${noteIdsSql})`);
@@ -30,6 +29,8 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, n
await sync_table.cleanupSyncRowsForMissingEntities("notes_tree", "note_tree_id");
await sync_table.cleanupSyncRowsForMissingEntities("notes_history", "note_history_id");
await sync_table.cleanupSyncRowsForMissingEntities("recent_notes", "note_tree_id");
log.info("Following notes has been completely cleaned from database: " + noteIdsSql);
});
res.send({});
@@ -38,6 +39,8 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, n
router.post('/vacuum-database', auth.checkApiAuth, async (req, res, next) => {
await sql.execute("VACUUM");
log.info("Database has been vacuumed.");
res.send({});
});