DB migration fixes

This commit is contained in:
zadam 2020-12-16 20:58:43 +01:00
parent 4a15127e58
commit cdc2721ac1
5 changed files with 15 additions and 6 deletions

View file

@ -5,10 +5,12 @@ CREATE TABLE IF NOT EXISTS "mig_entity_changes" (
`hash` TEXT NOT NULL,
`isErased` INT NOT NULL,
`sourceId` TEXT NOT NULL,
`isSynced` INTEGER NOT NULL);
`isSynced` INTEGER NOT NULL,
`utcDateChanged` TEXT NOT NULL
);
INSERT INTO mig_entity_changes (entityName, entityId, hash, sourceId, isSynced, isErased)
SELECT entityName, entityId, '', sourceId, isSynced, isErased FROM entity_changes;
INSERT INTO mig_entity_changes (entityName, entityId, hash, sourceId, isSynced, isErased, utcDateChanged)
SELECT entityName, entityId, '', sourceId, isSynced, isErased, utcDateChanged FROM entity_changes;
UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM api_tokens WHERE apiTokenId = entityId), '') WHERE entityName = 'api_tokens';
UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM attributes WHERE attributeId = entityId), '') WHERE entityName = 'attributes';

View file

@ -465,7 +465,13 @@ class ConsistencyChecks {
if (this.autoFix) {
const entity = repository.getEntity(`SELECT * FROM ${entityName} WHERE ${key} = ?`, [entityId]);
entityChangesService.addEntityChange(entityName, entityId, entity.generateHash());
entityChangesService.addEntityChange({
entityName,
entityId,
hash: entity.generateHash(),
isErased: false,
utcDateChanged: entity.getUtcDateChanged()
}, null);
logFix(`Created missing entity change for entityName=${entityName}, entityId=${entityId}`);
} else {

View file

@ -62,7 +62,7 @@ async function migrate() {
}
// not using repository because of changed utcDateModified column in migration 129
sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion, "dbVersion"]);
sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]);
});
log.info("Migration to version " + mig.dbVersion + " has been successful.");

View file

@ -58,7 +58,6 @@ function initNotSyncedOptions(initialized, startNotePath = 'root', opts = {}) {
const defaultOptions = [
{ name: 'noteRevisionSnapshotTimeInterval', value: '600', isSynced: true },
{ name: 'protectedSessionTimeout', value: '600', isSynced: true },
{ name: 'hoistedNoteId', value: 'root', isSynced: false },
{ name: 'zoomFactor', value: '1.0', isSynced: false },
{ name: 'mainFontSize', value: '100', isSynced: false },
{ name: 'treeFontSize', value: '100', isSynced: false },

View file

@ -210,6 +210,8 @@ function wrap(query, func) {
return null
}
throw e;
}
const milliseconds = Date.now() - startTimestamp;