-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] embeddable migrations (#101070)
* [Maps] embeddable migrations * review feedback Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
8f83090
commit 93df9a3
Showing
8 changed files
with
259 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import semverGte from 'semver/functions/gte'; | ||
import { embeddableMigrations } from './embeddable_migrations'; | ||
// @ts-ignore | ||
import { savedObjectMigrations } from './saved_objects/saved_object_migrations'; | ||
|
||
describe('saved object migrations and embeddable migrations', () => { | ||
test('should have same versions registered (>7.12)', () => { | ||
const savedObjectMigrationVersions = Object.keys(savedObjectMigrations).filter((version) => { | ||
return semverGte(version, '7.13.0'); | ||
}); | ||
const embeddableMigrationVersions = Object.keys(embeddableMigrations); | ||
expect(savedObjectMigrationVersions.sort()).toEqual(embeddableMigrationVersions.sort()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { SerializableState } from '../../../../src/plugins/kibana_utils/common'; | ||
import { MapSavedObjectAttributes } from '../common/map_saved_object_type'; | ||
import { moveAttribution } from '../common/migrations/move_attribution'; | ||
|
||
/* | ||
* Embeddables such as Maps, Lens, and Visualize can be embedded by value or by reference on a dashboard. | ||
* To ensure that any migrations (>7.12) are run correctly in both cases, | ||
* the migration function must be registered as both a saved object migration and an embeddable migration | ||
* This is the embeddable migration registry. | ||
*/ | ||
export const embeddableMigrations = { | ||
'7.14.0': (state: SerializableState) => { | ||
return { | ||
...state, | ||
attributes: moveAttribution(state as { attributes: MapSavedObjectAttributes }), | ||
} as SerializableState; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
x-pack/plugins/maps/server/saved_objects/saved_object_migrations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { extractReferences } from '../../common/migrations/references'; | ||
import { emsRasterTileToEmsVectorTile } from '../../common/migrations/ems_raster_tile_to_ems_vector_tile'; | ||
import { topHitsTimeToSort } from '../../common/migrations/top_hits_time_to_sort'; | ||
import { moveApplyGlobalQueryToSources } from '../../common/migrations/move_apply_global_query'; | ||
import { addFieldMetaOptions } from '../../common/migrations/add_field_meta_options'; | ||
import { migrateSymbolStyleDescriptor } from '../../common/migrations/migrate_symbol_style_descriptor'; | ||
import { migrateUseTopHitsToScalingType } from '../../common/migrations/scaling_type'; | ||
import { migrateJoinAggKey } from '../../common/migrations/join_agg_key'; | ||
import { removeBoundsFromSavedObject } from '../../common/migrations/remove_bounds'; | ||
import { setDefaultAutoFitToBounds } from '../../common/migrations/set_default_auto_fit_to_bounds'; | ||
import { addTypeToTermJoin } from '../../common/migrations/add_type_to_termjoin'; | ||
import { moveAttribution } from '../../common/migrations/move_attribution'; | ||
|
||
/* | ||
* Embeddables such as Maps, Lens, and Visualize can be embedded by value or by reference on a dashboard. | ||
* To ensure that any migrations (>7.12) are run correctly in both cases, | ||
* the migration function must be registered as both a saved object migration and an embeddable migration | ||
* This is the saved object migration registry. | ||
*/ | ||
export const savedObjectMigrations = { | ||
'7.2.0': (doc) => { | ||
const { attributes, references } = extractReferences(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
references, | ||
}; | ||
}, | ||
'7.4.0': (doc) => { | ||
const attributes = emsRasterTileToEmsVectorTile(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
}; | ||
}, | ||
'7.5.0': (doc) => { | ||
const attributes = topHitsTimeToSort(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
}; | ||
}, | ||
'7.6.0': (doc) => { | ||
const attributesPhase1 = moveApplyGlobalQueryToSources(doc); | ||
const attributesPhase2 = addFieldMetaOptions({ attributes: attributesPhase1 }); | ||
|
||
return { | ||
...doc, | ||
attributes: attributesPhase2, | ||
}; | ||
}, | ||
'7.7.0': (doc) => { | ||
const attributesPhase1 = migrateSymbolStyleDescriptor(doc); | ||
const attributesPhase2 = migrateUseTopHitsToScalingType({ attributes: attributesPhase1 }); | ||
|
||
return { | ||
...doc, | ||
attributes: attributesPhase2, | ||
}; | ||
}, | ||
'7.8.0': (doc) => { | ||
const attributes = migrateJoinAggKey(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
}; | ||
}, | ||
'7.9.0': (doc) => { | ||
const attributes = removeBoundsFromSavedObject(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
}; | ||
}, | ||
'7.10.0': (doc) => { | ||
const attributes = setDefaultAutoFitToBounds(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
}; | ||
}, | ||
'7.12.0': (doc) => { | ||
const attributes = addTypeToTermJoin(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
}; | ||
}, | ||
'7.14.0': (doc) => { | ||
const attributes = moveAttribution(doc); | ||
|
||
return { | ||
...doc, | ||
attributes, | ||
}; | ||
}, | ||
}; |
Oops, something went wrong.