Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dev_docs/tutorials/saved_objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
11 changes: 0 additions & 11 deletions docs/extend/saved-objects-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -198,7 +195,6 @@ const myType: SavedObjectsType = {
```ts
const myType: SavedObjectsType = {
name: 'test',
switchToModelVersionAt: '8.10.0',
modelVersions: {
1: {
changes: [
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const typedef: Partial<SavedObjectsType> = {
count: schema.number(),
}),
},
switchToModelVersionAt: '8.10.0',
};

export const typedef1: Partial<SavedObjectsType> = {
Expand All @@ -53,7 +52,6 @@ export const typedef1: Partial<SavedObjectsType> = {
count: schema.number(),
}),
},
switchToModelVersionAt: '8.10.0',
modelVersions: {
'1': {
changes: [
Expand Down Expand Up @@ -96,7 +94,6 @@ export const typedef2: Partial<SavedObjectsType> = {
foo: schema.string(),
}),
},
switchToModelVersionAt: '8.10.0',
modelVersions: {
'1': {
changes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('SavedObjectsRepository#createRepository', () => {
name: { type: 'keyword' },
},
},
migrations: {},
});

typeRegistry.registerType({
Expand All @@ -43,7 +42,6 @@ describe('SavedObjectsRepository#createRepository', () => {
name: { type: 'keyword' },
},
},
migrations: {},
});
typeRegistry.registerType({
name: 'hiddenType',
Expand All @@ -54,7 +52,6 @@ describe('SavedObjectsRepository#createRepository', () => {
name: { type: 'keyword' },
},
},
migrations: {},
});

const migrator = kibanaMigratorMock.create({ types: typeRegistry.getAllTypes() });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ export const createType = (
? mappings.properties[type].properties!
: {}) as SavedObjectsMappingProperties,
},
migrations: { '1.1.1': (doc) => doc },
...parts,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export {
} from './src/utils';
export {
modelVersionVirtualMajor,
globalSwitchToModelVersionAt,
assertValidModelVersion,
isVirtualModelVersion,
virtualVersionToModelVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import {
getModelVersionMapForTypes,
getLatestModelVersion,
getLatestMigrationVersion,
getCurrentVirtualVersion,
getVirtualVersionMap,
getLatestMappingsVersionNumber,
getLatestMappingsModelVersion,
getLatestMappingsVirtualVersionMap,
} from './version_map';

Expand Down Expand Up @@ -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,
Expand All @@ -267,7 +229,6 @@ describe('ModelVersion map utilities', () => {
}),
buildType({
name: 'dolly',
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
Expand Down Expand Up @@ -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,
Expand All @@ -409,7 +332,6 @@ describe('ModelVersion map utilities', () => {
}),
buildType({
name: 'dolly',
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<string>((memo, current) => {
return Semver.gt(memo, current) ? memo : current;
}, '0.0.0');
};

/**
* Build a version map for the given types.
*/
Expand All @@ -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);
};

/**
Expand Down Expand Up @@ -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);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const createType = (type: Partial<SavedObjectsType>): SavedObjectsType => ({
hidden: false,
namespaceType: 'single' as 'single',
mappings: { properties: {} },
migrations: {},
...type,
});

Expand Down Expand Up @@ -302,9 +301,6 @@ describe('SavedObjectTypeRegistry', () => {
registry.registerType(
createType({
name: 'typeB',
migrations: {
'1.0.0': jest.fn(),
},
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export const cleanupUnknownAndExcluded = ({
},
};

if (2 === 2) {
return TaskEither.right();
}
return deleteByQuery({
client,
indexName,
Expand Down
Loading