Skip to content

Commit a78c6d2

Browse files
authored
handle "null" in "timepicker:quickRanges" migration (#95767) (#96317)
# Conflicts: # src/core/server/ui_settings/saved_objects/migrations.test.ts
1 parent fde0fe3 commit a78c6d2

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/core/server/ui_settings/saved_objects/migrations.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,53 @@ describe('ui_settings 7.9.0 migrations', () => {
4444
});
4545
});
4646
});
47+
48+
describe('ui_settings 7.12.0 migrations', () => {
49+
const migration = migrations['7.12.0'];
50+
51+
test('returns doc on empty object', () => {
52+
expect(migration({} as SavedObjectUnsanitizedDoc)).toEqual({
53+
references: [],
54+
});
55+
});
56+
test('properly migrates timepicker:quickRanges', () => {
57+
const initialQuickRange: any = {
58+
from: '123',
59+
to: '321',
60+
display: 'abc',
61+
section: 2,
62+
};
63+
const { section, ...migratedQuickRange } = initialQuickRange;
64+
65+
const doc = {
66+
type: 'config',
67+
id: '8.0.0',
68+
attributes: {
69+
buildNum: 9007199254740991,
70+
'timepicker:quickRanges': JSON.stringify([initialQuickRange]),
71+
},
72+
references: [],
73+
updated_at: '2020-06-09T20:18:20.349Z',
74+
migrationVersion: {},
75+
};
76+
const migrated = migration(doc);
77+
expect(JSON.parse(migrated.attributes['timepicker:quickRanges'])).toEqual([migratedQuickRange]);
78+
});
79+
80+
// https://github.com/elastic/kibana/issues/95616
81+
test('returns doc when "timepicker:quickRanges" is null', () => {
82+
const doc = {
83+
type: 'config',
84+
id: '8.0.0',
85+
attributes: {
86+
buildNum: 9007199254740991,
87+
'timepicker:quickRanges': null,
88+
},
89+
references: [],
90+
updated_at: '2020-06-09T20:18:20.349Z',
91+
migrationVersion: {},
92+
};
93+
const migrated = migration(doc);
94+
expect(migrated).toEqual(doc);
95+
});
96+
});

src/core/server/ui_settings/saved_objects/migrations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const migrations = {
3232
...doc,
3333
...(doc.attributes && {
3434
attributes: Object.keys(doc.attributes).reduce((acc, key) => {
35-
if (key === 'timepicker:quickRanges' && doc.attributes[key].indexOf('section') > -1) {
35+
if (key === 'timepicker:quickRanges' && doc.attributes[key]?.indexOf('section') > -1) {
3636
const ranges = JSON.parse(doc.attributes[key]).map(
3737
({ from, to, display }: { from: string; to: string; display: string }) => {
3838
return {

0 commit comments

Comments
 (0)