From fbbeee9e4d22988a6410b4f92620ae18f5a65107 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 20:08:29 +0000 Subject: [PATCH] fix(migration): avoid mutating MIGRATIONS array in-place during sort The prepareMigrations() function called MIGRATIONS.sort() which mutated the module-level exported array. When the test setup ran migrations via beforeAll(), the array was left in ascending order, causing the migrations.spec.ts ordering test to fail. Co-authored-by: Elian Doran --- packages/trilium-core/src/services/migration.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/trilium-core/src/services/migration.ts b/packages/trilium-core/src/services/migration.ts index 209ad6f76b..e0cc55e47c 100644 --- a/packages/trilium-core/src/services/migration.ts +++ b/packages/trilium-core/src/services/migration.ts @@ -77,9 +77,9 @@ async function migrate() { } async function prepareMigrations(currentDbVersion: number): Promise { - MIGRATIONS.sort((a, b) => a.version - b.version); + const sortedMigrations = [...MIGRATIONS].sort((a, b) => a.version - b.version); const migrations: MigrationInfo[] = []; - for (const migration of MIGRATIONS) { + for (const migration of sortedMigrations) { const dbVersion = migration.version; if (dbVersion > currentDbVersion) { if ("sql" in migration) {