Skip to content

Rename roleTargets -> roleTarget#16247

Merged
charlesBochet merged 6 commits intomainfrom
c--rename-role-targets
Dec 2, 2025
Merged

Rename roleTargets -> roleTarget#16247
charlesBochet merged 6 commits intomainfrom
c--rename-role-targets

Conversation

@Weiko
Copy link
Copy Markdown
Member

@Weiko Weiko commented Dec 2, 2025

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Dec 2, 2025

Greptile Overview

Greptile Summary

This PR performs a systematic renaming of the RoleTargetsEntity class and roleTargets database table to the singular forms RoleTargetEntity and roleTarget, improving naming consistency across the codebase. The entity was also moved to a dedicated role-target module for better organization.

Key changes:

  • Database migration renames table from roleTargets to roleTarget along with all associated constraints and indexes
  • Entity class renamed from RoleTargetsEntity to RoleTargetEntity and relocated to engine/metadata-modules/role-target/
  • All imports and repository references updated across 81 files including services, tests, resolvers, and modules
  • Relation property names (like role.roleTargets) intentionally kept plural to indicate array collections, following TypeORM conventions
  • Enhanced workspace cache service with proper parameter validation and exception handling

Additional improvements:

  • New WorkspaceCacheException class added for better error handling
  • Comprehensive test suite added for API key service
  • Cleaned up unused module dependencies

Minor issue:

  • Variable naming inconsistency in new test file (mockroleTargetRepository should be mockRoleTargetRepository)

Confidence Score: 4/5

  • This PR is safe to merge with minor style improvements recommended
  • The refactoring is well-executed with proper database migration, comprehensive updates across the codebase, and good test coverage. The migration includes proper up/down methods. Only minor style issues found (variable naming inconsistency in test file). The changes are primarily mechanical renames with no logic alterations, reducing risk significantly.
  • packages/twenty-server/src/engine/core-modules/api-key/services/tests/api-key.service.spec.ts needs variable naming correction for consistency

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-server/src/database/typeorm/core/migrations/common/1764671363647-renameRoleTargets.ts 5/5 Renamed database table from roleTargets to roleTarget along with all associated constraints and indexes
packages/twenty-server/src/engine/metadata-modules/role-target/role-target.entity.ts 5/5 Entity class renamed from RoleTargetsEntity to RoleTargetEntity and moved to dedicated role-target module
packages/twenty-server/src/engine/metadata-modules/role/role.entity.ts 5/5 Updated import to reference RoleTargetEntity from new location; property name roleTargets (plural) intentionally kept for array relation
packages/twenty-server/src/engine/workspace-cache/services/workspace-cache.service.ts 5/5 Added parameter validation and proper exception handling to getOrRecompute method
packages/twenty-server/src/engine/workspace-cache/exceptions/workspace-cache.exception.ts 5/5 New exception class for workspace cache with proper error codes for missing decorator and invalid parameters
packages/twenty-server/src/engine/core-modules/api-key/services/tests/api-key.service.spec.ts 4/5 New comprehensive test file for API key service; contains variable naming inconsistency (mockroleTargetRepository)

Sequence Diagram

sequenceDiagram
    participant DB as Database
    participant Migration as RenameRoleTargets Migration
    participant Entity as RoleTargetEntity
    participant Role as RoleEntity
    participant Cache as WorkspaceCacheService
    participant Provider as RoleMapCacheService
    
    Note over Migration,DB: Database Schema Rename
    Migration->>DB: Rename table roleTargets → roleTarget
    Migration->>DB: Rename constraints (UNIQUE, CHECK)
    Migration->>DB: Rename indexes
    
    Note over Entity,Role: Entity Layer Updates
    Entity->>Entity: Class renamed RoleTargetsEntity → RoleTargetEntity
    Entity->>Entity: Moved to role-target module
    Role->>Entity: OneToMany relation (property stays plural)
    
    Note over Cache,Provider: Cache Layer Integration
    Provider->>Entity: Inject RoleTargetEntity repository
    Provider->>Cache: Register as WorkspaceCacheProvider
    Cache->>Cache: Validate workspaceId and cache keys
    Cache->>Provider: Call computeForCache(workspaceId)
    Provider->>Entity: Query roleTarget records
    Entity-->>Provider: Return role target data
    Provider-->>Cache: Return computed cache map
    Cache->>Cache: Store in local and Redis cache
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. packages/twenty-server/src/engine/core-modules/api-key/services/__tests__/api-key.service.spec.ts, line 64-68 (link)

    style: update variable reference to match corrected name

    Context Used: Context from dashboard - Ensure parameter names in function calls are clear and consistent with the naming conventions used i... (source)

81 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 2, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:3249

This environment will automatically shut down when the PR is closed or after 5 hours.

@charlesBochet charlesBochet merged commit 13e283f into main Dec 2, 2025
53 checks passed
@charlesBochet charlesBochet deleted the c--rename-role-targets branch December 2, 2025 13:39
@twenty-eng-sync
Copy link
Copy Markdown

Hey @Weiko! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants