renamed db columns to camelCase

This commit is contained in:
azivner
2018-01-28 19:30:14 -05:00
parent 55d8ef7e81
commit 3b1f928fbc
58 changed files with 778 additions and 778 deletions

View File

@@ -11,33 +11,33 @@ const wrap = require('express-promise-wrap').wrap;
router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, wrap(async (req, res, next) => {
await sql.doInTransaction(async () => {
const noteIdsToDelete = await sql.getFirstColumn("SELECT note_id FROM notes WHERE is_deleted = 1");
const noteIdsToDelete = await sql.getFirstColumn("SELECT noteId FROM notes WHERE isDeleted = 1");
const noteIdsSql = noteIdsToDelete
.map(noteId => "'" + utils.sanitizeSql(noteId) + "'")
.join(', ');
await sql.execute(`DELETE FROM event_log WHERE note_id IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM event_log WHERE noteId IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM notes_history WHERE note_id IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM notes_history WHERE noteId IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM notes_image WHERE note_id IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM notes_image WHERE noteId IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM attributes WHERE note_id IN (${noteIdsSql})`);
await sql.execute(`DELETE FROM attributes WHERE noteId IN (${noteIdsSql})`);
await sql.execute("DELETE FROM notes_tree WHERE is_deleted = 1");
await sql.execute("DELETE FROM notes_tree WHERE isDeleted = 1");
await sql.execute("DELETE FROM notes_image WHERE is_deleted = 1");
await sql.execute("DELETE FROM notes_image WHERE isDeleted = 1");
await sql.execute("DELETE FROM images WHERE is_deleted = 1");
await sql.execute("DELETE FROM images WHERE isDeleted = 1");
await sql.execute("DELETE FROM notes WHERE is_deleted = 1");
await sql.execute("DELETE FROM notes WHERE isDeleted = 1");
await sql.execute("DELETE FROM recent_notes");
await sync_table.cleanupSyncRowsForMissingEntities("notes", "note_id");
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");
await sync_table.cleanupSyncRowsForMissingEntities("notes", "noteId");
await sync_table.cleanupSyncRowsForMissingEntities("notes_tree", "noteTreeId");
await sync_table.cleanupSyncRowsForMissingEntities("notes_history", "noteHistoryId");
await sync_table.cleanupSyncRowsForMissingEntities("recent_notes", "noteTreeId");
log.info("Following notes has been completely cleaned from database: " + noteIdsSql);
});
@@ -46,23 +46,23 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, wrap(async (req, r
}));
router.post('/cleanup-unused-images', auth.checkApiAuth, wrap(async (req, res, next) => {
const sourceId = req.headers.source_id;
const sourceId = req.headers.sourceId;
await sql.doInTransaction(async () => {
const unusedImageIds = await sql.getFirstColumn(`
SELECT images.image_id
SELECT images.imageId
FROM images
LEFT JOIN notes_image ON notes_image.image_id = images.image_id AND notes_image.is_deleted = 0
LEFT JOIN notes_image ON notes_image.imageId = images.imageId AND notes_image.isDeleted = 0
WHERE
images.is_deleted = 0
AND notes_image.note_image_id IS NULL`);
images.isDeleted = 0
AND notes_image.noteImageId IS NULL`);
const now = utils.nowDate();
for (const imageId of unusedImageIds) {
log.info(`Deleting unused image: ${imageId}`);
await sql.execute("UPDATE images SET is_deleted = 1, data = null, date_modified = ? WHERE image_id = ?",
await sql.execute("UPDATE images SET isDeleted = 1, data = null, dateModified = ? WHERE imageId = ?",
[now, imageId]);
await sync_table.addImageSync(imageId, sourceId);