Skip to content

Commit

Permalink
return migration into 6.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Sep 30, 2020
1 parent b0e1ac7 commit e4da267
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 96 deletions.
11 changes: 11 additions & 0 deletions src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ const migrations700: SavedObjectMigrationFn<any, any> = (doc): DashboardDoc700To
};

export const dashboardSavedObjectTypeMigrations = {
/**
* We need to have this migration twice, once with a version prior to 7.0.0 once with a version
* after it. The reason for that is, that this migration has been introduced once 7.0.0 was already
* released. Thus a user who already had 7.0.0 installed already got the 7.0.0 migrations below running,
* so we need a version higher than that. But this fix was backported to the 6.7 release, meaning if we
* would only have the 7.0.1 migration in here a user on the 6.7 release will migrate their saved objects
* to the 7.0.1 state, and thus when updating their Kibana to 7.0, will never run the 7.0.0 migrations introduced
* in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
* only contained the 6.7.2 migration and not the 7.0.1 migration.
*/
'6.7.2': flow(migrateMatchAllQuery),
'7.0.0': flow(migrations700),
'7.3.0': flow(migrations730),
'7.9.3': flow(migrateMatchAllQuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';
* This migration script is related to:
* @link https://github.com/elastic/kibana/pull/62194
* @link https://github.com/elastic/kibana/pull/14644
* Important: migration scripts was moved from 6.7.2 -> 7.9.3
* This is only a problem when you import an object from 5.x into 6.x but to be sure that all saved objects migrated that script was added into 7.9.3
* This is only a problem when you import an object from 5.x into 6.x but to be sure that all saved objects migrated we should execute it twice in 6.7.2 and 7.9.3
*/
export const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = (doc) => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
Expand Down
104 changes: 59 additions & 45 deletions src/plugins/discover/server/saved_objects/search_migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,64 @@ import { searchMigrations } from './search_migrations';

const savedObjectMigrationContext = (null as unknown) as SavedObjectMigrationContext;

const testMigrateMatchAllQuery = (migrationFn: Function) => {
it('should migrate obsolete match_all query', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
query: {
match_all: {},
},
}),
},
},
},
savedObjectMigrationContext
);
const migratedSearchSource = JSON.parse(
migratedDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON
);

expect(migratedSearchSource).toEqual({
query: {
query: '',
language: 'kuery',
},
});
});

it('should return original doc if searchSourceJSON cannot be parsed', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
},
savedObjectMigrationContext
);

expect(migratedDoc).toEqual({
type: 'search',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
});
});
};

describe('migration search', () => {
describe('6.7.2', () => {
const migrationFn = searchMigrations['6.7.2'];

describe('migrateMatchAllQuery', () => {
testMigrateMatchAllQuery(migrationFn);
});
});

describe('7.0.0', () => {
const migrationFn = searchMigrations['7.0.0'];

Expand Down Expand Up @@ -300,51 +357,8 @@ Object {
describe('7.9.3', () => {
const migrationFn = searchMigrations['7.9.3'];

it('should migrate obsolete match_all query', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
query: {
match_all: {},
},
}),
},
},
},
savedObjectMigrationContext
);
const migratedSearchSource = JSON.parse(
migratedDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON
);

expect(migratedSearchSource).toEqual({
query: {
query: '',
language: 'kuery',
},
});
});

it('should return original doc if searchSourceJSON cannot be parsed', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
},
savedObjectMigrationContext
);

