@@ -14,6 +14,8 @@ import {
1414import * as Registry from '../../registry' ;
1515import { CallESAsCurrentUser } from '../../../../types' ;
1616import { saveInstalledEsRefs } from '../../packages/install' ;
17+ import { getInstallationObject } from '../../packages' ;
18+ import { deletePipelineRefs } from './remove' ;
1719
1820interface RewriteSubstitution {
1921 source : string ;
@@ -31,6 +33,7 @@ export const installPipelines = async (
3133 // it can be created pointing to the new template, without removing the old one and effecting data
3234 // so do not remove the currently installed pipelines here
3335 const dataStreams = installablePackage . data_streams ;
36+ const { name : pkgName , version : pkgVersion } = installablePackage ;
3437 if ( ! dataStreams ?. length ) return [ ] ;
3538 const pipelinePaths = paths . filter ( ( path ) => isPipeline ( path ) ) ;
3639 // get and save pipeline refs before installing pipelines
@@ -50,6 +53,20 @@ export const installPipelines = async (
5053 acc . push ( ...pipelineObjectRefs ) ;
5154 return acc ;
5255 } , [ ] ) ;
56+
57+ // check that we don't duplicate the pipeline refs if the user is reinstalling
58+ const installedPkg = await getInstallationObject ( {
59+ savedObjectsClient,
60+ pkgName,
61+ } ) ;
62+ if ( ! installedPkg ) throw new Error ( "integration wasn't found while installing pipelines" ) ;
63+ // remove the current pipeline refs, if any exist, associated with this version before saving new ones so no duplicates occur
64+ await deletePipelineRefs (
65+ savedObjectsClient ,
66+ installedPkg . attributes . installed_es ,
67+ pkgName ,
68+ pkgVersion
69+ ) ;
5370 await saveInstalledEsRefs ( savedObjectsClient , installablePackage . name , pipelineRefs ) ;
5471 const pipelines = dataStreams . reduce < Array < Promise < EsAssetReference [ ] > > > ( ( acc , dataStream ) => {
5572 if ( dataStream . ingest_pipeline ) {
0 commit comments