[Graph] Make Graph saved object share-capable (#111404)

* [graph] Make Graph saved object share-capable

Step 4 of https://www.elastic.co/guide/en/kibana/master/sharing-saved-objects.html#sharing-saved-objects-faq-changing-object-ids

* bump migration version to fix the test

* test

* Revert "bump migration version to fix the test"

This reverts commit 04d2f49386.

* Revert "test"

This reverts commit 7b0a74d431.

* Fix Core migration integration tests

The existing tests incorrectly asserted an object's `migrationVersion`
solely based on the registered type's `migration` field; in reality, the
`convertToMultiNamespaceTypeVersion` field is also used when determining
an object's `migrationVersion`. This commit simply updates the test to
reflect that.

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Marta Bondyra 2021-09-13 08:42:07 +02:00 committed by GitHub
parent 3c6cfb6c99
commit f9f90705f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -118,18 +118,23 @@ describe('migration v2', () => {
.getTypeRegistry()
.getAllTypes()
.reduce((versionMap, type) => {
if (type.migrations) {
const migrationsMap =
typeof type.migrations === 'function' ? type.migrations() : type.migrations;
const highestVersion = Object.keys(migrationsMap).sort(Semver.compare).reverse()[0];
const { name, migrations, convertToMultiNamespaceTypeVersion } = type;
if (migrations || convertToMultiNamespaceTypeVersion) {
const migrationsMap = typeof migrations === 'function' ? migrations() : migrations;
const migrationsKeys = migrationsMap ? Object.keys(migrationsMap) : [];
if (convertToMultiNamespaceTypeVersion) {
// Setting this option registers a conversion migration that is reflected in the object's `migrationVersions` field
migrationsKeys.push(convertToMultiNamespaceTypeVersion);
}
const highestVersion = migrationsKeys.sort(Semver.compare).reverse()[0];
return {
...versionMap,
[type.name]: highestVersion,
[name]: highestVersion,
};
} else {
return {
...versionMap,
[type.name]: undefined,
[name]: undefined,
};
}
}, {} as Record<string, string | undefined>);

View file

@ -10,7 +10,8 @@ import { graphMigrations } from './migrations';
export const graphWorkspace: SavedObjectsType = {
name: 'graph-workspace',
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
hidden: false,
management: {
icon: 'graphApp',