diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectmigrationfn.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectmigrationfn.md
index a502c40db0cd8c..a3294fb0a087ae 100644
--- a/docs/development/core/server/kibana-plugin-core-server.savedobjectmigrationfn.md
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectmigrationfn.md
@@ -9,22 +9,36 @@ A migration function for a [saved object type](./kibana-plugin-core-server.saved
Signature:
```typescript
-export declare type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc;
+export declare type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc;
```
## Example
```typescript
-const migrateProperty: SavedObjectMigrationFn = (doc, { log }) => {
- if(doc.attributes.someProp === null) {
- log.warn('Skipping migration');
- } else {
- doc.attributes.someProp = migrateProperty(doc.attributes.someProp);
- }
-
- return doc;
+interface TypeV1Attributes {
+ someKey: string;
+ obsoleteProperty: number;
}
+interface TypeV2Attributes {
+ someKey: string;
+ newProperty: string;
+}
+
+const migrateToV2: SavedObjectMigrationFn = (doc, { log }) => {
+ const { obsoleteProperty, ...otherAttributes } = doc.attributes;
+ // instead of mutating `doc` we make a shallow copy so that we can use separate types for the input
+ // and output attributes. We don't need to make a deep copy, we just need to ensure that obsolete
+ // attributes are not present on the returned doc.
+ return {
+ ...doc,
+ attributes: {
+ ...otherAttributes,
+ newProperty: migrate(obsoleteProperty),
+ },
+ };
+};
+
```
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md
index 6d4e252fe7532e..3f4090619edbfb 100644
--- a/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectsanitizeddoc.md
@@ -9,5 +9,5 @@ Describes Saved Object documents that have passed through the migration framewor
Signature:
```typescript
-export declare type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
+export declare type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
```
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectunsanitizeddoc.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectunsanitizeddoc.md
index be51400addbbc5..8e2395ee6310d8 100644
--- a/docs/development/core/server/kibana-plugin-core-server.savedobjectunsanitizeddoc.md
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectunsanitizeddoc.md
@@ -9,5 +9,5 @@ Describes Saved Object documents from Kibana < 7.0.0 which don't have a `refe
Signature:
```typescript
-export declare type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
+export declare type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
```
diff --git a/src/core/MIGRATION_EXAMPLES.md b/src/core/MIGRATION_EXAMPLES.md
index 8c5fe4875aaea2..c91c00bc1aa021 100644
--- a/src/core/MIGRATION_EXAMPLES.md
+++ b/src/core/MIGRATION_EXAMPLES.md
@@ -957,7 +957,7 @@ const migration = (doc, log) => {...}
Would be converted to:
```typescript
-const migration: SavedObjectMigrationFn = (doc, { log }) => {...}
+const migration: SavedObjectMigrationFn = (doc, { log }) => {...}
```
### Remarks
diff --git a/src/core/server/saved_objects/migrations/core/index.ts b/src/core/server/saved_objects/migrations/core/index.ts
index 466d399f653cd6..f7274740ea5fe3 100644
--- a/src/core/server/saved_objects/migrations/core/index.ts
+++ b/src/core/server/saved_objects/migrations/core/index.ts
@@ -21,5 +21,5 @@ export { DocumentMigrator } from './document_migrator';
export { IndexMigrator } from './index_migrator';
export { buildActiveMappings } from './build_active_mappings';
export { CallCluster } from './call_cluster';
-export { LogFn } from './migration_logger';
+export { LogFn, SavedObjectsMigrationLogger } from './migration_logger';
export { MigrationResult, MigrationStatus } from './migration_coordinator';
diff --git a/src/core/server/saved_objects/migrations/mocks.ts b/src/core/server/saved_objects/migrations/mocks.ts
new file mode 100644
index 00000000000000..76a890d26bfa0c
--- /dev/null
+++ b/src/core/server/saved_objects/migrations/mocks.ts
@@ -0,0 +1,43 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { SavedObjectMigrationContext } from './types';
+import { SavedObjectsMigrationLogger } from './core';
+
+const createLoggerMock = (): jest.Mocked => {
+ const mock = {
+ debug: jest.fn(),
+ info: jest.fn(),
+ warning: jest.fn(),
+ warn: jest.fn(),
+ };
+
+ return mock;
+};
+
+const createContextMock = (): jest.Mocked => {
+ const mock = {
+ log: createLoggerMock(),
+ };
+ return mock;
+};
+
+export const migrationMocks = {
+ createContext: createContextMock,
+};
diff --git a/src/core/server/saved_objects/migrations/types.ts b/src/core/server/saved_objects/migrations/types.ts
index 6bc085dde872e3..85f15b4c18b66a 100644
--- a/src/core/server/saved_objects/migrations/types.ts
+++ b/src/core/server/saved_objects/migrations/types.ts
@@ -26,23 +26,37 @@ import { SavedObjectsMigrationLogger } from './core/migration_logger';
*
* @example
* ```typescript
- * const migrateProperty: SavedObjectMigrationFn = (doc, { log }) => {
- * if(doc.attributes.someProp === null) {
- * log.warn('Skipping migration');
- * } else {
- * doc.attributes.someProp = migrateProperty(doc.attributes.someProp);
- * }
+ * interface TypeV1Attributes {
+ * someKey: string;
+ * obsoleteProperty: number;
+ * }
*
- * return doc;
+ * interface TypeV2Attributes {
+ * someKey: string;
+ * newProperty: string;
* }
+ *
+ * const migrateToV2: SavedObjectMigrationFn = (doc, { log }) => {
+ * const { obsoleteProperty, ...otherAttributes } = doc.attributes;
+ * // instead of mutating `doc` we make a shallow copy so that we can use separate types for the input
+ * // and output attributes. We don't need to make a deep copy, we just need to ensure that obsolete
+ * // attributes are not present on the returned doc.
+ * return {
+ * ...doc,
+ * attributes: {
+ * ...otherAttributes,
+ * newProperty: migrate(obsoleteProperty),
+ * },
+ * };
+ * };
* ```
*
* @public
*/
-export type SavedObjectMigrationFn = (
- doc: SavedObjectUnsanitizedDoc,
+export type SavedObjectMigrationFn = (
+ doc: SavedObjectUnsanitizedDoc,
context: SavedObjectMigrationContext
-) => SavedObjectUnsanitizedDoc;
+) => SavedObjectUnsanitizedDoc;
/**
* Migration context provided when invoking a {@link SavedObjectMigrationFn | migration handler}
diff --git a/src/core/server/saved_objects/saved_objects_service.mock.ts b/src/core/server/saved_objects/saved_objects_service.mock.ts
index 7ba4613c857d7b..4e1f5981d6a410 100644
--- a/src/core/server/saved_objects/saved_objects_service.mock.ts
+++ b/src/core/server/saved_objects/saved_objects_service.mock.ts
@@ -31,6 +31,7 @@ import { savedObjectsClientProviderMock } from './service/lib/scoped_client_prov
import { savedObjectsRepositoryMock } from './service/lib/repository.mock';
import { savedObjectsClientMock } from './service/saved_objects_client.mock';
import { typeRegistryMock } from './saved_objects_type_registry.mock';
+import { migrationMocks } from './migrations/mocks';
import { ServiceStatusLevels } from '../status';
type SavedObjectsServiceContract = PublicMethodsOf;
@@ -105,4 +106,5 @@ export const savedObjectsServiceMock = {
createSetupContract: createSetupContractMock,
createInternalStartContract: createInternalStartContractMock,
createStartContract: createStartContractMock,
+ createMigrationContext: migrationMocks.createContext,
};
diff --git a/src/core/server/saved_objects/serialization/types.ts b/src/core/server/saved_objects/serialization/types.ts
index a33e16895078ed..acd2c7b5284aa2 100644
--- a/src/core/server/saved_objects/serialization/types.ts
+++ b/src/core/server/saved_objects/serialization/types.ts
@@ -47,8 +47,8 @@ export interface SavedObjectsRawDocSource {
/**
* Saved Object base document
*/
-interface SavedObjectDoc {
- attributes: any;
+interface SavedObjectDoc {
+ attributes: T;
id?: string; // NOTE: SavedObjectDoc is used for uncreated objects where `id` is optional
type: string;
namespace?: string;
@@ -69,7 +69,7 @@ interface Referencable {
*
* @public
*/
-export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
+export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
/**
* Describes Saved Object documents that have passed through the migration
@@ -77,4 +77,4 @@ export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
*
* @public
*/
-export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
+export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md
index dc1c9d379d508a..e8b77a8570291e 100644
--- a/src/core/server/server.api.md
+++ b/src/core/server/server.api.md
@@ -1680,7 +1680,7 @@ export interface SavedObjectMigrationContext {
}
// @public
-export type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc;
+export type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc;
// @public
export interface SavedObjectMigrationMap {
@@ -1708,7 +1708,7 @@ export interface SavedObjectsAddToNamespacesOptions extends SavedObjectsBaseOpti
// Warning: (ae-forgotten-export) The symbol "Referencable" needs to be exported by the entry point index.d.ts
//
// @public
-export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
+export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
// @public (undocumented)
export interface SavedObjectsBaseOptions {
@@ -2311,7 +2311,7 @@ export class SavedObjectTypeRegistry {
}
// @public
-export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
+export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial;
// @public
export type ScopeableRequest = KibanaRequest | LegacyRequest | FakeRequest;
diff --git a/src/plugins/dashboard/server/saved_objects/dashboard_migrations.test.ts b/src/plugins/dashboard/server/saved_objects/dashboard_migrations.test.ts
index 9829498118cc0a..22ed18f75c652a 100644
--- a/src/plugins/dashboard/server/saved_objects/dashboard_migrations.test.ts
+++ b/src/plugins/dashboard/server/saved_objects/dashboard_migrations.test.ts
@@ -18,14 +18,17 @@
*/
import { SavedObjectUnsanitizedDoc } from 'kibana/server';
+import { savedObjectsServiceMock } from '../../../../core/server/mocks';
import { dashboardSavedObjectTypeMigrations as migrations } from './dashboard_migrations';
+const contextMock = savedObjectsServiceMock.createMigrationContext();
+
describe('dashboard', () => {
describe('7.0.0', () => {
const migration = migrations['7.0.0'];
test('skips error on empty object', () => {
- expect(migration({} as SavedObjectUnsanitizedDoc)).toMatchInlineSnapshot(`
+ expect(migration({} as SavedObjectUnsanitizedDoc, contextMock)).toMatchInlineSnapshot(`
Object {
"references": Array [],
}
@@ -44,7 +47,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
};
- const migratedDoc = migration(doc);
+ const migratedDoc = migration(doc, contextMock);
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
@@ -83,7 +86,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
};
- const migratedDoc = migration(doc);
+ const migratedDoc = migration(doc, contextMock);
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
@@ -122,7 +125,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
};
- expect(migration(doc)).toMatchInlineSnapshot(`
+ expect(migration(doc, contextMock)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"kibanaSavedObjectMeta": Object {
@@ -160,7 +163,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
};
- expect(migration(doc)).toMatchInlineSnapshot(`
+ expect(migration(doc, contextMock)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"kibanaSavedObjectMeta": Object {
@@ -198,7 +201,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
};
- const migratedDoc = migration(doc);
+ const migratedDoc = migration(doc, contextMock);
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
@@ -237,7 +240,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
};
- const migratedDoc = migration(doc);
+ const migratedDoc = migration(doc, contextMock);
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
@@ -291,7 +294,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
};
- const migratedDoc = migration(doc);
+ const migratedDoc = migration(doc, contextMock);
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
@@ -331,7 +334,7 @@ Object {
panelsJSON: 123,
},
} as SavedObjectUnsanitizedDoc;
- expect(migration(doc)).toMatchInlineSnapshot(`
+ expect(migration(doc, contextMock)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"panelsJSON": 123,
@@ -349,7 +352,7 @@ Object {
panelsJSON: '{123abc}',
},
} as SavedObjectUnsanitizedDoc;
- expect(migration(doc)).toMatchInlineSnapshot(`
+ expect(migration(doc, contextMock)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"panelsJSON": "{123abc}",
@@ -367,7 +370,7 @@ Object {
panelsJSON: '{}',
},
} as SavedObjectUnsanitizedDoc;
- expect(migration(doc)).toMatchInlineSnapshot(`
+ expect(migration(doc, contextMock)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"panelsJSON": "{}",
@@ -385,7 +388,7 @@ Object {
panelsJSON: '[{"id":"123"}]',
},
} as SavedObjectUnsanitizedDoc;
- expect(migration(doc)).toMatchInlineSnapshot(`
+ expect(migration(doc, contextMock)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"panelsJSON": "[{\\"id\\":\\"123\\"}]",
@@ -403,7 +406,7 @@ Object {
panelsJSON: '[{"type":"visualization"}]',
},
} as SavedObjectUnsanitizedDoc;
- expect(migration(doc)).toMatchInlineSnapshot(`
+ expect(migration(doc, contextMock)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"panelsJSON": "[{\\"type\\":\\"visualization\\"}]",
@@ -422,7 +425,7 @@ Object {
'[{"id":"1","type":"visualization","foo":true},{"id":"2","type":"visualization","bar":true}]',
},
} as SavedObjectUnsanitizedDoc;
- const migratedDoc = migration(doc);
+ const migratedDoc = migration(doc, contextMock);
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
diff --git a/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts b/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts
index 7c1d0568cd3d71..4f7945d6dd6017 100644
--- a/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts
+++ b/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts
@@ -19,7 +19,7 @@
import { get, flow } from 'lodash';
-import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';
+import { SavedObjectMigrationFn } from 'kibana/server';
import { migrations730 } from './migrations_730';
import { migrateMatchAllQuery } from './migrate_match_all_query';
import { DashboardDoc700To720 } from '../../common';
@@ -62,7 +62,7 @@ function migrateIndexPattern(doc: DashboardDoc700To720) {
doc.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify(searchSource);
}
-const migrations700: SavedObjectMigrationFn = (doc): DashboardDoc700To720 => {
+const migrations700: SavedObjectMigrationFn = (doc): DashboardDoc700To720 => {
// Set new "references" attribute
doc.references = doc.references || [];
@@ -111,7 +111,7 @@ export const dashboardSavedObjectTypeMigrations = {
* in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
* only contained the 6.7.2 migration and not the 7.0.1 migration.
*/
- '6.7.2': flow(migrateMatchAllQuery),
- '7.0.0': flow<(doc: SavedObjectUnsanitizedDoc) => DashboardDoc700To720>(migrations700),
- '7.3.0': flow(migrations730),
+ '6.7.2': flow>(migrateMatchAllQuery),
+ '7.0.0': flow>(migrations700),
+ '7.3.0': flow>(migrations730),
};
diff --git a/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts b/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts
index 5b8582bf821ef5..db2fbeb2788023 100644
--- a/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts
+++ b/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts
@@ -21,7 +21,7 @@ import { SavedObjectMigrationFn } from 'kibana/server';
import { get } from 'lodash';
import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';
-export const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
+export const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
if (searchSourceJSON) {
diff --git a/src/plugins/dashboard/server/saved_objects/migrations_730.test.ts b/src/plugins/dashboard/server/saved_objects/migrations_730.test.ts
index aa744324428a41..a58df547fa5224 100644
--- a/src/plugins/dashboard/server/saved_objects/migrations_730.test.ts
+++ b/src/plugins/dashboard/server/saved_objects/migrations_730.test.ts
@@ -17,19 +17,13 @@
* under the License.
*/
+import { savedObjectsServiceMock } from '../../../../core/server/mocks';
import { dashboardSavedObjectTypeMigrations as migrations } from './dashboard_migrations';
import { migrations730 } from './migrations_730';
import { DashboardDoc700To720, DashboardDoc730ToLatest, DashboardDocPre700 } from '../../common';
import { RawSavedDashboardPanel730ToLatest } from '../../common';
-const mockContext = {
- log: {
- warning: () => {},
- warn: () => {},
- debug: () => {},
- info: () => {},
- },
-};
+const mockContext = savedObjectsServiceMock.createMigrationContext();
test('dashboard migration 7.3.0 migrates filters to query on search source', () => {
const doc: DashboardDoc700To720 = {
@@ -95,7 +89,7 @@ test('dashboard migration 7.3.0 migrates filters to query on search source when
},
};
- const doc700: DashboardDoc700To720 = migrations['7.0.0'](doc);
+ const doc700 = migrations['7.0.0'](doc, mockContext);
const newDoc = migrations['7.3.0'](doc700, mockContext);
const parsedSearchSource = JSON.parse(newDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON);
@@ -127,7 +121,7 @@ test('dashboard migration works when panelsJSON is missing panelIndex', () => {
},
};
- const doc700: DashboardDoc700To720 = migrations['7.0.0'](doc);
+ const doc700 = migrations['7.0.0'](doc, mockContext);
const newDoc = migrations['7.3.0'](doc700, mockContext);
const parsedSearchSource = JSON.parse(newDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON);
diff --git a/src/plugins/data/server/saved_objects/index_pattern_migrations.ts b/src/plugins/data/server/saved_objects/index_pattern_migrations.ts
index 7a16386ea484c8..c64f7361a8cf4f 100644
--- a/src/plugins/data/server/saved_objects/index_pattern_migrations.ts
+++ b/src/plugins/data/server/saved_objects/index_pattern_migrations.ts
@@ -20,7 +20,7 @@
import { flow, omit } from 'lodash';
import { SavedObjectMigrationFn } from 'kibana/server';
-const migrateAttributeTypeAndAttributeTypeMeta: SavedObjectMigrationFn = doc => ({
+const migrateAttributeTypeAndAttributeTypeMeta: SavedObjectMigrationFn = doc => ({
...doc,
attributes: {
...doc.attributes,
@@ -29,7 +29,7 @@ const migrateAttributeTypeAndAttributeTypeMeta: SavedObjectMigrationFn = doc =>
},
});
-const migrateSubTypeAndParentFieldProperties: SavedObjectMigrationFn = doc => {
+const migrateSubTypeAndParentFieldProperties: SavedObjectMigrationFn = doc => {
if (!doc.attributes.fields) return doc;
const fieldsString = doc.attributes.fields;
diff --git a/src/plugins/data/server/saved_objects/search_migrations.ts b/src/plugins/data/server/saved_objects/search_migrations.ts
index 45fa5e11e2a3d7..c8ded51193c92b 100644
--- a/src/plugins/data/server/saved_objects/search_migrations.ts
+++ b/src/plugins/data/server/saved_objects/search_migrations.ts
@@ -21,7 +21,7 @@ import { flow, get } from 'lodash';
import { SavedObjectMigrationFn } from 'kibana/server';
import { DEFAULT_QUERY_LANGUAGE } from '../../common';
-const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
+const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
if (searchSourceJSON) {
@@ -55,7 +55,7 @@ const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
return doc;
};
-const migrateIndexPattern: SavedObjectMigrationFn = doc => {
+const migrateIndexPattern: SavedObjectMigrationFn = doc => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
if (typeof searchSourceJSON !== 'string') {
return doc;
@@ -97,13 +97,13 @@ const migrateIndexPattern: SavedObjectMigrationFn = doc => {
return doc;
};
-const setNewReferences: SavedObjectMigrationFn = (doc, context) => {
+const setNewReferences: SavedObjectMigrationFn = (doc, context) => {
doc.references = doc.references || [];
// Migrate index pattern
return migrateIndexPattern(doc, context);
};
-const migrateSearchSortToNestedArray: SavedObjectMigrationFn = doc => {
+const migrateSearchSortToNestedArray: SavedObjectMigrationFn = doc => {
const sort = get(doc, 'attributes.sort');
if (!sort) return doc;
@@ -122,7 +122,7 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn = doc => {
};
export const searchSavedObjectTypeMigrations = {
- '6.7.2': flow(migrateMatchAllQuery),
- '7.0.0': flow(setNewReferences),
- '7.4.0': flow(migrateSearchSortToNestedArray),
+ '6.7.2': flow>(migrateMatchAllQuery),
+ '7.0.0': flow>(setNewReferences),
+ '7.4.0': flow>(migrateSearchSortToNestedArray),
};
diff --git a/src/plugins/vis_type_timeseries/server/saved_objects/tsvb_telemetry.ts b/src/plugins/vis_type_timeseries/server/saved_objects/tsvb_telemetry.ts
index 34922976f22ff5..1e5508b44ee0ec 100644
--- a/src/plugins/vis_type_timeseries/server/saved_objects/tsvb_telemetry.ts
+++ b/src/plugins/vis_type_timeseries/server/saved_objects/tsvb_telemetry.ts
@@ -20,7 +20,7 @@
import { flow } from 'lodash';
import { SavedObjectMigrationFn, SavedObjectsType } from 'kibana/server';
-const resetCount: SavedObjectMigrationFn = doc => ({
+const resetCount: SavedObjectMigrationFn = doc => ({
...doc,
attributes: {
...doc.attributes,
diff --git a/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts b/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts
index 94473e35a942d5..f6455d0c1e43f4 100644
--- a/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts
+++ b/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts
@@ -21,7 +21,7 @@ import { SavedObjectMigrationFn } from 'kibana/server';
import { cloneDeep, get, omit, has, flow } from 'lodash';
import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';
-const migrateIndexPattern: SavedObjectMigrationFn = doc => {
+const migrateIndexPattern: SavedObjectMigrationFn = doc => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
if (typeof searchSourceJSON !== 'string') {
return doc;
@@ -64,7 +64,7 @@ const migrateIndexPattern: SavedObjectMigrationFn = doc => {
};
// [TSVB] Migrate percentile-rank aggregation (value -> values)
-const migratePercentileRankAggregation: SavedObjectMigrationFn = doc => {
+const migratePercentileRankAggregation: SavedObjectMigrationFn = doc => {
const visStateJSON = get(doc, 'attributes.visState');
let visState;
@@ -100,7 +100,7 @@ const migratePercentileRankAggregation: SavedObjectMigrationFn = doc => {
};
// [TSVB] Remove stale opperator key
-const migrateOperatorKeyTypo: SavedObjectMigrationFn = doc => {
+const migrateOperatorKeyTypo: SavedObjectMigrationFn = doc => {
const visStateJSON = get(doc, 'attributes.visState');
let visState;
@@ -132,7 +132,7 @@ const migrateOperatorKeyTypo: SavedObjectMigrationFn = doc => {
};
// Migrate date histogram aggregation (remove customInterval)
-const migrateDateHistogramAggregation: SavedObjectMigrationFn = doc => {
+const migrateDateHistogramAggregation: SavedObjectMigrationFn = doc => {
const visStateJSON = get(doc, 'attributes.visState');
let visState;
@@ -174,7 +174,7 @@ const migrateDateHistogramAggregation: SavedObjectMigrationFn = doc => {
return doc;
};
-const removeDateHistogramTimeZones: SavedObjectMigrationFn = doc => {
+const removeDateHistogramTimeZones: SavedObjectMigrationFn = doc => {
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
let visState;
@@ -206,7 +206,7 @@ const removeDateHistogramTimeZones: SavedObjectMigrationFn = doc => {
// migrate gauge verticalSplit to alignment
// https://github.com/elastic/kibana/issues/34636
-const migrateGaugeVerticalSplitToAlignment: SavedObjectMigrationFn = (doc, logger) => {
+const migrateGaugeVerticalSplitToAlignment: SavedObjectMigrationFn = (doc, logger) => {
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
@@ -241,7 +241,7 @@ const migrateGaugeVerticalSplitToAlignment: SavedObjectMigrationFn = (doc, logge
Path to the series array is thus:
attributes.visState.
*/
-const transformFilterStringToQueryObject: SavedObjectMigrationFn = (doc, logger) => {
+const transformFilterStringToQueryObject: SavedObjectMigrationFn = (doc, logger) => {
// Migrate filters
// If any filters exist and they are a string, we assume it to be lucene and transform the filter into an object accordingly
const newDoc = cloneDeep(doc);
@@ -325,7 +325,7 @@ const transformFilterStringToQueryObject: SavedObjectMigrationFn = (doc, logger)
return newDoc;
};
-const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn = doc => {
+const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn = doc => {
// Migrate split_filters in TSVB objects that weren't migrated in 7.3
// If any filters exist and they are a string, we assume them to be lucene syntax and transform the filter into an object accordingly
const newDoc = cloneDeep(doc);
@@ -370,7 +370,7 @@ const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn = doc =>
return newDoc;
};
-const migrateFiltersAggQuery: SavedObjectMigrationFn = doc => {
+const migrateFiltersAggQuery: SavedObjectMigrationFn = doc => {
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
@@ -402,7 +402,7 @@ const migrateFiltersAggQuery: SavedObjectMigrationFn = doc => {
return doc;
};
-const replaceMovAvgToMovFn: SavedObjectMigrationFn = (doc, logger) => {
+const replaceMovAvgToMovFn: SavedObjectMigrationFn = (doc, logger) => {
const visStateJSON = get(doc, 'attributes.visState');
let visState;
@@ -450,7 +450,7 @@ const replaceMovAvgToMovFn: SavedObjectMigrationFn = (doc, logger) => {
return doc;
};
-const migrateFiltersAggQueryStringQueries: SavedObjectMigrationFn = (doc, logger) => {
+const migrateFiltersAggQueryStringQueries: SavedObjectMigrationFn = (doc, logger) => {
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
@@ -483,12 +483,12 @@ const migrateFiltersAggQueryStringQueries: SavedObjectMigrationFn = (doc, logger
return doc;
};
-const addDocReferences: SavedObjectMigrationFn = doc => ({
+const addDocReferences: SavedObjectMigrationFn = doc => ({
...doc,
references: doc.references || [],
});
-const migrateSavedSearch: SavedObjectMigrationFn = doc => {
+const migrateSavedSearch: SavedObjectMigrationFn = doc => {
const savedSearchId = get(doc, 'attributes.savedSearchId');
if (savedSearchId && doc.references) {
@@ -505,7 +505,7 @@ const migrateSavedSearch: SavedObjectMigrationFn = doc => {
return doc;
};
-const migrateControls: SavedObjectMigrationFn = doc => {
+const migrateControls: SavedObjectMigrationFn = doc => {
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
@@ -536,7 +536,7 @@ const migrateControls: SavedObjectMigrationFn = doc => {
return doc;
};
-const migrateTableSplits: SavedObjectMigrationFn = doc => {
+const migrateTableSplits: SavedObjectMigrationFn = doc => {
try {
const visState = JSON.parse(doc.attributes.visState);
if (get(visState, 'type') !== 'table') {
@@ -572,7 +572,7 @@ const migrateTableSplits: SavedObjectMigrationFn = doc => {
}
};
-const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
+const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
if (searchSourceJSON) {
@@ -606,7 +606,7 @@ const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
};
// [TSVB] Default color palette is changing, keep the default for older viz
-const migrateTsvbDefaultColorPalettes: SavedObjectMigrationFn = doc => {
+const migrateTsvbDefaultColorPalettes: SavedObjectMigrationFn = doc => {
const visStateJSON = get(doc, 'attributes.visState');
let visState;
@@ -649,27 +649,30 @@ export const visualizationSavedObjectTypeMigrations = {
* in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
* only contained the 6.7.2 migration and not the 7.0.1 migration.
*/
- '6.7.2': flow(migrateMatchAllQuery, removeDateHistogramTimeZones),
- '7.0.0': flow(
+ '6.7.2': flow>(
+ migrateMatchAllQuery,
+ removeDateHistogramTimeZones
+ ),
+ '7.0.0': flow>(
addDocReferences,
migrateIndexPattern,
migrateSavedSearch,
migrateControls,
migrateTableSplits
),
- '7.0.1': flow(removeDateHistogramTimeZones),
- '7.2.0': flow(
+ '7.0.1': flow>(removeDateHistogramTimeZones),
+ '7.2.0': flow>(
migratePercentileRankAggregation,
migrateDateHistogramAggregation
),
- '7.3.0': flow(
+ '7.3.0': flow>(
migrateGaugeVerticalSplitToAlignment,
transformFilterStringToQueryObject,
migrateFiltersAggQuery,
replaceMovAvgToMovFn
),
- '7.3.1': flow(migrateFiltersAggQueryStringQueries),
- '7.4.2': flow(transformSplitFiltersStringToQueryObject),
- '7.7.0': flow(migrateOperatorKeyTypo),
- '7.8.0': flow(migrateTsvbDefaultColorPalettes),
+ '7.3.1': flow>(migrateFiltersAggQueryStringQueries),
+ '7.4.2': flow>(transformSplitFiltersStringToQueryObject),
+ '7.7.0': flow>(migrateOperatorKeyTypo),
+ '7.8.0': flow>(migrateTsvbDefaultColorPalettes),
};
diff --git a/x-pack/plugins/graph/server/saved_objects/migrations.ts b/x-pack/plugins/graph/server/saved_objects/migrations.ts
index e77d2ea0fb7c97..beb31d548c6702 100644
--- a/x-pack/plugins/graph/server/saved_objects/migrations.ts
+++ b/x-pack/plugins/graph/server/saved_objects/migrations.ts
@@ -8,7 +8,7 @@ import { get } from 'lodash';
import { SavedObjectUnsanitizedDoc } from 'kibana/server';
export const graphMigrations = {
- '7.0.0': (doc: SavedObjectUnsanitizedDoc) => {
+ '7.0.0': (doc: SavedObjectUnsanitizedDoc) => {
// Set new "references" attribute
doc.references = doc.references || [];
// Migrate index pattern
diff --git a/x-pack/plugins/lens/server/migrations.ts b/x-pack/plugins/lens/server/migrations.ts
index 3d238723b7438c..25a63a26e254ba 100644
--- a/x-pack/plugins/lens/server/migrations.ts
+++ b/x-pack/plugins/lens/server/migrations.ts
@@ -14,7 +14,8 @@ interface XYLayerPre77 {
accessors: string[];
}
-export const migrations: Record = {
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export const migrations: Record> = {
'7.7.0': doc => {
const newDoc = cloneDeep(doc);
if (newDoc.attributes?.visualizationType === 'lnsXY') {
diff --git a/x-pack/plugins/spaces/server/saved_objects/migrations/migrate_6x.ts b/x-pack/plugins/spaces/server/saved_objects/migrations/migrate_6x.ts
index b063404f68e4fb..65a810ff94a1f5 100644
--- a/x-pack/plugins/spaces/server/saved_objects/migrations/migrate_6x.ts
+++ b/x-pack/plugins/spaces/server/saved_objects/migrations/migrate_6x.ts
@@ -6,7 +6,7 @@
import { SavedObjectMigrationFn } from 'src/core/server';
-export const migrateToKibana660: SavedObjectMigrationFn = doc => {
+export const migrateToKibana660: SavedObjectMigrationFn = doc => {
if (!doc.attributes.hasOwnProperty('disabledFeatures')) {
doc.attributes.disabledFeatures = [];
}