mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Saved Objects] Fix document migrator to prevent losing namespaces on import (#164848)
This commit is contained in:
parent
e3af1246cf
commit
ac73d1f6b2
2 changed files with 37 additions and 0 deletions
|
@ -713,6 +713,36 @@ describe('DocumentMigrator', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('does not lose namespaces in documents with undefined namespace and defined namespaces property', () => {
|
||||
const migrator = new DocumentMigrator({
|
||||
...testOpts(),
|
||||
typeRegistry: createRegistry(
|
||||
{ name: 'dog', namespaceType: 'multiple', convertToMultiNamespaceTypeVersion: '1.0.0' }
|
||||
// no migration transforms are defined, the typeMigrationVersion will be derived from 'convertToMultiNamespaceTypeVersion'
|
||||
),
|
||||
});
|
||||
migrator.prepareMigrations();
|
||||
const obj = {
|
||||
id: 'mischievous',
|
||||
type: 'dog',
|
||||
attributes: { name: 'Ann' },
|
||||
coreMigrationVersion: kibanaVersion,
|
||||
typeMigrationVersion: '0.1.0',
|
||||
namespaces: ['something'],
|
||||
} as SavedObjectUnsanitizedDoc;
|
||||
const actual = migrator.migrateAndConvert(obj);
|
||||
expect(actual).toEqual([
|
||||
{
|
||||
id: 'mischievous',
|
||||
type: 'dog',
|
||||
attributes: { name: 'Ann' },
|
||||
coreMigrationVersion: kibanaVersion,
|
||||
typeMigrationVersion: '1.0.0',
|
||||
namespaces: ['something'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not fail when encountering documents with coreMigrationVersion higher than the latest known', () => {
|
||||
const migrator = new DocumentMigrator({
|
||||
...testOpts(),
|
||||
|
|
|
@ -105,6 +105,13 @@ function convertNamespaceType(doc: SavedObjectUnsanitizedDoc) {
|
|||
const { namespace, ...otherAttrs } = doc;
|
||||
const additionalDocs: SavedObjectUnsanitizedDoc[] = [];
|
||||
|
||||
if (namespace == null && otherAttrs.namespaces) {
|
||||
return {
|
||||
additionalDocs,
|
||||
transformedDoc: otherAttrs,
|
||||
};
|
||||
}
|
||||
|
||||
// If this object exists in the default namespace, return it with the appropriate `namespaces` field without changing its ID.
|
||||
if (namespace === undefined) {
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue