fix note revision's isErased initial value after migration

This commit is contained in:
zadam 2019-11-11 23:26:46 +01:00
parent 4cda661c1b
commit 4ba7e74b58
2 changed files with 23 additions and 0 deletions

View File

@ -19,6 +19,8 @@ SELECT noteRevisionId, noteId, title, contentLength, 0, isProtected, utcDateLast
DROP TABLE note_revisions; DROP TABLE note_revisions;
ALTER TABLE note_revisions_mig RENAME TO note_revisions; ALTER TABLE note_revisions_mig RENAME TO note_revisions;
UPDATE note_revisions SET isErased = (SELECT isErased FROM notes WHERE notes.noteId = note_revisions.noteId);
CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`); CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`);
CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`); CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`);
CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`); CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`);

View File

@ -334,6 +334,27 @@ async function findLogicIssues() {
AND content IS NOT NULL`, AND content IS NOT NULL`,
({noteId}) => `Note ${noteId} content is not null even though the note is erased`); ({noteId}) => `Note ${noteId} content is not null even though the note is erased`);
await findAndFixIssues(`
SELECT noteId, noteRevisionId
FROM notes
JOIN note_revisions USING(noteId)
WHERE
notes.isErased = 1
AND note_revisions.isErased = 0`,
async ({noteId, noteRevisionId}, autoFix) => {
if (autoFix) {
const noteRevision = await repository.getNoteRevision(noteRevisionId);
noteRevision.isErased = true;
await noteRevision.setContent(null);
await noteRevision.save();
logFix(`Note revision ${noteRevisionId} has been erased since its note ${noteId} is also erased.`);
}
else {
logError(`Note revision ${noteRevisionId} is not erased even though note ${noteId} is erased.`);
}
});
await findAndFixIssues(` await findAndFixIssues(`
SELECT noteRevisionId SELECT noteRevisionId
FROM note_revisions FROM note_revisions