Skip to content

fix(api): prevent dropping collection when diff starts with nested meta property (#27877) - #28030

Closed
tagadearpit wants to merge 1 commit into
directus:mainfrom
tagadearpit:fix/schema-apply-nested-meta-delete
Closed

tagadearpit wants to merge 1 commit into
directus:mainfrom
tagadearpit:fix/schema-apply-nested-meta-delete

Conversation

@tagadearpit

@tagadearpit tagadearpit commented Aug 3, 2026 •

Copy link
Copy Markdown

Summary

Fixes #27877 where POST /schema/apply would silently drop a populated collection (DROP TABLE + data loss) when a collection's diff starts with a nested metadata property update or deletion (e.g. { kind: 'D', path: ['meta', 'status'] }), rather than a true collection deletion.

Root Cause

In api/src/utils/schema/apply-diff.ts, collection deletion checks evaluated diff?.[0]?.kind === DiffKind.DELETE unconditionally. Unlike field deletions, which were guarded with !isNestedMetaUpdate(diff?.[0]), collection deletions lacked this guard. As a result, any nested meta.* deletion entry in a collection diff misclassified the collection as deleted, triggering collectionsService.deleteOne and dropping the database table.

Solution

  1. Guarded collection deletion: Updated collectionsToDelete pre-filter and deleteCollections in api/src/utils/schema/apply-diff.ts to require !isNestedMetaUpdate(diff?.[0]).
  2. Collection update routing: Updated collection update logic in api/src/utils/schema/apply-diff.ts to include isNestedMetaUpdate(diff[0]!), ensuring nested metadata modifications route through collectionsService.updateOne.
  3. CLI formatting fix: Updated api/src/cli/commands/schema/apply.ts to format nested metadata modifications as Update <collection> rather than Delete <collection>.
  4. Type signature update: Extended isNestedMetaUpdate type signature to accept SnapshotCollection.
  5. Testing & Changeset: Added unit tests in api/src/utils/schema/apply-diff.test.ts and created patch changeset in .changeset/prevent-collection-drop-nested-meta.md.

@tagadearpit

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@ComfortablyCoding

Copy link
Copy Markdown
Member

Thanks for the contribution!

This PR appears to address an issue that already has an existing PR open (#27880), so I’ll go ahead and close this one to avoid duplicate work.

Before starting work on an issue, please check whether there is already an open PR associated with it. This helps prevent duplicated efforts and makes it easier to coordinate contributions.

Thanks again for taking the time to contribute!

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/schema/apply drops an entire collection (DROP TABLE + data loss, HTTP 204) when a collection's first diff entry is a nested meta delete

2 participants