Skip to content

Enforce parent-scoped folder uniqueness with partial indexes#2219

Merged
MarceloRGonc merged 3 commits intomainfrom
mg/OPS-4127
Apr 14, 2026
Merged

Enforce parent-scoped folder uniqueness with partial indexes#2219
MarceloRGonc merged 3 commits intomainfrom
mg/OPS-4127

Conversation

@MarceloRGonc
Copy link
Copy Markdown
Contributor

Fixes OPS-4127

Copilot AI review requested due to automatic review settings April 13, 2026 18:02
@linear
Copy link
Copy Markdown

linear bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 parentFolderId when checking for existing folders by display name.
  • Replace TypeORM upsert with insert for folder creation and add a QueryFailedError fallback in getOrCreate.
  • 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

  • update can still hit the DB unique index (e.g. concurrent rename/move into same parent) and folderRepo().update(...) would throw a QueryFailedError that becomes a 500 and may leak DB details. Consider catching unique-constraint failures here and translating them to an ApplicationError (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.

@MarceloRGonc MarceloRGonc changed the title WIP Enforce parent-scoped folder uniqueness with partial indexes Apr 13, 2026
@sonarqubecloud
Copy link
Copy Markdown

@MarceloRGonc MarceloRGonc merged commit 267e6ea into main Apr 14, 2026
21 checks passed
@MarceloRGonc MarceloRGonc deleted the mg/OPS-4127 branch April 14, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants