Skip to content

Commit

Permalink
Create a migration function for datasource to add migrationVersion fi…
Browse files Browse the repository at this point in the history
…eld (#6025) (#6046)
  • Loading branch information
opensearch-trigger-bot[bot] committed Mar 6, 2024
1 parent 0cad69d commit 293adfb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/plugins/data_source/server/saved_objects/data_source.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { migrateDataSource } from './data_source';
import { savedObjectsServiceMock } from '../../../../core/server/mocks';

const contextMock = savedObjectsServiceMock.createMigrationContext();

describe('migrateDataSource Function', () => {
it('should return the input document unchanged', () => {
const mockDoc = {
id: 'test-id',
type: 'test-type',
attributes: {
name: 'Test Name',
description: 'Test Description',
},
references: [],
};

// Call the migrateDataSource function with the mock document
const result = migrateDataSource(mockDoc, contextMock);

// Expect the result to be deeply equal to the mock document
expect(result).toEqual(mockDoc);
});
});
11 changes: 10 additions & 1 deletion src/plugins/data_source/server/saved_objects/data_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SavedObjectsType } from 'opensearch-dashboards/server';
import { flow } from 'lodash';
import { SavedObjectMigrationFn, SavedObjectsType } from 'opensearch-dashboards/server';

// create a migration function which return the doc without any changes
export const migrateDataSource: SavedObjectMigrationFn<any, any> = (doc) => ({
...doc,
});

export const dataSource: SavedObjectsType = {
name: 'data-source',
Expand Down Expand Up @@ -34,4 +40,7 @@ export const dataSource: SavedObjectsType = {
},
},
},
migrations: {
'2.4.0': flow(migrateDataSource), // 2.4.0 is the version that introduces the datasource
},
};

0 comments on commit 293adfb

Please sign in to comment.