@@ -78,6 +78,8 @@ import { SavedObjectMigrationFn } from '../types';
7878import { DEFAULT_NAMESPACE_STRING } from '../../service/lib/utils' ;
7979import { LegacyUrlAlias , LEGACY_URL_ALIAS_TYPE } from '../../object_types' ;
8080
81+ const DEFAULT_MINIMUM_CONVERT_VERSION = '8.0.0' ;
82+
8183export type MigrateFn = ( doc : SavedObjectUnsanitizedDoc ) => SavedObjectUnsanitizedDoc ;
8284export type MigrateAndConvertFn = ( doc : SavedObjectUnsanitizedDoc ) => SavedObjectUnsanitizedDoc [ ] ;
8385
@@ -105,6 +107,7 @@ interface TransformOptions {
105107interface DocumentMigratorOptions {
106108 kibanaVersion : string ;
107109 typeRegistry : ISavedObjectTypeRegistry ;
110+ minimumConvertVersion ?: string ;
108111 log : Logger ;
109112}
110113
@@ -159,11 +162,17 @@ export class DocumentMigrator implements VersionedTransformer {
159162 * @param {DocumentMigratorOptions } opts
160163 * @prop {string } kibanaVersion - The current version of Kibana
161164 * @prop {SavedObjectTypeRegistry } typeRegistry - The type registry to get type migrations from
165+ * @prop {string } minimumConvertVersion - The minimum version of Kibana in which documents can be converted to multi-namespace types
162166 * @prop {Logger } log - The migration logger
163167 * @memberof DocumentMigrator
164168 */
165- constructor ( { typeRegistry, kibanaVersion, log } : DocumentMigratorOptions ) {
166- validateMigrationDefinition ( typeRegistry , kibanaVersion ) ;
169+ constructor ( {
170+ typeRegistry,
171+ kibanaVersion,
172+ minimumConvertVersion = DEFAULT_MINIMUM_CONVERT_VERSION ,
173+ log,
174+ } : DocumentMigratorOptions ) {
175+ validateMigrationDefinition ( typeRegistry , kibanaVersion , minimumConvertVersion ) ;
167176
168177 this . migrations = buildActiveMigrations ( typeRegistry , log ) ;
169178 this . transformDoc = buildDocumentTransform ( {
@@ -231,7 +240,11 @@ export class DocumentMigrator implements VersionedTransformer {
231240 * language. So, this is just to provide a little developer-friendly error messaging. Joi was
232241 * giving weird errors, so we're just doing manual validation.
233242 */
234- function validateMigrationDefinition ( registry : ISavedObjectTypeRegistry , kibanaVersion : string ) {
243+ function validateMigrationDefinition (
244+ registry : ISavedObjectTypeRegistry ,
245+ kibanaVersion : string ,
246+ minimumConvertVersion : string
247+ ) {
235248 function assertObject ( obj : any , prefix : string ) {
236249 if ( ! obj || typeof obj !== 'object' ) {
237250 throw new Error ( `${ prefix } Got ${ obj } .` ) ;
@@ -270,6 +283,10 @@ function validateMigrationDefinition(registry: ISavedObjectTypeRegistry, kibanaV
270283 throw new Error (
271284 `Invalid convertToMultiNamespaceTypeVersion for type ${ type } . Expected value to be a semver, but got '${ convertToMultiNamespaceTypeVersion } '.`
272285 ) ;
286+ } else if ( Semver . lt ( convertToMultiNamespaceTypeVersion , minimumConvertVersion ) ) {
287+ throw new Error (
288+ `Invalid convertToMultiNamespaceTypeVersion for type ${ type } . Value '${ convertToMultiNamespaceTypeVersion } ' cannot be less than '${ minimumConvertVersion } '.`
289+ ) ;
273290 } else if ( Semver . gt ( convertToMultiNamespaceTypeVersion , kibanaVersion ) ) {
274291 throw new Error (
275292 `Invalid convertToMultiNamespaceTypeVersion for type ${ type } . Value '${ convertToMultiNamespaceTypeVersion } ' cannot be greater than the current Kibana version '${ kibanaVersion } '.`
0 commit comments