Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
#	src/services/build.js
#	src/services/migration.js
  • Loading branch information
zadam committed Jan 27, 2024
2 parents 69b686b + e76093e commit 92e8b15
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions db/migrations/0215__content_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 1 addition & 0 deletions db/migrations/0218__rename_note_revision_to_revision.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 2 additions & 0 deletions db/migrations/0219__attachments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/services/build.js
Original file line number Diff line number Diff line change
@@ -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" };
12 changes: 11 additions & 1 deletion src/services/cls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -102,5 +110,7 @@ module.exports = {
putEntityChange,
ignoreEntityChangeIds,
disableSlowQueryLogging,
isSlowQueryLoggingDisabled
isSlowQueryLoggingDisabled,
setMigrationRunning,
isMigrationRunning
};
8 changes: 6 additions & 2 deletions src/services/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ 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;
}

// 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'
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 92e8b15

Please sign in to comment.