Retention fails with FK violation on directus_revisions_parent_foreign (still broken in v11.15.x)
- Dominant language
- TypeScript
- Stars
- 37.9k
- Forks
- 4.9k
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 36
Description
### Describe the Bug
When retention deletes `directus_activity` rows, the cascade deletes their corresponding `directus_revisions`. However, some of those revisions are referenced as `parent` by *newer* revisions outside the retention window. Since `directus_revisions_parent_foreign` has no `ON DELETE` action, PostgreSQL rejects the entire batch.
### related
- #25163 (locked)
- #25842 (fix PR, closed without merge)
### To Reproduce
1. Enable retention (`RETENTION_ENABLED=true`) on an existing instance with data
2. Ensure some revisions have a `parent` value pointing to an older revision
that falls within the retention cutoff
3. Wait for or manually trigger the retention job
## Expected Behavior
Retention cleans up old activity/revision records without errors. Child revisions
whose parent is deleted should have `parent` set to `NULL`.
## Workaround
```sql
ALTER TABLE directus_revisions
DROP CONSTRAINT directus_revisions_parent_foreign,
ADD CONSTRAINT directus_revisions_parent_foreign
FOREIGN KEY (parent) REFERENCES directus_revisions(id) ON DELETE SET NULL;
```
### Directus Version
v11.5.2
### Hosting Strategy
Self-Hosted (Docker Image)
### Database
PostgreSQL 16
Contributor guide
Assessment
This issue has not been assessed yet.