diff --git a/src/plugins/saved_objects/README.md b/src/plugins/saved_objects/README.md index 55f9c219879c..3b6dc4f7a79c 100644 --- a/src/plugins/saved_objects/README.md +++ b/src/plugins/saved_objects/README.md @@ -1,6 +1,6 @@ # Saved object -The saved object plugin provides all the core services and functionalities of saved objects. It is utilized by many core plugins such as [`visualization`](../visualizations/), [`dashboard`](../dashboard/) and [`visBuilder`](../visBuilder/), as well as external plugins. Saved object is the primary way to store app and plugin data in a standardized form in OpenSearch Dashboards. They allow plugin developers to manage creating, saving, editing and retrieving data for the application. They can also make reference to other saved objects and have useful features out of the box, such as migrations and strict typings. The saved objects can be managed by the Saved Object Management UI. +The saved object plugin provides all the core services and functionalities of saved objects. It is utilized by many core plugins such as [`visualization`](../visualizations/), [`dashboard`](../dashboard/) and [`visBuilder`](../vis_builder/), as well as external plugins. Saved object is the primary way to store app and plugin data in a standardized form in OpenSearch Dashboards. They allow plugin developers to manage creating, saving, editing and retrieving data for the application. They can also make reference to other saved objects and have useful features out of the box, such as migrations and strict typings. The saved objects can be managed by the Saved Object Management UI. ## Save relationships to index pattern diff --git a/src/plugins/vis_builder/server/saved_objects/vis_builder_app.ts b/src/plugins/vis_builder/server/saved_objects/vis_builder_app.ts index 4769aad73659..15d785b3b451 100644 --- a/src/plugins/vis_builder/server/saved_objects/vis_builder_app.ts +++ b/src/plugins/vis_builder/server/saved_objects/vis_builder_app.ts @@ -10,7 +10,6 @@ import { VisBuilderSavedObjectAttributes, VISBUILDER_SAVED_OBJECT, } from '../../common'; -import { visBuilderSavedObjectTypeMigrations } from './vis_builder_migration'; export const visBuilderSavedObjectType: SavedObjectsType = { name: VISBUILDER_SAVED_OBJECT, @@ -30,7 +29,7 @@ export const visBuilderSavedObjectType: SavedObjectsType = { }; }, }, - migrations: visBuilderSavedObjectTypeMigrations, + migrations: {}, mappings: { properties: { title: { diff --git a/src/plugins/vis_builder/server/saved_objects/vis_builder_migration.test.ts b/src/plugins/vis_builder/server/saved_objects/vis_builder_migration.test.ts deleted file mode 100644 index e15b1e60e9fa..000000000000 --- a/src/plugins/vis_builder/server/saved_objects/vis_builder_migration.test.ts +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { SavedObjectMigrationFn, SavedObjectMigrationContext } from '../../../../core/server'; -import { visBuilderSavedObjectTypeMigrations } from './vis_builder_migration'; - -const savedObjectMigrationContext = (null as unknown) as SavedObjectMigrationContext; - -describe('2.3.0', () => { - const migrate = (doc: any) => - visBuilderSavedObjectTypeMigrations['2.3.0']( - doc as Parameters[0], - savedObjectMigrationContext - ); - - it('should return original doc if visualizationState is not found', () => { - const migratedDoc = migrate({ - type: 'visBuilder', - attributes: {}, - }); - - expect(migratedDoc).toEqual({ - type: 'visBuilder', - attributes: {}, - }); - }); - - it('should return original doc if indexPattern is not found within visualizationState', () => { - const migratedDoc = migrate({ - type: 'visBuilder', - attributes: { - visualizationState: { - searchSource: '', - activeVisualization: {}, - }, - }, - }); - - expect(migratedDoc).toEqual({ - type: 'visBuilder', - attributes: { - visualizationState: { - searchSource: '', - activeVisualization: {}, - }, - }, - }); - }); - - it('should return original doc if references is not an array', () => { - const migratedDoc = migrate({ - type: 'visBuilder', - attributes: { - visualizationState: {}, - }, - references: {}, - }); - - expect(migratedDoc).toEqual({ - type: 'visBuilder', - attributes: { - visualizationState: {}, - }, - references: {}, - }); - }); - - it('should migrate the old version visBuilder saved object to new version VisBuilder saved object', () => { - const migratedDoc = migrate({ - type: 'visBuilder', - attributes: { - visualizationState: JSON.stringify({ - searchFields: {}, - activeVisualization: {}, - indexPattern: 'indexPatternId', - }), - version: 1, - }, - references: [], - }); - - expect(migratedDoc).toEqual({ - type: 'visBuilder', - attributes: { - visualizationState: JSON.stringify({ - searchFields: {}, - activeVisualization: {}, - }), - version: 2, - kibanaSavedObjectMeta: { - searchSourceJSON: JSON.stringify({ - indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index', - }), - }, - }, - references: [ - { - name: 'kibanaSavedObjectMeta.searchSourceJSON.index', - type: 'index-pattern', - id: 'indexPatternId', - }, - ], - }); - }); -}); diff --git a/src/plugins/vis_builder/server/saved_objects/vis_builder_migration.ts b/src/plugins/vis_builder/server/saved_objects/vis_builder_migration.ts deleted file mode 100644 index c3a14575d4a4..000000000000 --- a/src/plugins/vis_builder/server/saved_objects/vis_builder_migration.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { get, flow } from 'lodash'; -import { SavedObjectMigrationFn } from '../../../../core/server'; - -const migrateIndexPattern: SavedObjectMigrationFn = (doc) => { - try { - const visualizationStateJSON = get(doc, 'attributes.visualizationState'); - const visualizationState = JSON.parse(visualizationStateJSON); - const indexPatternId = visualizationState.indexPattern; - const indexRefName = 'kibanaSavedObjectMeta.searchSourceJSON.index'; - - if (indexPatternId && Array.isArray(doc.references)) { - const searchSourceIndex = { - indexRefName, - }; - const visualizationWithoutIndex = { - searchFields: visualizationState.searchFields, - activeVisualization: visualizationState.activeVisualization, - }; - doc.attributes.visualizationState = JSON.stringify(visualizationWithoutIndex); - - doc.references.push({ - name: indexRefName, - type: 'index-pattern', - id: indexPatternId, - }); - doc.attributes.version = 2; - - return { - ...doc, - attributes: { - ...doc.attributes, - kibanaSavedObjectMeta: { - searchSourceJSON: JSON.stringify(searchSourceIndex), - }, - }, - }; - } - return doc; - } catch (e) { - return doc; - } -}; - -// TODO: add migration to change the saved object type from wizard to visBuilder - -export const visBuilderSavedObjectTypeMigrations = { - '2.3.0': flow(migrateIndexPattern), -};