Skip to content

Commit

Permalink
[SO migration] remove v1 implementation (#118000)
Browse files Browse the repository at this point in the history
* remove v1 implementation

* fix type

* remove unused mock

* expose kibanaVersion again

* fix migrator mock

* move KibanaMigrator out of the kibana subfolder

* fix imports

* moves migrationsv2 into migrations

* fix test mocking
  • Loading branch information
pgayvallet authored Nov 10, 2021
1 parent 7ab3593 commit f716387
Show file tree
Hide file tree
Showing 147 changed files with 717 additions and 3,994 deletions.
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 {
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

0 comments on commit f716387

Please sign in to comment.