From c0e22792d06113daaa3b0935dfbdb3d223af6fda Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 28 Nov 2022 11:40:39 -0500 Subject: [PATCH] cascade delete services when removing environment --- controller/disable.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/controller/disable.go b/controller/disable.go index 456ed357..5f84cec1 100644 --- a/controller/disable.go +++ b/controller/disable.go @@ -107,6 +107,15 @@ func (self *disableHandler) removeServicesForEnvironment(envId int, tx *sqlx.Tx, } func (self *disableHandler) removeEnvironment(envId int, tx *sqlx.Tx) error { + svcs, err := str.FindServicesForEnvironment(envId, tx) + if err != nil { + return errors.Wrapf(err, "error finding services for environment '%d'", envId) + } + for _, svc := range svcs { + if err := str.DeleteService(svc.Id, tx); err != nil { + return errors.Wrapf(err, "error deleting service '%d' for environment '%d'", svc.Id, envId) + } + } if err := str.DeleteEnvironment(envId, tx); err != nil { return errors.Wrapf(err, "error deleting environment '%d'", envId) }