Skip to content
3 changes: 3 additions & 0 deletions packages/kbn-check-saved-objects-cli/current_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@
"fields": {
"keyword": {
"type": "keyword"
},
"text": {
"type": "text"
}
},
"type": "unsigned_long"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"canvas-element": "288fd8d216eb49cbeb5e8f7491f207ef074b80dd",
"canvas-workpad": "5cd605383a100a27941cca6cbf2d954aa96a16e2",
"canvas-workpad-template": "f9a6ffab76ddfcd8fa3823002aa576c8f1d0e686",
"cases": "2377506cc9ce6506bfc1c1b04cb8aed87d3fecab",
"cases": "9f91e6f385bbc09dc16c63309363822700a1ae53",
"cases-comments": "235311d14fbba84faf8ce1f32c31ddb3a435bacb",
"cases-configure": "66d4c64d83b464f5166005b8ffa03b721fcaaf8b",
"cases-connector-mappings": "877bb4d52e9821e330622bd75fba799490ec6952",
Expand Down Expand Up @@ -406,9 +406,10 @@ describe('checking migration metadata changes on all registered SO types', () =>
"canvas-workpad-template|warning: The SO type owner should ensure these transform functions DO NOT mutate after they are defined.",
"================================================================================================================================",
"cases|global: 58923536ede82aed6c22799b52c4f51f4bf66aba",
"cases|mappings: 04e7b5c53626eb3e5e08837830697951084d9d7d",
"cases|mappings: 2ee9c5f866298b30dbdcfd22d952ebbecb6582fb",
"cases|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
"cases|10.4.0: dad403e8d7d405cfb7f05d2972988408eb1a6ffb",
"cases|10.5.0: 96204bccc728de96e75fd5cc7d82c5990429fbf6",
"cases|10.4.0: 3b1d7eee41677f6b5e78b5d3b6108e6c12ae0222",
"cases|10.3.0: e75b333589e368f47fb160e6dd01200590e3c313",
"cases|10.2.0: bf34bde323a6d193f85d11a9ca87d52263beace6",
"cases|10.1.0: 2084c62dbe41da4fa3560ff80fe37af3bc0cc15c",
Expand Down Expand Up @@ -1255,7 +1256,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"canvas-element": "10.0.0",
"canvas-workpad": "10.0.0",
"canvas-workpad-template": "10.0.0",
"cases": "10.4.0",
"cases": "10.5.0",
"cases-comments": "10.1.0",
"cases-configure": "10.0.0",
"cases-connector-mappings": "10.0.0",
Expand Down Expand Up @@ -1402,7 +1403,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"canvas-element": "8.9.0",
"canvas-workpad": "8.9.0",
"canvas-workpad-template": "8.9.0",
"cases": "10.4.0",
"cases": "10.5.0",
"cases-comments": "10.1.0",
"cases-configure": "7.15.0",
"cases-connector-mappings": "7.14.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import { CASE_SAVED_OBJECT } from '../../../common/constants';
import type { CasePersistedAttributes } from '../../common/types/case';
import { handleExport } from '../import_export/export';
import { caseMigrations } from '../migrations';
import { modelVersion1, modelVersion2, modelVersion3, modelVersion4 } from './model_versions';
import {
modelVersion1,
modelVersion2,
modelVersion3,
modelVersion4,
modelVersion5,
} from './model_versions';
import { handleImport } from '../import_export/import';

export const createCaseSavedObjectType = (
Expand Down Expand Up @@ -245,6 +251,9 @@ export const createCaseSavedObjectType = (
keyword: {
type: 'keyword',
},
text: {
type: 'text',
},
},
},
},
Expand All @@ -255,6 +264,7 @@ export const createCaseSavedObjectType = (
2: modelVersion2,
3: modelVersion3,
4: modelVersion4,
5: modelVersion5,
},
management: {
importableAndExportable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { modelVersion1 } from './model_version_1';
export { modelVersion2 } from './model_version_2';
export { modelVersion3 } from './model_version_3';
export { modelVersion4 } from './model_version_4';
export { modelVersion5 } from './model_version_5';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { SavedObjectsModelVersion } from '@kbn/core-saved-objects-server';
import { casesSchemaV5 } from '../schemas';

/**
* Adds the incremental_id.keyword field to the cases SO.
*/
export const modelVersion5: SavedObjectsModelVersion = {
changes: [
{
type: 'mappings_addition',
addedMappings: {
incremental_id: {
type: 'unsigned_long',
fields: {
keyword: {
type: 'keyword',
},
text: {
type: 'text',
},
},
},
},
},
],
schemas: {
forwardCompatibility: casesSchemaV5.extends({}, { unknowns: 'ignore' }),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { modelVersion1, modelVersion2, modelVersion3, modelVersion4 } from '.';
import { modelVersion1, modelVersion2, modelVersion3, modelVersion4, modelVersion5 } from '.';

describe('Model versions', () => {
describe('version 1', () => {
Expand Down Expand Up @@ -120,4 +120,29 @@ describe('Model versions', () => {
`);
});
});

describe('version 5', () => {
it('returns version 5 changes correctly', () => {
expect(modelVersion5.changes).toMatchInlineSnapshot(`
Array [
Object {
"addedMappings": Object {
"incremental_id": Object {
"fields": Object {
"keyword": Object {
"type": "keyword",
},
"text": Object {
"type": "text",
},
},
"type": "unsigned_long",
},
},
"type": "mappings_addition",
},
]
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export { casesSchema as casesSchemaV1 } from './v1';
export { casesSchema as casesSchemaV2 } from './v2';
export { casesSchema as casesSchemaV3 } from './v3';
export { casesSchema as casesSchemaV4 } from './v4';
export { casesSchema as casesSchemaV5 } from './v5';
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export * from './v4';
export * from './v5';
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@ export const casesSchema = casesSchemaV3.extends({
time_to_acknowledge: schema.maybe(schema.nullable(schema.number())),
time_to_investigate: schema.maybe(schema.nullable(schema.number())),
time_to_resolve: schema.maybe(schema.nullable(schema.number())),
incremental_id: schema.maybe(
schema.nullable(
schema.oneOf([
schema.number(),
schema.object({
keyword: schema.maybe(schema.string()),
}),
])
)
),
// Also updated mappings for the incremental_id field to multi-field but no declaration necessary
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { casesSchema as casesSchemaV4 } from './v4';

export const casesSchema = // v5
casesSchemaV4.extends({
/* Same fields, just added new multi-type `.text` to increment_id */
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('caseSavedObjectType model version transformations', () => {
});

describe('Model version 3 to 4', () => {
const version4Fields = ['incremental_id.keyword'];
const version4Fields = ['incremental_id'];

it('by default does not add the new fields to the object', () => {
const migrated = migrator.migrate({
Expand All @@ -73,4 +73,20 @@ describe('caseSavedObjectType model version transformations', () => {
});
});
});

describe('Model version 4 to 5', () => {
const version4Fields = ['incremental_id'];

it('by default does not add the new fields to the object', () => {
const migrated = migrator.migrate({
document: createCaseSavedObjectResponse(),
fromVersion: 4,
toVersion: 5,
});

version4Fields.forEach((field) => {
expect(migrated.attributes).not.toHaveProperty(field);
});
});
});
});