directus / directus/directus

Retention fails with FK violation on directus_revisions_parent_foreign (still broken in v11.15.x)

Open
#26,747 1 comment 1 reaction 0 assignees View on GitHub
Bug Engine High Impact Low Reach
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.