Skip to content

Commit

Permalink
Addresses minor changes requested
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed May 10, 2021
1 parent 671b286 commit 39f9f28
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,6 @@ describe('migration actions', () => {
const resultsWithProcessDocs = ((await transformTask()) as Either.Right<DocumentsTransformSuccess>)
.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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down

0 comments on commit 39f9f28

Please sign in to comment.