fix: await promises in migration

This commit is contained in:
Johann150 2022-08-18 18:26:17 +02:00
parent 01a4f3a7b8
commit 5d41384708
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -19,16 +19,16 @@ export class pagesToPlaintext1659335999000 {
async function convertBlock(block) { async function convertBlock(block) {
switch (block.type) { switch (block.type) {
case 'note': case 'note':
if (block.note) return noteUrl(block.note); if (block.note) return await noteUrl(block.note);
else break; else break;
case 'section': case 'section':
return block.children.map(convertBlock).join('\n'); return (await Promise.all(block.children.map(convertBlock))).join('\n');
case 'text': case 'text':
return block.text; return block.text;
case 'textarea': case 'textarea':
return '```\n' + block.text + '```'; return '```\n' + block.text + '```';
case 'image': case 'image':
if (block.fileId) return '![image](' + fileUrl(block.fileId) + ')'; if (block.fileId) return '![image](' + await fileUrl(block.fileId) + ')';
else break; else break;
case 'if': // no idea how to convert these case 'if': // no idea how to convert these
case 'post': // new note form, why? case 'post': // new note form, why?
@ -48,9 +48,10 @@ export class pagesToPlaintext1659335999000 {
await queryRunner.query(`SELECT id, "content" FROM "page"`) await queryRunner.query(`SELECT id, "content" FROM "page"`)
.then(pages => Promise.all(pages.map(page => { .then(pages => Promise.all(pages.map(page => {
let text = page.content.map(convertBlock).join('\n'); return Promise.all(page.content.map(convertBlock))
.then(texts => {
return queryRunner.query(`UPDATE "page" SET "text" = $1 WHERE "id" = $2`, [text, page.id]); queryRunner.query(`UPDATE "page" SET "text" = $1 WHERE "id" = $2`, [texts.join('\n'), page.id]);
});
}))); })));
await queryRunner.query(`ALTER TABLE "page" DROP COLUMN "content"`); await queryRunner.query(`ALTER TABLE "page" DROP COLUMN "content"`);