diff --git a/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts b/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts index b6e6d2c24b7fc..ac91c5a92048a 100644 --- a/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts +++ b/src/plugins/dashboard/server/saved_objects/dashboard_migrations.ts @@ -101,6 +101,17 @@ const migrations700: SavedObjectMigrationFn = (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), diff --git a/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts b/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts index d517af0dd03c3..3d7aadab5602c 100644 --- a/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts +++ b/src/plugins/dashboard/server/saved_objects/migrate_match_all_query.ts @@ -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 = (doc) => { const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON'); diff --git a/src/plugins/discover/server/saved_objects/search_migrations.test.ts b/src/plugins/discover/server/saved_objects/search_migrations.test.ts index 089d201afe94d..3324a2d93f5ad 100644 --- a/src/plugins/discover/server/saved_objects/search_migrations.test.ts +++ b/src/plugins/discover/server/saved_objects/search_migrations.test.ts @@ -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']; @@ -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); }); }); }); diff --git a/src/plugins/discover/server/saved_objects/search_migrations.ts b/src/plugins/discover/server/saved_objects/search_migrations.ts index 3851571dbdff5..fdb086bd17a2d 100644 --- a/src/plugins/discover/server/saved_objects/search_migrations.ts +++ b/src/plugins/discover/server/saved_objects/search_migrations.ts @@ -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 = (doc) => { const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON'); @@ -130,6 +129,7 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn = (doc) = }; export const searchMigrations = { + '6.7.2': flow(migrateMatchAllQuery), '7.0.0': flow(setNewReferences), '7.4.0': flow(migrateSearchSortToNestedArray), '7.9.3': flow(migrateMatchAllQuery), diff --git a/src/plugins/visualizations/server/saved_objects/visualization_migrations.test.ts b/src/plugins/visualizations/server/saved_objects/visualization_migrations.test.ts index 508c54a6249e2..c4ee92194ec36 100644 --- a/src/plugins/visualizations/server/saved_objects/visualization_migrations.test.ts +++ b/src/plugins/visualizations/server/saved_objects/visualization_migrations.test.ts @@ -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) => @@ -31,6 +75,10 @@ describe('migration visualization', () => { ); let doc: any; + describe('migrateMatchAllQuery', () => { + testMigrateMatchAllQuery(migrate); + }); + describe('date histogram time zone removal', () => { beforeEach(() => { doc = { @@ -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[0], savedObjectMigrationContext ); - expect(migratedDoc).toEqual({ - type: 'area', - attributes: { - kibanaSavedObjectMeta: 'kibanaSavedObjectMeta', - }, - }); + describe('migrateMatchAllQuery', () => { + testMigrateMatchAllQuery(migrate); }); }); diff --git a/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts b/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts index 287c863220435..fbeefacf6035f 100644 --- a/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts +++ b/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts @@ -659,8 +659,7 @@ const migrateTableSplits: SavedObjectMigrationFn = (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 = (doc) => { const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON'); @@ -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,