diff --git a/dev_docs/tutorials/saved_objects.mdx b/dev_docs/tutorials/saved_objects.mdx index 71b99e2ae5e7e..542eed50733b5 100644 --- a/dev_docs/tutorials/saved_objects.mdx +++ b/dev_docs/tutorials/saved_objects.mdx @@ -19,8 +19,7 @@ import { SavedObjectsType } from 'src/core/server'; export const dashboardVisualization: SavedObjectsType = { name: 'dashboard_visualization', [1] hidden: true, [3] - switchToModelVersionAt: '8.10.0', // this is the default, feel free to omit it unless you intend to switch to using model versions before 8.10.0 - namespaceType: 'multiple-isolated', [2] + namespaceType: 'multiple-isolated', [2] mappings: { dynamic: false, properties: { diff --git a/docs/extend/saved-objects-service.md b/docs/extend/saved-objects-service.md index d883aafc2a0b5..b757a126d9e2d 100644 --- a/docs/extend/saved-objects-service.md +++ b/docs/extend/saved-objects-service.md @@ -38,7 +38,6 @@ export const dashboardVisualization: SavedObjectsType = { name: 'dashboard_visualization', <1> hidden: true, namespaceType: 'multiple-isolated', <2> - switchToModelVersionAt: '8.10.0', modelVersions: { 1: modelVersion1, 2: modelVersion2, @@ -165,7 +164,6 @@ That way: - SO type versions are decoupled from stack versioning - SO type versi ```ts const myType: SavedObjectsType = { name: 'test', - switchToModelVersionAt: '8.10.0', modelVersions: { 1: modelVersion1, // valid: start with version 1 2: modelVersion2, // valid: no gap between versions @@ -179,7 +177,6 @@ const myType: SavedObjectsType = { ```ts const myType: SavedObjectsType = { name: 'test', - switchToModelVersionAt: '8.10.0', modelVersions: { 2: modelVersion2, // invalid: first version must be 1 4: modelVersion3, // invalid: skipped version 3 @@ -198,7 +195,6 @@ const myType: SavedObjectsType = { ```ts const myType: SavedObjectsType = { name: 'test', - switchToModelVersionAt: '8.10.0', modelVersions: { 1: { changes: [ @@ -429,7 +425,6 @@ The definition of the type at version 1 would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', modelVersions: { // initial (and current) model version 1: { @@ -486,7 +481,6 @@ The full type definition after the addition of the new model version: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', modelVersions: { 1: { changes: [], @@ -575,7 +569,6 @@ the full type definition after the addition of the model version 2 would be: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', modelVersions: { 1: { changes: [ @@ -671,7 +664,6 @@ The full type definition would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', modelVersions: { 1: { changes: [ @@ -742,7 +734,6 @@ The definition of the type at version 1 would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', modelVersions: { // initial (and current) model version 1: { @@ -807,7 +798,6 @@ The full type definition after the addition of the new model version: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', modelVersions: { // initial (and current) model version 1: { @@ -875,7 +865,6 @@ The full type definition after the data removal would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', modelVersions: { // initial (and current) model version 1: { diff --git a/src/core/packages/saved-objects/api-server-internal/src/lib/apis/helpers/validation_fixtures.ts b/src/core/packages/saved-objects/api-server-internal/src/lib/apis/helpers/validation_fixtures.ts index 419e50bf57952..d9bccc009c211 100644 --- a/src/core/packages/saved-objects/api-server-internal/src/lib/apis/helpers/validation_fixtures.ts +++ b/src/core/packages/saved-objects/api-server-internal/src/lib/apis/helpers/validation_fixtures.ts @@ -30,7 +30,6 @@ export const typedef: Partial = { count: schema.number(), }), }, - switchToModelVersionAt: '8.10.0', }; export const typedef1: Partial = { @@ -53,7 +52,6 @@ export const typedef1: Partial = { count: schema.number(), }), }, - switchToModelVersionAt: '8.10.0', modelVersions: { '1': { changes: [ @@ -96,7 +94,6 @@ export const typedef2: Partial = { foo: schema.string(), }), }, - switchToModelVersionAt: '8.10.0', modelVersions: { '1': { changes: [ diff --git a/src/core/packages/saved-objects/api-server-internal/src/lib/repository_create_repository.test.ts b/src/core/packages/saved-objects/api-server-internal/src/lib/repository_create_repository.test.ts index 87bfdc1605fe2..828dd2b37eba3 100644 --- a/src/core/packages/saved-objects/api-server-internal/src/lib/repository_create_repository.test.ts +++ b/src/core/packages/saved-objects/api-server-internal/src/lib/repository_create_repository.test.ts @@ -30,7 +30,6 @@ describe('SavedObjectsRepository#createRepository', () => { name: { type: 'keyword' }, }, }, - migrations: {}, }); typeRegistry.registerType({ @@ -43,7 +42,6 @@ describe('SavedObjectsRepository#createRepository', () => { name: { type: 'keyword' }, }, }, - migrations: {}, }); typeRegistry.registerType({ name: 'hiddenType', @@ -54,7 +52,6 @@ describe('SavedObjectsRepository#createRepository', () => { name: { type: 'keyword' }, }, }, - migrations: {}, }); const migrator = kibanaMigratorMock.create({ types: typeRegistry.getAllTypes() }); diff --git a/src/core/packages/saved-objects/api-server-internal/src/test_helpers/repository.test.common.ts b/src/core/packages/saved-objects/api-server-internal/src/test_helpers/repository.test.common.ts index 8682e449dfd15..4dde19f695c00 100644 --- a/src/core/packages/saved-objects/api-server-internal/src/test_helpers/repository.test.common.ts +++ b/src/core/packages/saved-objects/api-server-internal/src/test_helpers/repository.test.common.ts @@ -338,7 +338,6 @@ export const createType = ( ? mappings.properties[type].properties! : {}) as SavedObjectsMappingProperties, }, - migrations: { '1.1.1': (doc) => doc }, ...parts, }); diff --git a/src/core/packages/saved-objects/base-server-internal/index.ts b/src/core/packages/saved-objects/base-server-internal/index.ts index 7aac4bcdb4c20..01b8dad1ff5ba 100644 --- a/src/core/packages/saved-objects/base-server-internal/index.ts +++ b/src/core/packages/saved-objects/base-server-internal/index.ts @@ -56,7 +56,6 @@ export { } from './src/utils'; export { modelVersionVirtualMajor, - globalSwitchToModelVersionAt, assertValidModelVersion, isVirtualModelVersion, virtualVersionToModelVersion, diff --git a/src/core/packages/saved-objects/base-server-internal/src/model_version/constants.ts b/src/core/packages/saved-objects/base-server-internal/src/model_version/constants.ts index 2d46aa53a34c1..b19cae9b37366 100644 --- a/src/core/packages/saved-objects/base-server-internal/src/model_version/constants.ts +++ b/src/core/packages/saved-objects/base-server-internal/src/model_version/constants.ts @@ -11,8 +11,3 @@ * The major version that is used to represent model versions. */ export const modelVersionVirtualMajor = 10; - -/** - * The stack version where all types will be forced to switch to using the model version system. - */ -export const globalSwitchToModelVersionAt = '8.10.0'; diff --git a/src/core/packages/saved-objects/base-server-internal/src/model_version/index.ts b/src/core/packages/saved-objects/base-server-internal/src/model_version/index.ts index e05479974e49c..9aeaf8ebf0df0 100644 --- a/src/core/packages/saved-objects/base-server-internal/src/model_version/index.ts +++ b/src/core/packages/saved-objects/base-server-internal/src/model_version/index.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -export { modelVersionVirtualMajor, globalSwitchToModelVersionAt } from './constants'; +export { modelVersionVirtualMajor } from './constants'; export { assertValidModelVersion, isVirtualModelVersion, diff --git a/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.test.ts b/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.test.ts index a0e5bd3fa9bd3..d49b985ee3866 100644 --- a/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.test.ts +++ b/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.test.ts @@ -12,10 +12,8 @@ import { getModelVersionMapForTypes, getLatestModelVersion, getLatestMigrationVersion, - getCurrentVirtualVersion, getVirtualVersionMap, getLatestMappingsVersionNumber, - getLatestMappingsModelVersion, getLatestMappingsVirtualVersionMap, } from './version_map'; @@ -205,48 +203,12 @@ describe('ModelVersion map utilities', () => { }); }); - describe('getCurrentVirtualVersion', () => { - it('returns the latest registered migration if switchToModelVersionAt is unset', () => { - expect( - getCurrentVirtualVersion( - buildType({ - migrations: { - '7.17.2': dummyMigration, - '8.6.0': dummyMigration, - }, - modelVersions: { - 1: dummyModelVersion(), - }, - }) - ) - ).toEqual('8.6.0'); - }); - - it('returns the virtual version of the latest model version if switchToModelVersionAt is set', () => { - expect( - getCurrentVirtualVersion( - buildType({ - switchToModelVersionAt: '8.7.0', - migrations: { - '7.17.2': dummyMigration, - '8.6.0': dummyMigration, - }, - modelVersions: { - 1: dummyModelVersion(), - }, - }) - ) - ).toEqual('10.1.0'); - }); - }); - describe('getVirtualVersionMap', () => { it('returns the virtual version for each of the provided types', () => { expect( getVirtualVersionMap([ buildType({ name: 'foo', - switchToModelVersionAt: '8.7.0', migrations: { '7.17.2': dummyMigration, '8.6.0': dummyMigration, @@ -267,7 +229,6 @@ describe('ModelVersion map utilities', () => { }), buildType({ name: 'dolly', - switchToModelVersionAt: '8.7.0', migrations: { '7.17.2': dummyMigration, '8.6.0': dummyMigration, @@ -343,50 +304,12 @@ describe('ModelVersion map utilities', () => { }); }); - describe('getLatestMappingsModelVersion', () => { - it('returns the latest registered migration if switchToModelVersionAt is unset', () => { - expect( - getLatestMappingsModelVersion( - buildType({ - migrations: { - '7.17.2': dummyMigration, - '8.6.0': dummyMigration, - }, - modelVersions: { - 1: dummyModelVersionWithMappingsChanges(), - 2: dummyModelVersion(), - }, - }) - ) - ).toEqual('8.6.0'); - }); - - it('returns the virtual version of the latest model version if switchToModelVersionAt is set', () => { - expect( - getLatestMappingsModelVersion( - buildType({ - switchToModelVersionAt: '8.7.0', - migrations: { - '7.17.2': dummyMigration, - '8.6.0': dummyMigration, - }, - modelVersions: { - 1: dummyModelVersionWithMappingsChanges(), - 2: dummyModelVersion(), - }, - }) - ) - ).toEqual('10.1.0'); - }); - }); - describe('getLatestMappingsVirtualVersionMap', () => { it('returns the virtual version for each of the provided types', () => { expect( getLatestMappingsVirtualVersionMap([ buildType({ name: 'foo', - switchToModelVersionAt: '8.7.0', migrations: { '7.17.2': dummyMigration, '8.6.0': dummyMigration, @@ -409,7 +332,6 @@ describe('ModelVersion map utilities', () => { }), buildType({ name: 'dolly', - switchToModelVersionAt: '8.7.0', migrations: { '7.17.2': dummyMigration, '8.6.0': dummyMigration, diff --git a/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.ts b/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.ts index 64ce3d29ec1bb..16f65ada3e75e 100644 --- a/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.ts +++ b/src/core/packages/saved-objects/base-server-internal/src/model_version/version_map.ts @@ -7,7 +7,6 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import Semver from 'semver'; import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; import { assertValidModelVersion, modelVersionToVirtualVersion } from './conversion'; @@ -44,14 +43,6 @@ export const getLatestModelVersion = (type: SavedObjectsType): number => { }, 0); }; -export const getLatestMigrationVersion = (type: SavedObjectsType): string => { - const migrationMap = - typeof type.migrations === 'function' ? type.migrations() : type.migrations ?? {}; - return Object.keys(migrationMap).reduce((memo, current) => { - return Semver.gt(memo, current) ? memo : current; - }, '0.0.0'); -}; - /** * Build a version map for the given types. */ @@ -64,17 +55,10 @@ export const getModelVersionMapForTypes = (types: SavedObjectsType[]): ModelVers /** * Returns the current virtual version for the given type. - * It will either be the latest model version if the type - * already switched to using them (switchToModelVersionAt is set), - * or the latest migration version for the type otherwise. */ export const getCurrentVirtualVersion = (type: SavedObjectsType): string => { - if (type.switchToModelVersionAt) { - const modelVersion = getLatestModelVersion(type); - return modelVersionToVirtualVersion(modelVersion); - } else { - return getLatestMigrationVersion(type); - } + const modelVersion = getLatestModelVersion(type); + return modelVersionToVirtualVersion(modelVersion); }; /** @@ -106,17 +90,10 @@ export const getLatestMappingsVersionNumber = (type: SavedObjectsType): number = /** * Returns the latest model version that includes changes in the mappings, for the given type. - * It will either be a model version if the type - * already switched to using them (switchToModelVersionAt is set), - * or the latest migration version for the type otherwise. */ export const getLatestMappingsModelVersion = (type: SavedObjectsType): string => { - if (type.switchToModelVersionAt) { - const modelVersion = getLatestMappingsVersionNumber(type); - return modelVersionToVirtualVersion(modelVersion); - } else { - return getLatestMigrationVersion(type); - } + const modelVersion = getLatestMappingsVersionNumber(type); + return modelVersionToVirtualVersion(modelVersion); }; /** diff --git a/src/core/packages/saved-objects/base-server-internal/src/saved_objects_type_registry.test.ts b/src/core/packages/saved-objects/base-server-internal/src/saved_objects_type_registry.test.ts index 1c7d86b1fea9c..00cb7abe84b88 100644 --- a/src/core/packages/saved-objects/base-server-internal/src/saved_objects_type_registry.test.ts +++ b/src/core/packages/saved-objects/base-server-internal/src/saved_objects_type_registry.test.ts @@ -15,7 +15,6 @@ const createType = (type: Partial): SavedObjectsType => ({ hidden: false, namespaceType: 'single' as 'single', mappings: { properties: {} }, - migrations: {}, ...type, }); @@ -302,9 +301,6 @@ describe('SavedObjectTypeRegistry', () => { registry.registerType( createType({ name: 'typeB', - migrations: { - '1.0.0': jest.fn(), - }, }) ); diff --git a/src/core/packages/saved-objects/migration-server-internal/src/actions/cleanup_unknown_and_excluded.ts b/src/core/packages/saved-objects/migration-server-internal/src/actions/cleanup_unknown_and_excluded.ts index fcbddcf2eebdd..41f38e8212729 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/actions/cleanup_unknown_and_excluded.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/actions/cleanup_unknown_and_excluded.ts @@ -108,6 +108,9 @@ export const cleanupUnknownAndExcluded = ({ }, }; + if (2 === 2) { + return TaskEither.right(); + } return deleteByQuery({ client, indexName, diff --git a/src/core/packages/saved-objects/migration-server-internal/src/core/build_index_map.test.ts b/src/core/packages/saved-objects/migration-server-internal/src/core/build_index_map.test.ts index ed63809842b7c..36569e93f40dd 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/core/build_index_map.test.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/core/build_index_map.test.ts @@ -19,7 +19,6 @@ const createRegistry = (...types: Array>) => { namespaceType: 'single', hidden: false, mappings: { properties: {} }, - migrations: {}, ...type, }) ); diff --git a/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/document_migrator.test.ts b/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/document_migrator.test.ts index 12a28f8a818f1..e12a6be1655d7 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/document_migrator.test.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/document_migrator.test.ts @@ -1415,7 +1415,6 @@ describe('DocumentMigrator', () => { const fooType = createType({ name: 'foo', - switchToModelVersionAt: '8.5.0', modelVersions: { 1: { changes: [], @@ -1458,7 +1457,6 @@ describe('DocumentMigrator', () => { const fooType = createType({ name: 'foo', - switchToModelVersionAt: '8.5.0', modelVersions: { 1: { changes: [], diff --git a/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migration.test.ts b/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migration.test.ts index 9f32634c2121e..f8600e6382108 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migration.test.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migration.test.ts @@ -111,140 +111,12 @@ describe('validateTypeMigrations', () => { expect(() => validate({ type })).not.toThrow(); }); - - describe('when switchToModelVersionAt is specified', () => { - it('throws if a migration is specified for a version superior to switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: '8.9.0', - migrations: { - '8.10.0': jest.fn(), - }, - }); - - expect(() => - validate({ type, kibanaVersion: '8.10.0' }) - ).toThrowErrorMatchingInlineSnapshot( - `"Migration for type foo for version 8.10.0 registered after switchToModelVersionAt (8.9.0)"` - ); - }); - - it('throws if a schema is specified for a version superior to switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: '8.9.0', - schemas: { - '8.10.0': schema.object({ name: schema.string() }), - }, - }); - - expect(() => - validate({ type, kibanaVersion: '8.10.0' }) - ).toThrowErrorMatchingInlineSnapshot( - `"Schema for type foo for version 8.10.0 registered after switchToModelVersionAt (8.9.0)"` - ); - }); - - it('throws if a migration is specified for a version equal to switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: '8.9.0', - migrations: { - '8.9.0': jest.fn(), - }, - }); - - expect(() => - validate({ type, kibanaVersion: '8.10.0' }) - ).toThrowErrorMatchingInlineSnapshot( - `"Migration for type foo for version 8.9.0 registered after switchToModelVersionAt (8.9.0)"` - ); - }); - - it('throws if a schema is specified for a version equal to switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: '8.9.0', - schemas: { - '8.9.0': schema.object({ name: schema.string() }), - }, - }); - - expect(() => - validate({ type, kibanaVersion: '8.10.0' }) - ).toThrowErrorMatchingInlineSnapshot( - `"Schema for type foo for version 8.9.0 registered after switchToModelVersionAt (8.9.0)"` - ); - }); - - it('does not throw if a migration is specified for a version inferior to switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: '8.9.0', - migrations: { - '8.7.0': jest.fn(), - }, - }); - - expect(() => validate({ type, kibanaVersion: '8.10.0' })).not.toThrow(); - }); - - it('does not throw if a schema is specified for a version inferior to switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: '8.9.0', - schemas: { - '8.7.0': schema.object({ name: schema.string() }), - }, - }); - - expect(() => validate({ type, kibanaVersion: '8.10.0' })).not.toThrow(); - }); - }); - }); - - describe('switchToModelVersionAt', () => { - it('throws if the specified version is not a valid semver', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: 'foo', - }); - - expect(() => validate({ type })).toThrowErrorMatchingInlineSnapshot( - `"Type foo: invalid version specified for switchToModelVersionAt: foo"` - ); - }); - - it('throws if the specified version defines a patch version > 0', () => { - const type = createType({ - name: 'foo', - switchToModelVersionAt: '8.9.3', - }); - - expect(() => validate({ type })).toThrowErrorMatchingInlineSnapshot( - `"Type foo: can't use a patch version for switchToModelVersionAt"` - ); - }); }); describe('modelVersions', () => { - it('throws if used without specifying switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - modelVersions: { - '1': someModelVersion, - }, - }); - - expect(() => validate({ type, kibanaVersion: '3.2.3' })).toThrowErrorMatchingInlineSnapshot( - `"Type foo: Using modelVersions requires to specify switchToModelVersionAt"` - ); - }); - it('throws if the version number is invalid', () => { const type = createType({ name: 'foo', - switchToModelVersionAt: '3.1.0', modelVersions: { '1.1': someModelVersion, }, @@ -258,7 +130,6 @@ describe('validateTypeMigrations', () => { it('throws when starting with a version higher than 1', () => { const type = createType({ name: 'foo', - switchToModelVersionAt: '3.1.0', modelVersions: { '2': someModelVersion, }, @@ -272,7 +143,6 @@ describe('validateTypeMigrations', () => { it('throws when there is a gap in versions', () => { const type = createType({ name: 'foo', - switchToModelVersionAt: '3.1.0', modelVersions: { '1': someModelVersion, '3': someModelVersion, @@ -298,30 +168,6 @@ describe('validateTypeMigrations', () => { describe('modelVersions with schemas', () => { const baseSchema = schema.object({ name: schema.string() }, { unknowns: 'ignore' }); - it('throws if used without specifying switchToModelVersionAt', () => { - const type = createType({ - name: 'foo', - modelVersions: { - 1: { - changes: [], - schemas: { - forwardCompatibility: baseSchema, - create: baseSchema, - }, - }, - }, - mappings: { - properties: { - name: { type: 'text' }, - }, - }, - }); - - expect(() => validate({ type, kibanaVersion: '3.2.3' })).toThrowErrorMatchingInlineSnapshot( - `"Type foo: Using modelVersions requires to specify switchToModelVersionAt"` - ); - }); - it('does not throw passing a model version schema map', () => { const someModelVersionWithSchema = { changes: [], @@ -332,7 +178,6 @@ describe('validateTypeMigrations', () => { }; const type = createType({ name: 'foo', - switchToModelVersionAt: '3.1.0', modelVersions: { '1': someModelVersionWithSchema, }, @@ -350,7 +195,6 @@ describe('validateTypeMigrations', () => { const someModelVersionWithSchema = { changes: [], schemas: {} }; const type = createType({ name: 'foo', - switchToModelVersionAt: '3.1.0', modelVersions: { '1': someModelVersionWithSchema, }, @@ -364,7 +208,6 @@ describe('validateTypeMigrations', () => { it('throws when registering mapping additions not present in the global mappings', () => { const type = createType({ name: 'foo', - switchToModelVersionAt: '8.8.0', modelVersions: { '1': { changes: [ @@ -392,7 +235,6 @@ describe('validateTypeMigrations', () => { it('does not throw when registering mapping additions are present in the global mappings with a schema', () => { const type = createType({ name: 'foo', - switchToModelVersionAt: '8.8.0', modelVersions: { '1': { changes: [ @@ -431,7 +273,6 @@ describe('validateTypeMigrations', () => { it('throws when registering mapping additions different than the global mappings', () => { const type = createType({ name: 'foo', - switchToModelVersionAt: '8.8.0', modelVersions: { '1': { changes: [ @@ -461,7 +302,6 @@ describe('validateTypeMigrations', () => { const baseSchema = schema.object({ name: schema.string() }); const type = createType({ name: 'foo', - switchToModelVersionAt: '8.10.0', modelVersions: { 1: { changes: [], diff --git a/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migrations.ts b/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migrations.ts index 0863e3907602a..001bd0a6ec2b1 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migrations.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/document_migrator/validate_migrations.ts @@ -33,18 +33,6 @@ export function validateTypeMigrations({ kibanaVersion: string; convertVersion?: string; }) { - if (type.switchToModelVersionAt) { - const switchToModelVersionAt = Semver.parse(type.switchToModelVersionAt); - if (!switchToModelVersionAt) { - throw new Error( - `Type ${type.name}: invalid version specified for switchToModelVersionAt: ${type.switchToModelVersionAt}` - ); - } - if (switchToModelVersionAt.patch !== 0) { - throw new Error(`Type ${type.name}: can't use a patch version for switchToModelVersionAt`); - } - } - if (type.migrations) { assertObjectOrFunction( type.migrations, @@ -62,11 +50,6 @@ export function validateTypeMigrations({ Object.entries(migrationMap).forEach(([version, migration]) => { assertValidSemver(kibanaVersion, version, type.name); assertValidTransform(migration, version, type.name); - if (type.switchToModelVersionAt && Semver.gte(version, type.switchToModelVersionAt)) { - throw new Error( - `Migration for type ${type.name} for version ${version} registered after switchToModelVersionAt (${type.switchToModelVersionAt})` - ); - } }); } @@ -79,11 +62,6 @@ export function validateTypeMigrations({ Object.entries(schemaMap).forEach(([version, schema]) => { assertValidSemver(kibanaVersion, version, type.name); - if (type.switchToModelVersionAt && Semver.gte(version, type.switchToModelVersionAt)) { - throw new Error( - `Schema for type ${type.name} for version ${version} registered after switchToModelVersionAt (${type.switchToModelVersionAt})` - ); - } }); } @@ -92,12 +70,6 @@ export function validateTypeMigrations({ typeof type.modelVersions === 'function' ? type.modelVersions() : type.modelVersions ?? {}; if (Object.keys(modelVersionMap).length > 0) { - if (!type.switchToModelVersionAt) { - throw new Error( - `Type ${type.name}: Using modelVersions requires to specify switchToModelVersionAt` - ); - } - Object.entries(modelVersionMap).forEach(([version, definition]) => { assertValidModelVersion(version); }); diff --git a/src/core/packages/saved-objects/migration-server-internal/src/initial_state.test.ts b/src/core/packages/saved-objects/migration-server-internal/src/initial_state.test.ts index ab60da37a6b2d..7df476e9b423f 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/initial_state.test.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/initial_state.test.ts @@ -82,7 +82,6 @@ describe('createInitialState', () => { changes: [], }, }, - switchToModelVersionAt: '8.10.0', }); typeRegistry.registerType({ name: 'bar', @@ -99,7 +98,6 @@ describe('createInitialState', () => { changes: [{ type: 'mappings_addition', addedMappings: {} }], }, }, - switchToModelVersionAt: '8.10.0', }); docLinks = docLinksServiceMock.createSetupContract(); logger = mockLogger.get(); diff --git a/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/build_index_mappings.test.ts b/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/build_index_mappings.test.ts index 59d3430d6ce14..807efc347dbbb 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/build_index_mappings.test.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/build_index_mappings.test.ts @@ -13,7 +13,6 @@ import { createType } from '../test_helpers'; const getTestTypes = () => { const foo = createType({ name: 'foo', - switchToModelVersionAt: '8.7.0', modelVersions: { 1: { changes: [] }, 2: { changes: [] }, @@ -22,7 +21,6 @@ const getTestTypes = () => { }); const bar = createType({ name: 'bar', - switchToModelVersionAt: '8.7.0', modelVersions: { 1: { changes: [] }, }, @@ -30,7 +28,6 @@ const getTestTypes = () => { }); const dolly = createType({ name: 'dolly', - switchToModelVersionAt: '8.7.0', modelVersions: () => ({ 1: { changes: [] }, 2: { changes: [] }, diff --git a/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts b/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts index 125947acbcc2f..82ccc414eea01 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts @@ -34,7 +34,6 @@ describe('generateAdditiveMappingDiff', () => { const getTypes = () => { const foo = createType({ name: 'foo', - switchToModelVersionAt: '8.0.0', modelVersions: { 1: stubModelVersion, 2: stubModelVersion, diff --git a/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/outdated_documents_query.test.ts b/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/outdated_documents_query.test.ts index 539dc9c55af85..9156f4582a6dc 100644 --- a/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/outdated_documents_query.test.ts +++ b/src/core/packages/saved-objects/migration-server-internal/src/zdt/utils/outdated_documents_query.test.ts @@ -21,7 +21,6 @@ describe('getOutdatedDocumentsQuery', () => { it('generates the correct query for types using model versions', () => { const fooType = createType({ name: 'foo', - switchToModelVersionAt: '8.8.0', modelVersions: { 1: dummyModelVersion, 2: dummyModelVersion, @@ -29,7 +28,6 @@ describe('getOutdatedDocumentsQuery', () => { }); const barType = createType({ name: 'bar', - switchToModelVersionAt: '8.8.0', modelVersions: { 1: dummyModelVersion, 2: dummyModelVersion, @@ -160,7 +158,6 @@ describe('getOutdatedDocumentsQuery', () => { '7.17.2': dummyMigration, '8.5.0': dummyMigration, }, - switchToModelVersionAt: '8.8.0', modelVersions: { 1: dummyModelVersion, 2: dummyModelVersion, diff --git a/src/core/packages/saved-objects/server-internal/src/apply_type_defaults.test.ts b/src/core/packages/saved-objects/server-internal/src/apply_type_defaults.test.ts deleted file mode 100644 index f3a54dde6749d..0000000000000 --- a/src/core/packages/saved-objects/server-internal/src/apply_type_defaults.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; -import { globalSwitchToModelVersionAt } from '@kbn/core-saved-objects-base-server-internal'; -import { applyTypeDefaults } from './apply_type_defaults'; - -const createType = (parts: Partial = {}): SavedObjectsType => ({ - name: 'test', - namespaceType: 'single', - hidden: false, - mappings: { properties: {} }, - ...parts, -}); - -describe('applyTypeDefaults', () => { - describe('switchToModelVersionAt', () => { - it(`keeps the type's switchToModelVersionAt if lesser than the global version`, () => { - const type = createType({ - switchToModelVersionAt: '8.4.0', - }); - - const result = applyTypeDefaults(type); - expect(result.switchToModelVersionAt).toEqual('8.4.0'); - }); - - it(`sets switchToModelVersionAt to the global version if unspecified`, () => { - const type = createType({ - switchToModelVersionAt: undefined, - }); - - const result = applyTypeDefaults(type); - expect(result.switchToModelVersionAt).toEqual(globalSwitchToModelVersionAt); - }); - - it(`throws if switchToModelVersionAt is invalid`, () => { - const type = createType({ - switchToModelVersionAt: 'foobar', - }); - - expect(() => applyTypeDefaults(type)).toThrowErrorMatchingInlineSnapshot( - `"Type test: invalid switchToModelVersionAt provided: foobar"` - ); - }); - - it(`throws if type version is greater than the global version`, () => { - const type = createType({ - switchToModelVersionAt: '9.2.0', - }); - - expect(() => applyTypeDefaults(type)).toThrowErrorMatchingInlineSnapshot( - `"Type test: provided switchToModelVersionAt (9.2.0) is higher than maximum (8.10.0)"` - ); - }); - }); -}); diff --git a/src/core/packages/saved-objects/server-internal/src/apply_type_defaults.ts b/src/core/packages/saved-objects/server-internal/src/apply_type_defaults.ts deleted file mode 100644 index 0643179211010..0000000000000 --- a/src/core/packages/saved-objects/server-internal/src/apply_type_defaults.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import Semver from 'semver'; -import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; -import { globalSwitchToModelVersionAt } from '@kbn/core-saved-objects-base-server-internal'; - -/** - * Apply global defaults to the provided SO type. - */ -export const applyTypeDefaults = (type: SavedObjectsType): SavedObjectsType => { - let switchToModelVersionAt = type.switchToModelVersionAt; - if (switchToModelVersionAt) { - if (!Semver.valid(switchToModelVersionAt)) { - throw new Error( - `Type ${type.name}: invalid switchToModelVersionAt provided: ${switchToModelVersionAt}` - ); - } - if (Semver.gt(switchToModelVersionAt, globalSwitchToModelVersionAt)) { - throw new Error( - `Type ${type.name}: provided switchToModelVersionAt (${switchToModelVersionAt}) is higher than maximum (${globalSwitchToModelVersionAt})` - ); - } - } else { - switchToModelVersionAt = globalSwitchToModelVersionAt; - } - - return { - ...type, - switchToModelVersionAt, - }; -}; diff --git a/src/core/packages/saved-objects/server-internal/src/saved_objects_service.test.ts b/src/core/packages/saved-objects/server-internal/src/saved_objects_service.test.ts index 70e8fcf17c797..113715c9fff37 100644 --- a/src/core/packages/saved-objects/server-internal/src/saved_objects_service.test.ts +++ b/src/core/packages/saved-objects/server-internal/src/saved_objects_service.test.ts @@ -381,7 +381,6 @@ describe('SavedObjectsService', () => { }; const returnedType = { ...inputType, - switchToModelVersionAt: '9.9.9', }; applyTypeDefaultsMock.mockReturnValue(returnedType); diff --git a/src/core/packages/saved-objects/server/docs/model_versions.md b/src/core/packages/saved-objects/server/docs/model_versions.md index f3d67d6d299de..03942e390f17b 100644 --- a/src/core/packages/saved-objects/server/docs/model_versions.md +++ b/src/core/packages/saved-objects/server/docs/model_versions.md @@ -35,8 +35,8 @@ ## Introduction -The modelVersion API is a new way to define transformations (*"migrations"*) for your savedObject types, and will -replace the "old" migration API after Kibana version `8.10.0` (where it will no longer be possible to register +The modelVersion API is a new way to define transformations (*"migrations"*) for your savedObject types, and will +replace the "old" migration API after Kibana version `8.10.0` (where it will no longer be possible to register migrations using the old system). The main purpose of this API is to address two problems of the old migration system regarding managed ("serverless") deployments: @@ -56,7 +56,7 @@ migrations was the stack version. You couldn't for example, add 2 consecutive mi It was fine for on-prem distributions, given there is no way to upgrade Kibana to something else than a "fixed" stack version. -For our managed offering however, where we're planning on decoupling deployments and upgrades from stack versions +For our managed offering however, where we're planning on decoupling deployments and upgrades from stack versions (deploying more often, so more than once per stack release), it would have been an issue, as it wouldn't have been possible to add a new migration in-between 2 stack versions. @@ -66,8 +66,8 @@ We needed a way to decouple SO versioning from the stack versioning to support t ### 2. The current migrations API is unsafe for the zero-downtime and backward-compatible requirements -On traditional deployments (on-prem/non-managed cloud), upgrading Kibana is done with downtime. -The upgrade process requires shutting down all the nodes of the prior version before deploying the new one. +On traditional deployments (on-prem/non-managed cloud), upgrading Kibana is done with downtime. +The upgrade process requires shutting down all the nodes of the prior version before deploying the new one. That way, there is always a single version of Kibana running at a given time, which avoids all risks of data incompatibility between version (e.g the new version introduces a migration that changes the shape of the document in a way that breaks compatibility with the previous version) @@ -75,9 +75,9 @@ with the previous version) For serverless however, the same process can't be used, as we need to be able to upgrade Kibana without interruption of service. Which means that the old and new version of Kibana will have to cohabitate for a time. -This leads to a lot of constraints regarding what can, or cannot, be done with data transformations (migrations) during an upgrade. +This leads to a lot of constraints regarding what can, or cannot, be done with data transformations (migrations) during an upgrade. And, unsurprisingly, the existing migration API (which allows to register any kind of *(doc) => doc* transformations) was way too permissive and -unsafe given our backward compatibility requirements. +unsafe given our backward compatibility requirements. ## Defining model versions @@ -87,7 +87,7 @@ When registering a SO type, a new [modelVersions](https://github.com/elastic/kib property is available. This attribute is a map of [SavedObjectsModelVersion](https://github.com/elastic/kibana/blob/f0eb5d695745f1f3a19ae6392618d1826ce29ce2/src/core/packages/saved-objects/server/src/model_version/model_version.ts#L13-L21) which is the top-level type/container to define model versions. -This map follows a similar `{ [version number] => version definition }` format as the old migration map, however +This map follows a similar `{ [version number] => version definition }` format as the old migration map, however a given SO type's model version is now identified by a single integer. The first version must be numbered as version 1, incrementing by one for each new version. @@ -100,8 +100,7 @@ That way: ```ts const myType: SavedObjectsType = { name: 'test', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { 1: modelVersion1, // valid: start with version 1 2: modelVersion2, // valid: no gap between versions }, @@ -113,8 +112,7 @@ const myType: SavedObjectsType = { ```ts const myType: SavedObjectsType = { name: 'test', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { 2: modelVersion2, // invalid: first version must be 1 4: modelVersion3, // invalid: skipped version 3 }, @@ -132,8 +130,7 @@ are not just functions as the previous migrations were, but structured objects d ```ts const myType: SavedObjectsType = { name: 'test', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { 1: { changes: [ { @@ -157,7 +154,7 @@ const myType: SavedObjectsType = { }; ``` -**Note:** Having multiple changes of the same type for a given version is supported by design +**Note:** Having multiple changes of the same type for a given version is supported by design to allow merging different sources (to prepare for an eventual higher-level API) *This definition would be perfectly valid:* @@ -188,9 +185,9 @@ It's currently composed of two main properties: [link to the TS doc for `changes`](https://github.com/elastic/kibana/blob/f0eb5d695745f1f3a19ae6392618d1826ce29ce2/src/core/packages/saved-objects/server/src/model_version/model_version.ts#L22-L73) -Describes the list of changes applied during this version. +Describes the list of changes applied during this version. -**Important:** This is the part that replaces the old migration system, and allows defining when a version adds new mapping, +**Important:** This is the part that replaces the old migration system, and allows defining when a version adds new mapping, mutates the documents, or other type-related changes. The current types of changes are: @@ -249,12 +246,12 @@ let change: SavedObjectsModelDataBackfillChange = { }; ``` -**note:** *Even if no check is performed to ensure it, this type of model change should only be used to +**note:** *Even if no check is performed to ensure it, this type of model change should only be used to backfill newly introduced fields.* #### - data_removal -Used to remove data (unset fields) from all documents of the type. +Used to remove data (unset fields) from all documents of the type. *Usage example:* @@ -306,7 +303,7 @@ This is a new concept introduced by model versions. This schema is used for inte When retrieving a savedObject document from an index, if the version of the document is higher than the latest version known of the Kibana instance, the document will go through the `forwardCompatibility` schema of the associated model version. -**Important:** These conversion mechanism shouldn't assert the data itself, and only strip unknown fields to convert the document to +**Important:** These conversion mechanism shouldn't assert the data itself, and only strip unknown fields to convert the document to the **shape** of the document at the given version. Basically, this schema should keep all the known fields of a given version, and remove all the unknown fields, without throwing. @@ -352,7 +349,7 @@ definition, now directly included in the model version definition. As a refresher the `create` schema is a `@kbn/config-schema` object-type schema, and is used to validate the properties of the document during `create` and `bulkCreate` operations. -**note:** *Implementing this schema is optional, but still recommended, as otherwise there will be no validating when +**note:** *Implementing this schema is optional, but still recommended, as otherwise there will be no validating when importing objects* ## Use-case examples @@ -373,8 +370,7 @@ The definition of the type at version 1 would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { // initial (and current) model version 1: { changes: [], @@ -402,7 +398,7 @@ const myType: SavedObjectsType = { From here, say we want to introduce a new `dolly` field that is not indexed, and that we don't need to populate with a default value. -To achieve that, we need to introduce a new model version, with the only thing to do will be to define the +To achieve that, we need to introduce a new model version, with the only thing to do will be to define the associated schemas to include this new field. The added model version would look like: @@ -425,14 +421,13 @@ let modelVersion2: SavedObjectsModelVersion = { }; ``` -The full type definition after the addition of the new model version: +The full type definition after the addition of the new model version: ```ts const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { 1: { changes: [], schemas: { @@ -470,7 +465,7 @@ const myType: SavedObjectsType = { ### Adding an indexed field without default value This scenario is fairly close to the previous one. The difference being that working with an indexed field means -adding a `mappings_addition` change and to also update the root mappings accordingly. +adding a `mappings_addition` change and to also update the root mappings accordingly. To reuse the previous example, let's say the `dolly` field we want to add would need to be indexed instead. @@ -479,7 +474,7 @@ In that case, the new version needs to do the following: - update the root `mappings` accordingly - add the updated schemas as we did for the previous example -The new version definition would look like: +The new version definition would look like: ```ts let modelVersion2: SavedObjectsModelVersion = { @@ -523,8 +518,7 @@ the full type definition after the addition of the model version 2 would be: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { 1: { changes: [ { @@ -619,8 +613,7 @@ The full type definition would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { 1: { changes: [ { @@ -689,8 +682,7 @@ The definition of the type at version 1 would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { // initial (and current) model version 1: { changes: [], @@ -721,7 +713,7 @@ From here, say we want to remove the `removed` field, as our application doesn't The first thing to understand here is the impact toward backward compatibility: Say that Kibana version `X` was still using this field, and that we stopped utilizing the field in version `X+1`. -We can't remove the data in version `X+1`, as we need to be able to rollback to the prior version at **any time**. +We can't remove the data in version `X+1`, as we need to be able to rollback to the prior version at **any time**. If we were to delete the data of this `removed` field during the upgrade to version `X+1`, and if then, for any reason, we'd need to rollback to version `X`, it would cause a data loss, as version `X` was still using this field, but it would no longer present in our document after the rollback. @@ -763,8 +755,7 @@ The full type definition after the addition of the new model version: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { // initial (and current) model version 1: { changes: [], @@ -815,11 +806,11 @@ let modelVersion3: SavedObjectsModelVersion = { ], schemas: { forwardCompatibility: schema.object( - { kept: schema.string() }, + { kept: schema.string() }, { unknowns: 'ignore' } ), create: schema.object( - { kept: schema.string() }, + { kept: schema.string() }, ) }, }; @@ -831,8 +822,7 @@ The full type definition after the data removal would look like: const myType: SavedObjectsType = { name: 'test', namespaceType: 'single', - switchToModelVersionAt: '8.10.0', - modelVersions: { + modelVersions: { // initial (and current) model version 1: { changes: [], @@ -896,32 +886,32 @@ with model version and their associated transformations. ### Tooling for unit tests -For unit tests, the package exposes utilities to easily test the impact of transforming documents +For unit tests, the package exposes utilities to easily test the impact of transforming documents from a model version to another one, either upward or backward. #### Model version test migrator -The `createModelVersionTestMigrator` helper allows to create a test migrator that can be used to +The `createModelVersionTestMigrator` helper allows to create a test migrator that can be used to test model version changes between versions, by transforming documents the same way the migration algorithm would during an upgrade. **Example:** ```ts -import { - createModelVersionTestMigrator, - type ModelVersionTestMigrator +import { + createModelVersionTestMigrator, + type ModelVersionTestMigrator } from '@kbn/core-test-helpers-model-versions'; const mySoTypeDefinition = someSoType(); describe('mySoTypeDefinition model version transformations', () => { let migrator: ModelVersionTestMigrator; - + beforeEach(() => { migrator = createModelVersionTestMigrator({ type: mySoTypeDefinition }); }); - + describe('Model version 2', () => { it('properly backfill the expected fields when converting from v1 to v2', () => { const obj = createSomeSavedObject(); @@ -955,7 +945,7 @@ describe('mySoTypeDefinition model version transformations', () => { During integration tests, we can boot a real Elasticsearch cluster, allowing us to manipulate SO documents in a way almost similar to how it would be done on production runtime. With integration tests, we can even simulate the cohabitation of two Kibana instances with different model versions -to assert the behavior of their interactions. +to assert the behavior of their interactions. #### Model version test bed @@ -966,7 +956,7 @@ and to initiate the migration between the two versions we're testing. **Example:** ```ts -import { +import { createModelVersionTestBed, type ModelVersionTestKit } from '@kbn/core-test-helpers-model-versions'; @@ -1032,7 +1022,7 @@ test bed currently has some limitations: ## Limitations and edge cases in serverless environments The serverless environment, and the fact that upgrade in such environments are performed in a way -where, at some point, the old and new version of the application are living in cohabitation, leads +where, at some point, the old and new version of the application are living in cohabitation, leads to some particularities regarding the way the SO APIs works, and to some limitations / edge case that we need to document diff --git a/src/core/packages/saved-objects/server/src/saved_objects_type.ts b/src/core/packages/saved-objects/server/src/saved_objects_type.ts index 3f009ce5943f9..76dc8845a070d 100644 --- a/src/core/packages/saved-objects/server/src/saved_objects_type.ts +++ b/src/core/packages/saved-objects/server/src/saved_objects_type.ts @@ -191,59 +191,6 @@ export interface SavedObjectsType { */ modelVersions?: SavedObjectsModelVersionMap | SavedObjectsModelVersionMapProvider; - /** - * Allows to opt-in to the model version API. - * - * Must be a valid semver version (with the patch version being necessarily 0) - * - * When specified, the type will switch from using the {@link SavedObjectsType.migrations | legacy migration API} - * to use the {@link SavedObjectsType.modelVersions | modelVersion API} after the specified version. - * - * Once opted in, it will no longer be possible to use the legacy migration API after the specified version. - * - * @example A **valid** usage example would be: - * - * ```ts - * { - * name: 'foo', - * // other mandatory attributes... - * switchToModelVersionAt: '8.8.0', - * migrations: { - * '8.1.0': migrateTo810, - * '8.7.0': migrateTo870, - * }, - * modelVersions: { - * '1': modelVersion1 - * } - * } - * ``` - * - * @example An **invalid** usage example would be: - * - * ```ts - * { - * name: 'foo', - * // other mandatory attributes... - * switchToModelVersionAt: '8.9.0', - * migrations: { - * '8.1.0': migrateTo8_1, - * '8.9.0': migrateTo8_9, // error: migration registered for the switch version - * '8.10.0': migrateTo8_10, // error: migration registered for after the switch version - * }, - * modelVersions: { - * '1': modelVersion1 - * } - * } - * ``` - * - * Please refer to the {@link SavedObjectsType.modelVersions | modelVersion API} for more documentation on - * the new API. - * - * @remarks All types will be forced to switch to use the new API during `8.10.0`. This switch is - * allowing types owners to switch their types before the milestone (and for testing purposes). - */ - switchToModelVersionAt?: string; - /** * Function returning the title to display in the management table. * If not defined, will use the object's type and id to generate a label. diff --git a/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.test.ts b/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.test.ts index 207c50dad4658..5b7fc8377d545 100644 --- a/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.test.ts +++ b/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.test.ts @@ -161,16 +161,7 @@ describe('extractMigrationInfo', () => { }); describe('modelVersions', () => { - it('returns the correct switchToModelVersionAt', () => { - const type = createType({ - switchToModelVersionAt: '8.8.0', - }); - const output = extractMigrationInfo(type); - - expect(output.switchToModelVersionAt).toEqual('8.8.0'); - }); - - it('returns a proper summary of the model versions', () => { + it('returns a proper summary o the model versions', () => { const type = createType({ modelVersions: { '1': { @@ -319,7 +310,6 @@ describe('extractMigrationInfo', () => { it('returns the correct values for schemas', () => { const type = createType({ - switchToModelVersionAt: '8.8.0', modelVersions: { 1: { changes: [], @@ -374,7 +364,6 @@ describe('extractMigrationInfo', () => { ], }, }, - switchToModelVersionAt: '8.8.0', }); const output = extractMigrationInfo(type); @@ -382,7 +371,6 @@ describe('extractMigrationInfo', () => { expect(output).toEqual( expect.objectContaining({ migrationVersions: ['7.17.7', '8.0.2', '8.3.3'], - switchToModelVersionAt: '8.8.0', modelVersions: [ { version: '1', diff --git a/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.ts b/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.ts index 41da158916144..afca916091795 100644 --- a/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.ts +++ b/src/core/packages/test-helpers/so-type-serializer/src/extract_migration_info.ts @@ -24,7 +24,6 @@ export interface SavedObjectTypeMigrationInfo { mappings: Record; hasExcludeOnUpgrade: boolean; modelVersions: ModelVersionSummary[]; - switchToModelVersionAt?: string; } export interface ModelVersionSummary { @@ -80,7 +79,6 @@ export const extractMigrationInfo = (soType: SavedObjectsType): SavedObjectTypeM mappings: getFlattenedObject(soType.mappings ?? {}), hasExcludeOnUpgrade: !!soType.excludeOnUpgrade, modelVersions, - switchToModelVersionAt: soType.switchToModelVersionAt, }; }; diff --git a/src/core/packages/test-helpers/so-type-serializer/src/get_migration_hash.ts b/src/core/packages/test-helpers/so-type-serializer/src/get_migration_hash.ts index c65f6330e176b..0b17d1a3afa96 100644 --- a/src/core/packages/test-helpers/so-type-serializer/src/get_migration_hash.ts +++ b/src/core/packages/test-helpers/so-type-serializer/src/get_migration_hash.ts @@ -27,7 +27,6 @@ export const getMigrationHash = (soType: SavedObjectsType): SavedObjectTypeMigra migInfo.migrationVersions.join(','), migInfo.schemaVersions.join(','), JSON.stringify(migInfo.mappings, Object.keys(migInfo.mappings).sort()), - migInfo.switchToModelVersionAt ?? 'none', migInfo.modelVersions.map(serializeModelVersion).join(','), ]; const hashFeed = hashParts.join('-'); diff --git a/src/core/server/integration_tests/saved_objects/migrations/fixtures/zdt_base.fixtures.ts b/src/core/server/integration_tests/saved_objects/migrations/fixtures/zdt_base.fixtures.ts index 019e2755290c3..193b41083d215 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/fixtures/zdt_base.fixtures.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/fixtures/zdt_base.fixtures.ts @@ -53,7 +53,6 @@ export const getFooType = () => { someField: { type: 'text' }, }, }, - switchToModelVersionAt: '8.7.0', modelVersions: { '1': dummyModelVersion, '2': dummyModelVersion, @@ -69,7 +68,6 @@ export const getBarType = () => { aKeyword: { type: 'keyword' }, }, }, - switchToModelVersionAt: '8.7.0', modelVersions: { '1': dummyModelVersion, }, @@ -85,7 +83,6 @@ export const getSampleAType = () => { boolean: { type: 'boolean' }, }, }, - switchToModelVersionAt: '8.7.0', modelVersions: { '1': dummyModelVersion, }, @@ -101,7 +98,6 @@ export const getSampleBType = () => { text2: { type: 'text' }, }, }, - switchToModelVersionAt: '8.7.0', modelVersions: { '1': dummyModelVersion, }, @@ -117,7 +113,6 @@ export const getDeletedType = () => { text: { type: 'text' }, }, }, - switchToModelVersionAt: '8.7.0', modelVersions: { '1': dummyModelVersion, }, @@ -133,7 +128,6 @@ export const getExcludedType = () => { value: { type: 'integer' }, }, }, - switchToModelVersionAt: '8.7.0', modelVersions: { '1': dummyModelVersion, }, diff --git a/src/core/server/integration_tests/saved_objects/migrations/group4/v2_md5_to_mv.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group4/v2_md5_to_mv.test.ts index a9bb6716073dd..cd0e84067dfa6 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group4/v2_md5_to_mv.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group4/v2_md5_to_mv.test.ts @@ -26,7 +26,6 @@ import '../jest_matchers'; const logFilePath = Path.join(__dirname, 'v2_md5_to_mv.test.log'); const SOME_TYPE = createType({ - switchToModelVersionAt: '8.10.0', name: 'some-type', modelVersions: { 1: { @@ -42,7 +41,6 @@ const SOME_TYPE = createType({ }); const ANOTHER_TYPE = createType({ - switchToModelVersionAt: '8.10.0', name: 'another-type', modelVersions: { '1': { @@ -57,7 +55,6 @@ const ANOTHER_TYPE = createType({ }, }); const ANOTHER_TYPE_UPDATED = createType({ - switchToModelVersionAt: '8.10.0', name: 'another-type', modelVersions: { '1': { diff --git a/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_same_stack_version.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_same_stack_version.test.ts index ad3079e2b9627..82384e1728f0f 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_same_stack_version.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_same_stack_version.test.ts @@ -39,7 +39,6 @@ describe('V2 algorithm - using model versions - upgrade without stack version in name: 'test_mv', namespaceType: 'single', migrations: {}, - switchToModelVersionAt: '8.8.0', modelVersions: { 1: { changes: [], diff --git a/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_stack_version_bump.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_stack_version_bump.test.ts index 60353fd1d12b4..402f9efe81caf 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_stack_version_bump.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group4/v2_with_mv_stack_version_bump.test.ts @@ -54,7 +54,6 @@ describe('V2 algorithm - using model versions - stack version bump scenario', () if (!beforeUpgrade) { Object.assign>(type, { - switchToModelVersionAt: '8.8.0', modelVersions: { 1: { changes: [ @@ -91,7 +90,6 @@ describe('V2 algorithm - using model versions - stack version bump scenario', () name: 'test_mv', namespaceType: 'single', migrations: {}, - switchToModelVersionAt: '8.8.0', modelVersions: { 1: { changes: [], diff --git a/src/core/server/integration_tests/saved_objects/migrations/kibana_migrator_test_kit.fixtures.ts b/src/core/server/integration_tests/saved_objects/migrations/kibana_migrator_test_kit.fixtures.ts index 5b5e6db966ab9..ce5b3b1120608 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/kibana_migrator_test_kit.fixtures.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/kibana_migrator_test_kit.fixtures.ts @@ -39,7 +39,6 @@ const defaultType: SavedObjectsType = { changes: [], }, }, - switchToModelVersionAt: '8.10.0', migrations: {}, }; diff --git a/src/core/server/integration_tests/saved_objects/migrations/zdt_1/basic_downgrade.test.ts b/src/core/server/integration_tests/saved_objects/migrations/zdt_1/basic_downgrade.test.ts index 9523f6723fecb..11566e0f5ebf0 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/zdt_1/basic_downgrade.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/zdt_1/basic_downgrade.test.ts @@ -39,7 +39,6 @@ describe('ZDT upgrades - basic downgrade', () => { keyword: { type: 'keyword' }, }, }, - switchToModelVersionAt: '8.0.0', modelVersions: { 1: { changes: [], @@ -56,7 +55,6 @@ describe('ZDT upgrades - basic downgrade', () => { newField1: { type: 'text' }, }, }, - switchToModelVersionAt: '8.0.0', modelVersions: { 1: { changes: [], diff --git a/src/core/server/integration_tests/saved_objects/migrations/zdt_2/outdated_doc_query.test.ts b/src/core/server/integration_tests/saved_objects/migrations/zdt_2/outdated_doc_query.test.ts index da41ce206332b..7e7ad5a4d6573 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/zdt_2/outdated_doc_query.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/zdt_2/outdated_doc_query.test.ts @@ -52,7 +52,6 @@ describe('getOutdatedDocumentsQuery', () => { return createType({ name: 'test-type', - switchToModelVersionAt: '8.0.0', modelVersions, mappings: { dynamic: false, diff --git a/src/core/server/integration_tests/saved_objects/migrations/zdt_2/sor_higher_version_docs.test.ts b/src/core/server/integration_tests/saved_objects/migrations/zdt_2/sor_higher_version_docs.test.ts index 4c4d208a6af05..8fcabdf22797e 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/zdt_2/sor_higher_version_docs.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/zdt_2/sor_higher_version_docs.test.ts @@ -26,7 +26,6 @@ describe('Higher version doc conversion', () => { const getTestType = () => { return createType({ name: 'test-type', - switchToModelVersionAt: '8.0.0', modelVersions: { 1: { changes: [], diff --git a/src/core/server/integration_tests/saved_objects/migrations/zdt_2/v2_to_zdt_partial_failure.test.ts b/src/core/server/integration_tests/saved_objects/migrations/zdt_2/v2_to_zdt_partial_failure.test.ts index 093b18eee9b56..ec7bd0202da84 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/zdt_2/v2_to_zdt_partial_failure.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/zdt_2/v2_to_zdt_partial_failure.test.ts @@ -47,7 +47,6 @@ describe('ZDT with v2 compat - recovering from partially migrated state', () => const typeFailingBetween = createType({ ...typeBefore, - switchToModelVersionAt: '8.0.0', modelVersions: { 1: { changes: [ @@ -72,7 +71,6 @@ describe('ZDT with v2 compat - recovering from partially migrated state', () => const typeAfter = createType({ ...typeBefore, - switchToModelVersionAt: '8.0.0', modelVersions: { 1: { changes: [ diff --git a/src/core/server/integration_tests/saved_objects/migrations/zdt_v2_compat/switch_to_model_version.test.ts b/src/core/server/integration_tests/saved_objects/migrations/zdt_v2_compat/switch_to_model_version.test.ts index 4aff713b19d78..e313182b693f3 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/zdt_v2_compat/switch_to_model_version.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/zdt_v2_compat/switch_to_model_version.test.ts @@ -68,7 +68,6 @@ describe('ZDT with v2 compat - type switching from migration to model version', }; }, }, - switchToModelVersionAt: '8.0.0', modelVersions: { 1: { changes: [ diff --git a/src/core/server/integration_tests/saved_objects/service/lib/bulk_update.test.ts b/src/core/server/integration_tests/saved_objects/service/lib/bulk_update.test.ts index 986a06b57f92d..e961f11c7021a 100644 --- a/src/core/server/integration_tests/saved_objects/service/lib/bulk_update.test.ts +++ b/src/core/server/integration_tests/saved_objects/service/lib/bulk_update.test.ts @@ -73,7 +73,6 @@ describe('SOR - bulk_update API', () => { management: { importableAndExportable: true, }, - switchToModelVersionAt: '8.10.0', modelVersions: versionMap, }; }; @@ -117,7 +116,6 @@ describe('SOR - bulk_update API', () => { management: { importableAndExportable: true, }, - switchToModelVersionAt: '8.10.0', modelVersions: versionOtherMap, }; }; @@ -134,7 +132,6 @@ describe('SOR - bulk_update API', () => { management: { importableAndExportable: true, }, - switchToModelVersionAt: '8.10.0', modelVersions: {}, }; }; diff --git a/src/core/server/integration_tests/saved_objects/service/lib/update.test.ts b/src/core/server/integration_tests/saved_objects/service/lib/update.test.ts index bf83b2cfd07ea..95d34b1403d85 100644 --- a/src/core/server/integration_tests/saved_objects/service/lib/update.test.ts +++ b/src/core/server/integration_tests/saved_objects/service/lib/update.test.ts @@ -69,7 +69,6 @@ describe('SOR - update API', () => { management: { importableAndExportable: true, }, - switchToModelVersionAt: '8.10.0', modelVersions: versionMap, }; }; @@ -86,7 +85,6 @@ describe('SOR - update API', () => { management: { importableAndExportable: true, }, - switchToModelVersionAt: '8.10.0', modelVersions: {}, }; }; diff --git a/src/core/test-helpers/model-versions/src/model_version_tester.ts b/src/core/test-helpers/model-versions/src/model_version_tester.ts index 31553a0f4edc3..7c30aa355b5e0 100644 --- a/src/core/test-helpers/model-versions/src/model_version_tester.ts +++ b/src/core/test-helpers/model-versions/src/model_version_tester.ts @@ -15,7 +15,6 @@ import type { SavedObjectsType, SavedObject } from '@kbn/core-saved-objects-serv import { modelVersionToVirtualVersion, SavedObjectTypeRegistry, - globalSwitchToModelVersionAt, } from '@kbn/core-saved-objects-base-server-internal'; import { DocumentMigrator } from '@kbn/core-saved-objects-migration-server-internal'; @@ -81,10 +80,7 @@ export const createModelVersionTestMigrator = ({ type: SavedObjectsType; }): ModelVersionTestMigrator => { const typeRegistry = new SavedObjectTypeRegistry(); - typeRegistry.registerType({ - switchToModelVersionAt: globalSwitchToModelVersionAt, - ...type, - }); + typeRegistry.registerType(type); const logger = loggerMock.create(); diff --git a/x-pack/platform/plugins/shared/cases/server/saved_object_types/cases/cases.ts b/x-pack/platform/plugins/shared/cases/server/saved_object_types/cases/cases.ts index 0cf1905ca0cf4..518c51fef2f8b 100644 --- a/x-pack/platform/plugins/shared/cases/server/saved_object_types/cases/cases.ts +++ b/x-pack/platform/plugins/shared/cases/server/saved_object_types/cases/cases.ts @@ -24,7 +24,6 @@ export const createCaseSavedObjectType = ( logger: Logger ): SavedObjectsType => ({ name: CASE_SAVED_OBJECT, - switchToModelVersionAt: '8.10.0', indexPattern: ALERTING_CASES_SAVED_OBJECT_INDEX, hidden: true, namespaceType: 'multiple-isolated', diff --git a/x-pack/solutions/observability/plugins/slo/server/saved_objects/slo.ts b/x-pack/solutions/observability/plugins/slo/server/saved_objects/slo.ts index 1b594db90ae79..dd41f9031de26 100644 --- a/x-pack/solutions/observability/plugins/slo/server/saved_objects/slo.ts +++ b/x-pack/solutions/observability/plugins/slo/server/saved_objects/slo.ts @@ -36,7 +36,6 @@ export const slo: SavedObjectsType = { name: SO_SLO_TYPE, hidden: false, namespaceType: 'multiple-isolated', - switchToModelVersionAt: '8.10.0', modelVersions: { 1: { changes: [ diff --git a/x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin/server/index.ts b/x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin/server/index.ts index 19781d61bbc5e..817a13a5d3d47 100644 --- a/x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin/server/index.ts +++ b/x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin/server/index.ts @@ -317,7 +317,6 @@ function defineModelVersionWithMigration(core: CoreSetup, deps: Pl hidden: false, management: { importableAndExportable: true }, namespaceType: 'multiple-isolated', - switchToModelVersionAt: '8.10.0', mappings: { properties: { nonEncryptedAttribute: {