-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] [Canvas] Migrate saved object mappings and migrations to Kibana…
… Platform (#58891) (#63704) * [Canvas] Migrate saved object mappings and migrations to Kibana Platform (#58891) * Move saved object mappings and migratins to kibana platform * Remove ts-ignore Co-authored-by: Elastic Machine <[email protected]> * Fix types Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
f8563f8
commit c58f7f5
Showing
8 changed files
with
101 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/canvas/server/saved_objects/migrations/remove_attributes_id.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { removeAttributesId } from './remove_attributes_id'; | ||
|
||
const context: any = { | ||
log: jest.fn(), | ||
}; | ||
|
||
describe(`removeAttributesId`, () => { | ||
it('does not throw error on empty object', () => { | ||
const migratedDoc = removeAttributesId({} as any, context); | ||
expect(migratedDoc).toMatchInlineSnapshot(`Object {}`); | ||
}); | ||
|
||
it('removes id from "attributes"', () => { | ||
const migratedDoc = removeAttributesId( | ||
{ | ||
foo: true, | ||
attributes: { | ||
id: '123', | ||
bar: true, | ||
}, | ||
} as any, | ||
context | ||
); | ||
expect(migratedDoc).toMatchInlineSnapshot(` | ||
Object { | ||
"attributes": Object { | ||
"bar": true, | ||
}, | ||
"foo": true, | ||
} | ||
`); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/canvas/server/saved_objects/migrations/remove_attributes_id.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SavedObjectMigrationFn } from 'src/core/server'; | ||
|
||
export const removeAttributesId: SavedObjectMigrationFn = doc => { | ||
if (typeof doc.attributes === 'object' && doc.attributes !== null) { | ||
delete (doc.attributes as any).id; | ||
} | ||
return doc; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SavedObjectsType } from 'src/core/server'; | ||
import { CANVAS_TYPE } from '../../../../legacy/plugins/canvas/common/lib/constants'; | ||
import { removeAttributesId } from './migrations/remove_attributes_id'; | ||
|
||
export const workpadType: SavedObjectsType = { | ||
name: CANVAS_TYPE, | ||
hidden: false, | ||
namespaceType: 'single', | ||
mappings: { | ||
dynamic: false, | ||
properties: { | ||
name: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
'@timestamp': { type: 'date' }, | ||
'@created': { type: 'date' }, | ||
}, | ||
}, | ||
migrations: { | ||
'7.0.0': removeAttributesId, | ||
}, | ||
}; |