Soft-deletion of catalog items if a project/group is using it
About
!196764 (merged) has added a table called ai_catalog_item_consumers to track which agents and flows are enabled (or disabled) for a project or group.
Problem
We added a on_delete: :restrict relationship between ai_catalog_items and ai_catalog_item_consumers in !196764 (merged). This prevents a catalog item from being deleted if it is being used by any projects or groups.
This is good because it means all project and group flows will not be broken by something in the catalog being deleted, but it also blocks people from deleting things from the catalog.
Proposal
Mentioned at the bottom of #553334 (comment 2602691120) we should implement a soft deletion of items in the catalog if they are being referenced by something in ai_catalog_item_consumers (regardless of enabled or disabled state).
When deleting a catalog item:
- If there is
1record that references it inai_catalog_item_consumerswe soft delete it - If there are no records that reference it in
ai_catalog_item_consumerswe hard delete it
We could add a new deleted_at timestamp onto ai_catalog_items that could double as the property to determine if something is soft deleted.
We would add, or change, our finder classes to scope out soft-deleted catalog items by default (with the option of scoping them in with a param).
If the only records that reference it also belong to the same group/project, we could provide an experience for them where we allow deleting all their records at the same time.