Bug: Enabled AI Catalog items blocks Project destroy
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
About
We have an on_delete: :restrict which prevents us from deleting projects that have items with consumers:
Problem
In the scenario where a project has published a public item to the catalog that has been used by another project, the project would now be blocked from deletion.
We don't want to block project deletion.
Proposal
Instead we want to hook into the Projects::DestroyService and handle AI Catalog data in a way that supports project deletion, but does not break other customers' workflows.
When a project is deleted, and it owns any public Item records that have ItemConsumers associated with other projects:
- Unset the
projectassociation on theItemrecord (it will now be "owned" only be the organization) - Soft delete the record
But if the project only owns Item records used by itself, do nothing to allow the deletion to happen and the FKs to clean up the data. This would require changing the FK to be a cascading delete. Alternatively, we might want to keep the current on delete restrict, but manually clean up the project owned data within the project deletion service.
The hook we need might be Projects::DestroyService::#destroy_project_related_records.