expect(migratedDoc).toEqual({
type: 'search',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
});
describe('migrateMatchAllQuery', () => {
testMigrateMatchAllQuery(migrationFn);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';
* This migration script is related to:
* @link https://github.com/elastic/kibana/pull/62194
* @link https://github.com/elastic/kibana/pull/14644
* Important: migration scripts was moved from 6.7.2 -> 7.9.3
* This is only a problem when you import an object from 5.x into 6.x but to be sure that all saved objects migrated that script was added into 7.9.3
* This is only a problem when you import an object from 5.x into 6.x but to be sure that all saved objects migrated we should execute it twice in 6.7.2 and 7.9.3
*/
const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = (doc) => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
Expand Down Expand Up @@ -130,6 +129,7 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn<any, any> = (doc) =
};

export const searchMigrations = {
'6.7.2': flow(migrateMatchAllQuery),
'7.0.0': flow(setNewReferences),
'7.4.0': flow(migrateSearchSortToNestedArray),
'7.9.3': flow(migrateMatchAllQuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,50 @@ import { SavedObjectMigrationContext, SavedObjectMigrationFn } from 'kibana/serv

const savedObjectMigrationContext = (null as unknown) as SavedObjectMigrationContext;

const testMigrateMatchAllQuery = (migrate: Function) => {
it('should migrate obsolete match_all query', () => {
const migratedDoc = migrate({
type: 'area',
attributes: {
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
query: {
match_all: {},
},
}),
},
},
});

const migratedSearchSource = JSON.parse(
migratedDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON
);

expect(migratedSearchSource).toEqual({
query: {
query: '',
language: 'kuery',
},
});
});

it('should return original doc if searchSourceJSON cannot be parsed', () => {
const migratedDoc = migrate({
type: 'area',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
});

expect(migratedDoc).toEqual({
type: 'area',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
});
});
};

describe('migration visualization', () => {
describe('6.7.2', () => {
const migrate = (doc: any) =>
Expand All @@ -31,6 +75,10 @@ describe('migration visualization', () => {
);
let doc: any;

describe('migrateMatchAllQuery', () => {
testMigrateMatchAllQuery(migrate);
});

describe('date histogram time zone removal', () => {
beforeEach(() => {
doc = {
Expand Down Expand Up @@ -1462,53 +1510,14 @@ describe('migration visualization', () => {
});

describe('7.9.3', () => {
const migrationFn = visualizationSavedObjectTypeMigrations['7.9.3'];

it('should migrate obsolete match_all query', () => {
const migratedDoc = migrationFn(
{
type: 'area',
attributes: {
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
query: {
match_all: {},
},
}),
},
},
},
savedObjectMigrationContext
);
const migratedSearchSource = JSON.parse(
migratedDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON
);

expect(migratedSearchSource).toEqual({
query: {
query: '',
language: 'kuery',
},
});
});

it('should return original doc if searchSourceJSON cannot be parsed', () => {
const migratedDoc = migrationFn(
{
type: 'area',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
},
const migrate = (doc: any) =>
visualizationSavedObjectTypeMigrations['7.9.3'](
doc as Parameters<SavedObjectMigrationFn>[0],
savedObjectMigrationContext
);

expect(migratedDoc).toEqual({
type: 'area',
attributes: {
kibanaSavedObjectMeta: 'kibanaSavedObjectMeta',
},
});
describe('migrateMatchAllQuery', () => {
testMigrateMatchAllQuery(migrate);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@ const migrateTableSplits: SavedObjectMigrationFn<any, any> = (doc) => {
* This migration script is related to:
* @link https://github.com/elastic/kibana/pull/62194
* @link https://github.com/elastic/kibana/pull/14644
* Important: migration scripts was moved from 6.7.2 -> 7.9.3
* This is only a problem when you import an object from 5.x into 6.x but to be sure that all saved objects migrated that script was added into 7.9.3
* This is only a problem when you import an object from 5.x into 6.x but to be sure that all saved objects migrated we should execute it twice in 6.7.2 and 7.9.3
*/
const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = (doc) => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
Expand Down Expand Up @@ -769,7 +768,7 @@ export const visualizationSavedObjectTypeMigrations = {
* in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
* only contained the 6.7.2 migration and not the 7.0.1 migration.
*/
'6.7.2': flow(removeDateHistogramTimeZones),
'6.7.2': flow(migrateMatchAllQuery, removeDateHistogramTimeZones),
'7.0.0': flow(
addDocReferences,
migrateIndexPattern,
Expand Down

0 comments on commit e4da267

Please sign in to comment.