Skip to content

Commit

Permalink
Added datasources migrations to SO
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed May 11, 2020
1 parent 5f545ff commit 9eedd02
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { SavedObjectsServiceSetup, SavedObjectsType } from 'kibana/server';
import { EncryptedSavedObjectsPluginSetup } from '../../encrypted_saved_objects/server';
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
import {
OUTPUT_SAVED_OBJECT_TYPE,
AGENT_CONFIG_SAVED_OBJECT_TYPE,
Expand All @@ -16,7 +16,8 @@ import {
AGENT_ACTION_SAVED_OBJECT_TYPE,
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
GLOBAL_SETTINGS_SAVED_OBJET_TYPE,
} from './constants';
} from '../constants';
import { migrateDatasourcesToV790 } from './migrations/datasources_v790';

/*
* Saved object types and mappings
Expand Down Expand Up @@ -224,6 +225,9 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = {
created_by: { type: 'keyword' },
},
},
migrations: {
'7.9.0': migrateDatasourcesToV790,
},
},
[PACKAGES_SAVED_OBJECT_TYPE]: {
name: PACKAGES_SAVED_OBJECT_TYPE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 'kibana/server';
import { cloneDeep } from 'lodash';
import { Datasource } from '../../types/models';

type Pre790Datasource = Exclude<
Datasource,
'created_on' | 'created_by' | 'updated_on' | 'updated_by'
>;

export const migrateDatasourcesToV790: SavedObjectMigrationFn<
Pre790Datasource,
Datasource
> = doc => {
const updatedDatasource = cloneDeep(doc);
const defDate = new Date().toISOString();

updatedDatasource.attributes.created_by = 'system';
updatedDatasource.attributes.created_on = updatedDatasource?.updated_at ?? defDate;
updatedDatasource.attributes.updated_by = 'system';
updatedDatasource.attributes.updated_on = updatedDatasource?.updated_at ?? defDate;

return updatedDatasource;
};

0 comments on commit 9eedd02

Please sign in to comment.