trilium/apps/server/src/migrations/0220__migrate_images_to_attachments.ts
Elian Doran 8994f537dc
fix(migration): use bundleable migrations
This fixes TypeScript migrations, which were not being run correctly
even in previous versions.

On the ESBuild version, neither SQL migrations worked due to the fact
that they were not being bundled.
2025-05-30 21:32:35 +03:00

27 lines
994 B
TypeScript

import becca from "../becca/becca.js";
import becca_loader from "../becca/becca_loader.js";
import cls from "../services/cls.js";
import log from "../services/log.js";
import sql from "../services/sql.js";
export default () => {
cls.init(() => {
// emergency disabling of image compression since it appears to make problems in migration to 0.61
sql.execute(/*sql*/`UPDATE options SET value = 'false' WHERE name = 'compressImages'`);
becca_loader.load();
for (const note of Object.values(becca.notes)) {
try {
const attachment = note.convertToParentAttachment({ autoConversion: true });
if (attachment) {
log.info(`Auto-converted note '${note.noteId}' into attachment '${attachment.attachmentId}'.`);
}
} catch (e: any) {
log.error(`Cannot convert note '${note.noteId}' to attachment: ${e.message} ${e.stack}`);
}
}
});
};