Notes/db/migrations/0220__migrate_images_to_attachments.ts

27 lines
1002 B
TypeScript
Raw Normal View History

import becca from "../../src/becca/becca";
import becca_loader from "../../src/becca/becca_loader";
import cls from "../../src/services/cls";
import log from "../../src/services/log";
import sql from "../../src/services/sql";
2023-03-24 09:13:35 +01:00
export default () => {
2023-03-24 09:13:35 +01:00
cls.init(() => {
// emergency disabling of image compression since it appears to make problems in migration to 0.61
sql.execute(`UPDATE options SET value = 'false' WHERE name = 'compressImages'`);
becca_loader.load();
2023-03-24 09:13:35 +01:00
for (const note of Object.values(becca.notes)) {
try {
2024-03-30 10:49:40 +02:00
const attachment = note.convertToParentAttachment({ autoConversion: true });
2023-03-24 09:13:35 +01:00
2023-03-30 23:48:26 +02:00
if (attachment) {
log.info(`Auto-converted note '${note.noteId}' into attachment '${attachment.attachmentId}'.`);
}
2025-01-09 18:07:02 +02:00
} catch (e) {
2023-03-24 09:13:35 +01:00
log.error(`Cannot convert note '${note.noteId}' to attachment: ${e.message} ${e.stack}`);
}
}
});
2023-03-30 23:48:26 +02:00
};