diff --git a/db/migrations/0215__content_structure.sql b/db/migrations/0215__content_structure.sql index 9f599cec3..da4afcf6b 100644 --- a/db/migrations/0215__content_structure.sql +++ b/db/migrations/0215__content_structure.sql @@ -8,3 +8,6 @@ CREATE TABLE IF NOT EXISTS "blobs" ( ALTER TABLE notes ADD blobId TEXT DEFAULT NULL; ALTER TABLE note_revisions ADD blobId TEXT DEFAULT NULL; + +CREATE INDEX IF NOT EXISTS IDX_notes_blobId on notes (blobId); +CREATE INDEX IF NOT EXISTS IDX_note_revisions_blobId on note_revisions (blobId); diff --git a/db/migrations/0218__rename_note_revision_to_revision.sql b/db/migrations/0218__rename_note_revision_to_revision.sql index 780099872..c67c52393 100644 --- a/db/migrations/0218__rename_note_revision_to_revision.sql +++ b/db/migrations/0218__rename_note_revision_to_revision.sql @@ -21,5 +21,6 @@ CREATE INDEX `IDX_revisions_utcDateCreated` ON `revisions` (`utcDateCreated`); CREATE INDEX `IDX_revisions_utcDateLastEdited` ON `revisions` (`utcDateLastEdited`); CREATE INDEX `IDX_revisions_dateCreated` ON `revisions` (`dateCreated`); CREATE INDEX `IDX_revisions_dateLastEdited` ON `revisions` (`dateLastEdited`); +CREATE INDEX IF NOT EXISTS IDX_revisions_blobId on revisions (blobId); UPDATE entity_changes SET entityName = 'revisions' WHERE entityName = 'note_revisions'; diff --git a/db/migrations/0219__attachments.sql b/db/migrations/0219__attachments.sql index 5e7c93e96..246360bfe 100644 --- a/db/migrations/0219__attachments.sql +++ b/db/migrations/0219__attachments.sql @@ -19,3 +19,5 @@ CREATE INDEX IDX_attachments_ownerId_role CREATE INDEX IDX_attachments_utcDateScheduledForErasureSince on attachments (utcDateScheduledForErasureSince); + +CREATE INDEX IF NOT EXISTS IDX_attachments_blobId on attachments (blobId); diff --git a/src/services/build.js b/src/services/build.js index e73f6f542..f42c6d8df 100644 --- a/src/services/build.js +++ b/src/services/build.js @@ -1 +1 @@ -module.exports = { buildDate:"2024-01-12T00:02:50+01:00", buildRevision: "17e063f01d3b6c7a601630feaa96191d26095650" }; +module.exports = { buildDate:"2024-01-21T23:49:23+01:00", buildRevision: "4f8073daa7cff1b8b6737ae45792b2e87c2adf33" }; diff --git a/src/services/cls.js b/src/services/cls.js index 0bfde4436..8e2c2870c 100644 --- a/src/services/cls.js +++ b/src/services/cls.js @@ -48,6 +48,14 @@ function isEntityEventsDisabled() { return !!namespace.get('disableEntityEvents'); } +function setMigrationRunning(running) { + namespace.set('migrationRunning', !!running); +} + +function isMigrationRunning() { + return !!namespace.get('migrationRunning'); +} + function disableSlowQueryLogging(disable) { namespace.set('disableSlowQueryLogging', disable); } @@ -102,5 +110,7 @@ module.exports = { putEntityChange, ignoreEntityChangeIds, disableSlowQueryLogging, - isSlowQueryLoggingDisabled + isSlowQueryLoggingDisabled, + setMigrationRunning, + isMigrationRunning }; diff --git a/src/services/migration.js b/src/services/migration.js index 4b9240a04..aeb7ba217 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -5,12 +5,13 @@ const log = require('./log.js'); const utils = require('./utils.js'); const resourceDir = require('./resource_dir.js'); const appInfo = require('./app_info.js'); +const cls = require('./cls.js'); async function migrate() { const currentDbVersion = getDbVersion(); if (currentDbVersion < 214) { - log.error("Direct migration from your current version is not supported. Please upgrade to the latest v0.60.X first and only then to this version."); + log.error("Direct migration from your current version is not supported. Please upgrade to the latest v0.60.4 first and only then to this version."); utils.crash(); return; @@ -18,7 +19,7 @@ async function migrate() { // backup before attempting migration await backupService.backupNow( - // creating a special backup for versions 0.60.X, the changes in 0.61 are major. + // creating a special backup for version 0.60.4, the changes in 0.61 are major. currentDbVersion === 214 ? `before-migration-v060` : 'before-migration' @@ -51,6 +52,9 @@ async function migrate() { // all migrations are executed in one transaction - upgrade either succeeds, or the user can stay at the old version // otherwise if half of the migrations succeed, user can't use any version - DB is too "new" for the old app, // and too old for the new app version. + + cls.setMigrationRunning(true); + sql.transactional(() => { for (const mig of migrations) { try { diff --git a/src/services/notes.js b/src/services/notes.js index 0cb5ab5c8..80a3b8e84 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -895,6 +895,11 @@ function scanForLinks(note, content) { * Things which have to be executed after updating content, but asynchronously (separate transaction) */ async function asyncPostProcessContent(note, content) { + if (cls.isMigrationRunning()) { + // this is rarely needed for migrations, but can cause trouble by e.g. triggering downloads + return; + } + if (note.hasStringContent() && !utils.isString(content)) { content = content.toString(); }