Repository navigation
fix(api): prevent dropping collection when diff starts with nested meta property (#27877) - #28030
Closed
tagadearpit wants to merge 1 commit into
Closed
tagadearpit wants to merge 1 commit into
tagadearpit wants to merge 1 commit into
Conversation
Author
|
I have read the CLA Document and I hereby sign the CLA |
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! |
tagadearpit
added a commit
to tagadearpit/directus
that referenced
this pull request
Aug 3, 2026
Merged
1 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #27877 where
POST /schema/applywould 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 evaluateddiff?.[0]?.kind === DiffKind.DELETEunconditionally. Unlike field deletions, which were guarded with!isNestedMetaUpdate(diff?.[0]), collection deletions lacked this guard. As a result, any nestedmeta.*deletion entry in a collection diff misclassified the collection as deleted, triggeringcollectionsService.deleteOneand dropping the database table.Solution
collectionsToDeletepre-filter anddeleteCollectionsinapi/src/utils/schema/apply-diff.tsto require!isNestedMetaUpdate(diff?.[0]).api/src/utils/schema/apply-diff.tsto includeisNestedMetaUpdate(diff[0]!), ensuring nested metadata modifications route throughcollectionsService.updateOne.api/src/cli/commands/schema/apply.tsto format nested metadata modifications asUpdate <collection>rather thanDelete <collection>.isNestedMetaUpdatetype signature to acceptSnapshotCollection.api/src/utils/schema/apply-diff.test.tsand created patch changeset in.changeset/prevent-collection-drop-nested-meta.md.