Skip to content
Merged
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
1 change: 0 additions & 1 deletion dev_docs/tutorials/saved_objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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]
mappings: {
dynamic: false,
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 @@ -206,27 +206,23 @@ describe('ModelVersion map utilities', () => {
});

describe('getCurrentVirtualVersion', () => {
it('returns the latest registered migration if switchToModelVersionAt is unset', () => {
it('returns the latest registered migration if modelVersions is not defined', () => {
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', () => {
it('returns the virtual version of the latest model version if the type has modelVersions', () => {
expect(
getCurrentVirtualVersion(
buildType({
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
Expand All @@ -246,7 +242,6 @@ describe('ModelVersion map utilities', () => {
getVirtualVersionMap([
buildType({
name: 'foo',
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
Expand All @@ -261,16 +256,11 @@ describe('ModelVersion map utilities', () => {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
},
modelVersions: {
1: dummyModelVersion(),
},
}),
buildType({
name: 'dolly',
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
modelVersions: {
0: dummyModelVersion(),
},
}),
])
Expand Down Expand Up @@ -344,28 +334,23 @@ describe('ModelVersion map utilities', () => {
});

describe('getLatestMappingsModelVersion', () => {
it('returns the latest registered migration if switchToModelVersionAt is unset', () => {
it('returns the latest registered migration if no model versions are defined', () => {
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', () => {
it('returns the virtual version of the latest model version if model versions are defined', () => {
expect(
getLatestMappingsModelVersion(
buildType({
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
Expand All @@ -386,7 +371,6 @@ describe('ModelVersion map utilities', () => {
getLatestMappingsVirtualVersionMap([
buildType({
name: 'foo',
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
Expand All @@ -402,18 +386,14 @@ describe('ModelVersion map utilities', () => {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
},
modelVersions: {
1: dummyModelVersionWithMappingsChanges(),
2: dummyModelVersion(),
},
}),
buildType({
name: 'dolly',
switchToModelVersionAt: '8.7.0',
migrations: {
'7.17.2': dummyMigration,
'8.6.0': dummyMigration,
},
modelVersions: { 0: dummyModelVersion() },
}),
])
).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ 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.
* It will either be the latest model version or the latest
* migration version for the type if model versions have not been declared.
*/
export const getCurrentVirtualVersion = (type: SavedObjectsType): string => {
if (type.switchToModelVersionAt) {
if (type.modelVersions) {
Copy link
Copy Markdown
Contributor Author

@TinaHeiligers TinaHeiligers Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the main changes in this PR is to assume we can relax the enforced switch to modelVersions. There is a risk that type owners continue to add migrations even though they are deprecated.

const modelVersion = getLatestModelVersion(type);
return modelVersionToVirtualVersion(modelVersion);
} else {
Expand Down Expand Up @@ -106,12 +105,11 @@ 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.
* It will either be a model version or the latest migration version
* if no changed were introduced after enforcing the switch to model versions.
*/
export const getLatestMappingsModelVersion = (type: SavedObjectsType): string => {
if (type.switchToModelVersionAt) {
if (type.modelVersions) {
const modelVersion = getLatestMappingsVersionNumber(type);
return modelVersionToVirtualVersion(modelVersion);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,6 @@ describe('DocumentMigrator', () => {

const fooType = createType({
name: 'foo',
switchToModelVersionAt: '8.5.0',
modelVersions: {
1: {
changes: [],
Expand Down Expand Up @@ -1458,7 +1457,6 @@ describe('DocumentMigrator', () => {

const fooType = createType({
name: 'foo',
switchToModelVersionAt: '8.5.0',
modelVersions: {
1: {
changes: [],
Expand Down
Loading