Auto-commit local changes before build (2026-01-06 11:29:00) #40
@ -1 +1 @@
|
|||||||
v20260106-05-jobs-row-click-and-archive-button-move
|
v20260106-06-customers-delete-fk-cascade-fix
|
||||||
|
|||||||
@ -100,6 +100,9 @@ def customers_delete(customer_id: int):
|
|||||||
customer = Customer.query.get_or_404(customer_id)
|
customer = Customer.query.get_or_404(customer_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Prevent FK violations on older schemas and keep jobs for historical reporting.
|
||||||
|
# Jobs are not deleted when removing a customer; they are simply unlinked.
|
||||||
|
Job.query.filter_by(customer_id=customer.id).update({"customer_id": None})
|
||||||
db.session.delete(customer)
|
db.session.delete(customer)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("Customer deleted.", "success")
|
flash("Customer deleted.", "success")
|
||||||
|
|||||||
@ -1137,6 +1137,39 @@ def migrate_object_persistence_tables() -> None:
|
|||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Ensure existing installations also have ON DELETE CASCADE on customer_objects.customer_id.
|
||||||
|
# Older schemas created the FK without cascade, which blocks deleting customers.
|
||||||
|
conn.execute(
|
||||||
|
text(
|
||||||
|
'''
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.table_constraints tc
|
||||||
|
WHERE tc.table_name = 'customer_objects'
|
||||||
|
AND tc.constraint_type = 'FOREIGN KEY'
|
||||||
|
AND tc.constraint_name = 'customer_objects_customer_id_fkey'
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE customer_objects
|
||||||
|
DROP CONSTRAINT customer_objects_customer_id_fkey;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Recreate with cascade (idempotent via the drop above)
|
||||||
|
ALTER TABLE customer_objects
|
||||||
|
ADD CONSTRAINT customer_objects_customer_id_fkey
|
||||||
|
FOREIGN KEY (customer_id)
|
||||||
|
REFERENCES customers(id)
|
||||||
|
ON DELETE CASCADE;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN
|
||||||
|
-- Constraint already exists with the correct name.
|
||||||
|
NULL;
|
||||||
|
END $$;
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
)
|
||||||
conn.execute(
|
conn.execute(
|
||||||
text(
|
text(
|
||||||
'CREATE INDEX IF NOT EXISTS idx_customer_objects_customer_name ON customer_objects (customer_id, object_name)'
|
'CREATE INDEX IF NOT EXISTS idx_customer_objects_customer_name ON customer_objects (customer_id, object_name)'
|
||||||
|
|||||||
@ -38,6 +38,14 @@
|
|||||||
- Moved the Archive action from the Jobs table to the Job Details page.
|
- Moved the Archive action from the Jobs table to the Job Details page.
|
||||||
- Placed the Archive button next to the existing Delete job button for better consistency.
|
- Placed the Archive button next to the existing Delete job button for better consistency.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v20260106-06-customers-delete-fk-cascade-fix
|
||||||
|
|
||||||
|
- Fixed customer deletion failing with FK constraint errors caused by existing customer_objects rows.
|
||||||
|
- Migration: enforced ON DELETE CASCADE on customer_objects.customer_id by recreating the FK constraint if needed (idempotent).
|
||||||
|
- Customer delete flow: unlinks jobs (sets jobs.customer_id to NULL) before deleting the customer, so historical job/run data remains intact.
|
||||||
|
|
||||||
================================================================================================================================================
|
================================================================================================================================================
|
||||||
## v0.1.16
|
## v0.1.16
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user