diff --git a/db/bolt/integrations.go b/db/bolt/integrations.go index 17afe1f7..4613d979 100644 --- a/db/bolt/integrations.go +++ b/db/bolt/integrations.go @@ -6,6 +6,7 @@ import ( "reflect" "github.com/semaphoreui/semaphore/db" + "go.etcd.io/bbolt" ) /* @@ -145,10 +146,19 @@ func (d *BoltDb) UpdateIntegrationMatcher(projectID int, integrationMatcher db.I return d.updateObject(projectID, db.IntegrationMatcherProps, integrationMatcher) } -func (d *BoltDb) DeleteIntegrationMatcher(projectID int, matcherID int, integrationID int) error { - return d.deleteObject(projectID, db.IntegrationMatcherProps, intObjectID(matcherID), nil) +func (d *BoltDb) deleteIntegrationMatcher(projectID int, matcherID int, integrationID int, tx *bbolt.Tx) error { + return d.deleteObject(projectID, db.IntegrationMatcherProps, intObjectID(matcherID), tx) } + +func (d *BoltDb) DeleteIntegrationMatcher(projectID int, matcherID int, integrationID int) error { + return d.deleteIntegrationMatcher(projectID, matcherID, integrationID, nil) +} + func (d *BoltDb) DeleteIntegration(projectID int, integrationID int) error { + return d.deleteIntegration(projectID, integrationID, nil) +} + +func (d *BoltDb) deleteIntegration(projectID int, integrationID int, tx *bbolt.Tx) error { matchers, err := d.GetIntegrationMatchers(projectID, db.RetrieveQueryParams{}, integrationID) if err != nil { @@ -156,10 +166,10 @@ func (d *BoltDb) DeleteIntegration(projectID int, integrationID int) error { } for m := range matchers { - d.DeleteIntegrationMatcher(projectID, matchers[m].ID, integrationID) + d.deleteIntegrationMatcher(projectID, matchers[m].ID, integrationID, tx) } - return d.deleteObject(projectID, db.IntegrationProps, intObjectID(integrationID), nil) + return d.deleteObject(projectID, db.IntegrationProps, intObjectID(integrationID), tx) } func (d *BoltDb) GetIntegrationMatcherRefs(projectID int, matcherID int, integrationID int) (db.IntegrationExtractorChildReferrers, error) { diff --git a/db/bolt/template.go b/db/bolt/template.go index 9f23fd10..d7681c07 100644 --- a/db/bolt/template.go +++ b/db/bolt/template.go @@ -172,6 +172,30 @@ func (d *BoltDb) deleteTemplate(projectID int, templateID int, tx *bbolt.Tx) (er } } + // Delete template vaults + vaults, err := d.GetTemplateVaults(projectID, templateID) + if err != nil { + return + } + for _, sch := range vaults { + err = d.deleteTemplateVault(projectID, sch.ID, tx) + if err != nil { + return + } + } + + integrations, err := d.GetIntegrations(projectID, db.RetrieveQueryParams{}) + if err != nil { + return + } + + for _, integration := range integrations { + if integration.TemplateID != templateID { + continue + } + d.deleteIntegration(projectID, integration.ID, tx) + } + return d.deleteObject(projectID, db.TemplateProps, intObjectID(templateID), tx) } diff --git a/db/bolt/template_vault.go b/db/bolt/template_vault.go index ed44e4c4..1b593d77 100644 --- a/db/bolt/template_vault.go +++ b/db/bolt/template_vault.go @@ -69,3 +69,7 @@ func (d *BoltDb) UpdateTemplateVaults(projectID int, templateID int, vaults []db return } + +func (d *BoltDb) deleteTemplateVault(projectID int, vaultID int, tx *bbolt.Tx) error { + return d.deleteObject(projectID, db.TemplateVaultProps, intObjectID(vaultID), tx) +}