diff --git a/dev/tool/Dockerfile b/dev/tool/Dockerfile index 1ecba5bf36..57c69ccb4b 100644 --- a/dev/tool/Dockerfile +++ b/dev/tool/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16 +FROM node:18 WORKDIR /usr/src/app diff --git a/models/all/src/version.json b/models/all/src/version.json index 75a6ec1f45..f72b01b9e0 100644 --- a/models/all/src/version.json +++ b/models/all/src/version.json @@ -1 +1 @@ -{ "major": 0, "minor": 6, "patch": 6 } +{ "major": 0, "minor": 6, "patch": 73 } diff --git a/models/core/src/migration.ts b/models/core/src/migration.ts index c5be987982..4b73d9b384 100644 --- a/models/core/src/migration.ts +++ b/models/core/src/migration.ts @@ -37,52 +37,54 @@ async function fillCreatedBy (client: MigrationClient): Promise { ) { continue } - try { - const objects = await client.find( - domain, - { createdBy: { $exists: false } }, - { projection: { _id: 1, modifiedBy: 1 } } - ) - if (objects.length === 0) { - continue - } - const txes = await client.find>( - DOMAIN_TX, - { - _class: core.class.TxCreateDoc, - objectId: { $in: Array.from(objects.map((it) => it._id)) } - }, - { projection: { _id: 1, modifiedBy: 1, createdBy: 1, objectId: 1 } } - ) - - const txes2 = ( - await client.find>( + while (true) { + try { + const objects = await client.find( + domain, + { createdBy: { $exists: false } }, + { projection: { _id: 1, modifiedBy: 1 }, limit: 10000 } + ) + if (objects.length === 0) { + break + } + const txes = await client.find>( DOMAIN_TX, { - _class: core.class.TxCollectionCUD, - 'tx._class': core.class.TxCreateDoc, - 'tx.objectId': { $in: Array.from(objects.map((it) => it._id)) } + _class: core.class.TxCreateDoc, + objectId: { $in: Array.from(objects.map((it) => it._id)) } }, - { projection: { _id: 1, modifiedBy: 1, createdBy: 1, tx: 1 } } + { projection: { _id: 1, modifiedBy: 1, createdBy: 1, objectId: 1 } } ) - ).map((it) => it.tx as unknown as TxCreateDoc) - const txMap = new Map(txes.concat(txes2).map((p) => [p.objectId, p])) + const txes2 = ( + await client.find>( + DOMAIN_TX, + { + _class: core.class.TxCollectionCUD, + 'tx._class': core.class.TxCreateDoc, + 'tx.objectId': { $in: Array.from(objects.map((it) => it._id)) } + }, + { projection: { _id: 1, modifiedBy: 1, createdBy: 1, tx: 1 } } + ) + ).map((it) => it.tx as unknown as TxCreateDoc) - console.log('migrateCreateBy', domain, objects.length) - await client.bulk( - domain, - objects.map((it) => { - const createTx = txMap.get(it._id) - return { - filter: { _id: it._id }, - update: { - createdBy: createTx?.modifiedBy ?? it.modifiedBy + const txMap = new Map(txes.concat(txes2).map((p) => [p.objectId, p])) + + console.log('migrateCreateBy', domain, objects.length) + await client.bulk( + domain, + objects.map((it) => { + const createTx = txMap.get(it._id) + return { + filter: { _id: it._id }, + update: { + createdBy: createTx?.modifiedBy ?? it.modifiedBy + } } - } - }) - ) - } catch (err) {} + }) + ) + } catch (err) {} + } } } export const coreOperation: MigrateOperation = {