mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* Throw error when migration not defined in same plugin as mappings * Apply PR feedback
This commit is contained in:
parent
794a97cb9d
commit
53ab2c7beb
2 changed files with 64 additions and 2 deletions
|
@ -90,5 +90,48 @@ describe('plugin discovery', () => {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
it(`throws an error when migrations and mappings aren't defined in the same plugin`, () => {
|
||||
const invalidSpecs = new PluginPack({
|
||||
path: '/dev/null',
|
||||
pkg: {
|
||||
name: 'test',
|
||||
version: 'kibana',
|
||||
},
|
||||
provider({ Plugin }) {
|
||||
return [
|
||||
new Plugin({
|
||||
id: 'test',
|
||||
uiExports: {
|
||||
mappings: {
|
||||
'test-type': {
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
new Plugin({
|
||||
id: 'test2',
|
||||
uiExports: {
|
||||
migrations: {
|
||||
'test-type': {
|
||||
'1.2.3': (doc) => {
|
||||
return doc;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
];
|
||||
},
|
||||
}).getPluginSpecs();
|
||||
expect(
|
||||
() => collectUiExports(invalidSpecs),
|
||||
).to.throwError((err) => {
|
||||
expect(err).to.be.a(Error);
|
||||
expect(err).to.have.property('message', 'Migrations and mappings must be defined together in the uiExports of a single plugin. ' +
|
||||
'test2 defines migrations for types test-type but does not define their mappings.');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,10 +30,29 @@ export const mappings = wrap(
|
|||
flatConcatAtType
|
||||
);
|
||||
|
||||
const pluginId = (pluginSpec) => pluginSpec.id ? pluginSpec.id() : pluginSpec.getId();
|
||||
|
||||
// Combines the `migrations` property of each plugin,
|
||||
// ensuring that properties are unique across plugins.
|
||||
// ensuring that properties are unique across plugins
|
||||
// and has migrations defined where the mappings are defined.
|
||||
// See saved_objects/migrations for more details.
|
||||
export const migrations = wrap(alias('savedObjectMigrations'), uniqueKeys(), mergeAtType);
|
||||
export const migrations = wrap(
|
||||
alias('savedObjectMigrations'),
|
||||
(next) => (acc, spec, type, pluginSpec) => {
|
||||
const mappings = pluginSpec.getExportSpecs().mappings || {};
|
||||
const invalidMigrationTypes = Object.keys(spec)
|
||||
.filter(type => !mappings[type]);
|
||||
if (invalidMigrationTypes.length) {
|
||||
throw new Error(
|
||||
'Migrations and mappings must be defined together in the uiExports of a single plugin. ' +
|
||||
`${pluginId(pluginSpec)} defines migrations for types ${invalidMigrationTypes.join(', ')} but does not define their mappings.`
|
||||
);
|
||||
}
|
||||
return next(acc, spec, type, pluginSpec);
|
||||
},
|
||||
uniqueKeys(),
|
||||
mergeAtType,
|
||||
);
|
||||
|
||||
export const savedObjectSchemas = wrap(uniqueKeys(), mergeAtType);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue