diff --git a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts index c7d56f3912256..461ae1df6bc3d 100644 --- a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts +++ b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts @@ -21,16 +21,16 @@ import { MigrateAndConvertFn } from './document_migrator'; import { TransformSavedObjectDocumentError } from '.'; export interface DocumentsTransformFailed { - type: string; - corruptDocumentIds: string[]; - transformErrors: TransformErrorObjects[]; + readonly type: string; + readonly corruptDocumentIds: string[]; + readonly transformErrors: TransformErrorObjects[]; } export interface DocumentsTransformSuccess { - processedDocs: SavedObjectsRawDoc[]; + readonly processedDocs: SavedObjectsRawDoc[]; } export interface TransformErrorObjects { - rawId: string; - err: TransformSavedObjectDocumentError | Error; + readonly rawId: string; + readonly err: TransformSavedObjectDocumentError | Error; } type MigrateFn = ( doc: SavedObjectUnsanitizedDoc @@ -101,7 +101,6 @@ export function migrateRawDocsSafely( const options = { namespaceTreatment: 'lax' as const }; for (const raw of rawDocs) { if (serializer.isRawSavedObject(raw, options)) { - // const savedObject = convertToRawAddMigrationVersion(raw, options, serializer); try { const savedObject = convertToRawAddMigrationVersion(raw, options, serializer); processedDocs.push( @@ -110,9 +109,9 @@ export function migrateRawDocsSafely( } catch (err) { if (err instanceof TransformSavedObjectDocumentError) { // the doc id we get from the error is only the uuid part - // we transform the id to a raw saved object id. + // we use the original raw document _id instead transformErrors.push({ - rawId: serializer.generateRawId(err.namespace, err.type, err.id), + rawId: raw._id, err, }); } else { @@ -179,7 +178,7 @@ async function migrateMapToRawDoc( } /** - * Sanitizes the raw saved object document and sets the migration version + * Sanitizes the raw saved object document * @param {SavedObjectRawDoc} rawDoc * @param options * @param {SavedObjectsSerializer} serializer diff --git a/src/core/server/saved_objects/migrationsv2/integration_tests/actions.test.ts b/src/core/server/saved_objects/migrationsv2/integration_tests/actions.test.ts index cefe7d9360af0..d0158a4c68f24 100644 --- a/src/core/server/saved_objects/migrationsv2/integration_tests/actions.test.ts +++ b/src/core/server/saved_objects/migrationsv2/integration_tests/actions.test.ts @@ -1039,7 +1039,6 @@ describe('migration actions', () => { const resultsWithProcessDocs = ((await transformTask()) as Either.Right) .right.processedDocs; expect(resultsWithProcessDocs.length).toEqual(2); - // const foo2 = hits.find((h) => h._id === 'foo:2'); const foo2 = resultsWithProcessDocs.find((h) => h._id === 'foo:2'); expect(foo2?._source?.value).toBe(3); }); diff --git a/src/core/server/saved_objects/migrationsv2/integration_tests/corrupt_outdated_docs.test.ts b/src/core/server/saved_objects/migrationsv2/integration_tests/corrupt_outdated_docs.test.ts index 244cd4b1c21c9..e48f1e65c120f 100644 --- a/src/core/server/saved_objects/migrationsv2/integration_tests/corrupt_outdated_docs.test.ts +++ b/src/core/server/saved_objects/migrationsv2/integration_tests/corrupt_outdated_docs.test.ts @@ -111,10 +111,11 @@ describe('migration v2 with corrupt saved object documents', () => { const corruptBarSOs = /bar:/g; const corruptBazSOs = /baz:/g; expect( - [...err.message.matchAll(corruptFooSOs)].concat( - [...err.message.matchAll(corruptBarSOs)], - [...err.message.matchAll(corruptBazSOs)] - ).length + [ + ...err.message.matchAll(corruptFooSOs), + ...err.message.matchAll(corruptBarSOs), + ...err.message.matchAll(corruptBazSOs), + ].length ).toEqual(16); } });