Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a migration function for datasource to add migrationVersion field #6025

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [osd/std] Add additional recovery from false-positives in handling of long numerals ([#5956](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5956))
- [BUG][Discover] Allow saved sort from search embeddable to load in Dashboard ([#5934](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5934))
- [BUG][Multiple Datasource] Fix missing customApiRegistryPromise param for test connection ([#5944](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5944))
- [BUG][Multiple Datasource] Add a migration function for datasource to add migrationVersion field ([#6022](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6025)

### 🚞 Infrastructure

Expand Down
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: {
yibow98 marked this conversation as resolved.
Show resolved Hide resolved
'2.4.0': flow(migrateDataSource), // 2.4.0 is the version that introduces the datasource
},
};
Loading