Clear taxable_taxonomies created by audit records on taxonomy deletion
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "taxonomies" violates foreign key constraint "taxable_taxonomies_taxonomy_id_fk" on table "taxable_taxonomies"
DETAIL: Key (id)=(61304186) is still referenced from table "taxable_taxonomies".
: DELETE FROM "taxonomies" WHERE "taxonomies"."type" IN ('Organization') AND "taxonomies"."id" = $1
foreman-tasks (0.13.0) app/models/foreman_tasks/concerns/action_triggering.rb:35:in `block in destroy'
foreman-tasks (0.13.0) app/models/foreman_tasks/concerns/action_triggering.rb:121:in `dynflow_task_wrap'
foreman-tasks (0.13.0) app/models/foreman_tasks/concerns/action_triggering.rb:35:in `destroy'
Explanation on above error:
- For many resources, we have added audited which covers all CURD actions.
- Though we already added taxable_taxonomies :dependent => :destroy, when we try to destroy any taxonomy, it tries to destroy all dependent resources.
And which leads to many more audit records.
- These audit records creation occured after the deletion of existing taxable_taxonomies by :dependent => :destroy.
- For these audit records, taxable_taxonomies records get created which needs to be clear before taxonomy destroy.