Enforce parent-scoped folder uniqueness with partial indexes#2219
Merged
MarceloRGonc merged 3 commits intomainfrom Apr 14, 2026
Merged
Enforce parent-scoped folder uniqueness with partial indexes#2219MarceloRGonc merged 3 commits intomainfrom
MarceloRGonc merged 3 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts folder uniqueness semantics to be scoped to a folder’s parent (root vs subfolder), aligning application behavior with new database constraints (OPS-4127).
Changes:
- Update folder lookups to include
parentFolderIdwhen checking for existing folders by display name. - Replace TypeORM
upsertwithinsertfor folder creation and add aQueryFailedErrorfallback ingetOrCreate. - Add a migration that replaces the old global unique index with two partial unique indexes (root vs non-root).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| packages/server/api/src/app/flows/folder/folder.service.ts | Scopes “existing folder” checks by parentFolderId; changes create/getOrCreate behavior around inserts and DB constraint races. |
| packages/server/api/src/app/flows/folder/folder.entity.ts | Removes the previous unique index definition from the entity schema. |
| packages/server/api/src/app/database/migrations/1776097737024-FixFolderUniqueConstraint.ts | Drops old unique indexes and creates new partial unique indexes for root/non-root folders. |
Comments suppressed due to low confidence (1)
packages/server/api/src/app/flows/folder/folder.service.ts:72
updatecan still hit the DB unique index (e.g. concurrent rename/move into same parent) andfolderRepo().update(...)would throw aQueryFailedErrorthat becomes a 500 and may leak DB details. Consider catching unique-constraint failures here and translating them to anApplicationError(e.g.ErrorCode.VALIDATION/ conflict) similar to the pre-check.
await folderRepo().update(folder.id, {
displayName: request.displayName,
parentFolder,
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/server/api/src/app/database/migrations/1776097737024-FixFolderUniqueConstraint.ts
Outdated
Show resolved
Hide resolved
packages/server/api/src/app/database/migrations/1776097737024-FixFolderUniqueConstraint.ts
Outdated
Show resolved
Hide resolved
packages/server/api/src/app/database/migrations/1776097737024-FixFolderUniqueConstraint.ts
Outdated
Show resolved
Hide resolved
|
bigfluffycookie
approved these changes
Apr 14, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Fixes OPS-4127