Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SO migration] remove v1 implementation #118000

Merged
708 changes: 495 additions & 213 deletions src/core/server/saved_objects/migrations/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import * as Either from 'fp-ts/lib/Either';
import * as Option from 'fp-ts/lib/Option';
import { errors } from '@elastic/elasticsearch';
import { DocumentsTransformFailed, DocumentsTransformSuccess } from '../../../migrations/core';
import { DocumentsTransformFailed, DocumentsTransformSuccess } from '../../core';
import { TaskEither } from 'fp-ts/lib/TaskEither';
import Path from 'path';

Expand Down

This file was deleted.

28 changes: 0 additions & 28 deletions src/core/server/saved_objects/migrations/core/call_cluster.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { disableUnknownTypeMappingFields } from './migration_context';
import { disableUnknownTypeMappingFields } from './disable_unknown_type_mapping_fields';

describe('disableUnknownTypeMappingFields', () => {
const sourceMappings = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { SavedObjectsMappingProperties, IndexMapping } from '../../mappings';

/**
* Merges the active mappings and the source mappings while disabling the
* fields of any unknown Saved Object types present in the source index's
* mappings.
*
* Since the Saved Objects index has `dynamic: strict` defined at the
* top-level, only Saved Object types for which a mapping exists can be
* inserted into the index. To ensure that we can continue to store Saved
* Object documents belonging to a disabled plugin we define a mapping for all
* the unknown Saved Object types that were present in the source index's
* mappings. To limit the field count as much as possible, these unkwnown
* type's mappings are set to `dynamic: false`.
*
* (Since we're using the source index mappings instead of looking at actual
* document types in the inedx, we potentially add more "unknown types" than
* what would be necessary to support migrating all the data over to the
* target index.)
*
* @param activeMappings The mappings compiled from all the Saved Object types
* known to this Kibana node.
* @param sourceMappings The mappings of index used as the migration source.
* @returns The mappings that should be applied to the target index.
*/
export function disableUnknownTypeMappingFields(
activeMappings: IndexMapping,
sourceMappings: IndexMapping
): IndexMapping {
Comment on lines +34 to +37
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted from migration_context.ts, as this was the only function that is still used by v2.

const targetTypes = Object.keys(activeMappings.properties);

const disabledTypesProperties = Object.keys(sourceMappings.properties ?? {})
.filter((sourceType) => {
const isObjectType = 'properties' in sourceMappings.properties[sourceType];
// Only Object/Nested datatypes can be excluded from the field count by
// using `dynamic: false`.
return !targetTypes.includes(sourceType) && isObjectType;
})
.reduce((disabledTypesAcc, sourceType) => {
disabledTypesAcc[sourceType] = { dynamic: false, properties: {} };
return disabledTypesAcc;
}, {} as SavedObjectsMappingProperties);

return {
...activeMappings,
properties: {
...sourceMappings.properties,
...disabledTypesProperties,
...activeMappings.properties,
},
};
}
Loading