Compare commits
No commits in common. "c75e3d250b921deb58d78f2b3a65b67b6a161a31" and "a600a7ad3353cd9ca204bd7e3a164ecb42764ab6" have entirely different histories.
c75e3d250b
...
a600a7ad33
@ -1 +1 @@
|
|||||||
v20260106-06-customers-delete-fk-cascade-fix
|
v20260106-05-jobs-row-click-and-archive-button-move
|
||||||
|
|||||||
@ -100,9 +100,6 @@ 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,39 +1137,6 @@ 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,14 +38,6 @@
|
|||||||
- 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