From fe6bd7d1d7a420268d1f7789a0605a3cfaf81f9d Mon Sep 17 00:00:00 2001 From: abbyhu2000 Date: Fri, 28 Oct 2022 00:05:02 +0000 Subject: [PATCH] Delete migration Signed-off-by: abbyhu2000 --- .../server/saved_objects/vis_builder_app.ts | 3 +- .../vis_builder_migration.test.ts | 107 ------------------ .../saved_objects/vis_builder_migration.ts | 53 --------- 3 files changed, 1 insertion(+), 162 deletions(-) delete mode 100644 src/plugins/vis_builder/server/saved_objects/vis_builder_migration.test.ts delete mode 100644 src/plugins/vis_builder/server/saved_objects/vis_builder_migration.ts 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), -};