From 19fb328602bd097fafb8f68520a343996f7c3791 Mon Sep 17 00:00:00 2001 From: Ivo Oskamp Date: Thu, 8 Jan 2026 14:05:43 +0100 Subject: [PATCH] Auto-commit local changes before build (2026-01-08 14:05:43) --- .last-branch | 2 +- .../src/backend/app/main/routes_customers.py | 8 +++++++- docs/changelog.md | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.last-branch b/.last-branch index 913d3b2..3cbaaf7 100644 --- a/.last-branch +++ b/.last-branch @@ -1 +1 @@ -v20260108-29-inbox-attachment-body-fallback +v20260108-30-customer-delete-ticket-remark-scopes diff --git a/containers/backupchecks/src/backend/app/main/routes_customers.py b/containers/backupchecks/src/backend/app/main/routes_customers.py index f4348ae..688ecb0 100644 --- a/containers/backupchecks/src/backend/app/main/routes_customers.py +++ b/containers/backupchecks/src/backend/app/main/routes_customers.py @@ -100,9 +100,15 @@ def customers_delete(customer_id: int): customer = Customer.query.get_or_404(customer_id) try: - # Prevent FK violations on older schemas and keep jobs for historical reporting. + # Prevent FK violations and keep historical reporting intact. # Jobs are not deleted when removing a customer; they are simply unlinked. Job.query.filter_by(customer_id=customer.id).update({"customer_id": None}) + + # Ticket/remark scoping rows can reference customers directly (FK), + # so remove those links first to allow the customer to be deleted. + TicketScope.query.filter_by(customer_id=customer.id).delete(synchronize_session=False) + RemarkScope.query.filter_by(customer_id=customer.id).delete(synchronize_session=False) + db.session.delete(customer) db.session.commit() flash("Customer deleted.", "success") diff --git a/docs/changelog.md b/docs/changelog.md index 137784d..0cda6df 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -29,6 +29,15 @@ - Add legacy fallback in the Inbox message detail API: when stored bodies are empty/whitespace, extract the first HTML attachment from EML and render it. - Improve Inbox iframe rendering: if the returned content is a full HTML document (common for report attachments), render it directly instead of wrapping it. +--- + +## v20260108-29-customer-delete-ticket-remark-scopes + +- Updated customer deletion logic to allow removal of customers that have linked tickets or remarks. +- Added explicit cleanup of related TicketScope and RemarkScope records before deleting the customer. +- Ensured jobs linked to the customer are safely unassigned to prevent foreign key constraint errors. +- Prevented deletion failures caused by existing ticket and remark relationships. + ================================================================================================================================================ ## v0.1.18 -- 2.45.2