diff --git a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.test.ts b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.test.ts index 0d12a501f86b1..06b09e15951c4 100644 --- a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.test.ts @@ -19,7 +19,7 @@ jest.mock('timers/promises', () => ({ async setTimeout() {}, })); -import { installKibanaSavedObjects } from './install'; +import { createSavedObjectKibanaAsset, installKibanaSavedObjects } from './install'; const mockLogger = loggingSystemMock.createLogger(); @@ -122,3 +122,27 @@ describe('installKibanaSavedObjects', () => { expect(mockImporter.resolveImportErrors).toHaveBeenCalledTimes(1); }); }); + +describe('createSavedObjectKibanaAsset', () => { + it('should set migrationVersion as typeMigrationVersion in so', () => { + const asset = createAsset({ + attributes: { hello: 'world' }, + migrationVersion: { dashboard: '8.6.0' }, + }); + const result = createSavedObjectKibanaAsset(asset); + + expect(result.typeMigrationVersion).toEqual('8.6.0'); + }); + + it('should set coreMigrationVersion and typeMigrationVersion in so', () => { + const asset = createAsset({ + attributes: { hello: 'world' }, + typeMigrationVersion: '8.6.0', + coreMigrationVersion: '8.7.0', + }); + const result = createSavedObjectKibanaAsset(asset); + + expect(result.typeMigrationVersion).toEqual('8.6.0'); + expect(result.coreMigrationVersion).toEqual('8.7.0'); + }); +}); diff --git a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts index fdeb75480ea79..1c804991cbeaf 100644 --- a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts @@ -53,7 +53,7 @@ export type ArchiveAsset = Pick< SavedObject, | 'id' | 'attributes' - | 'migrationVersion' + | 'migrationVersion' // deprecated | 'references' | 'coreMigrationVersion' | 'typeMigrationVersion' @@ -99,8 +99,9 @@ export function createSavedObjectKibanaAsset(asset: ArchiveAsset): SavedObjectTo references: asset.references || [], }; - if (asset.migrationVersion) { - so.migrationVersion = asset.migrationVersion; + // migrating deprecated migrationVersion to typeMigrationVersion + if (asset.migrationVersion && asset.migrationVersion[asset.type]) { + so.typeMigrationVersion = asset.migrationVersion[asset.type]; } if (asset.coreMigrationVersion) { so.coreMigrationVersion = asset.coreMigrationVersion;