Skip to content

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Sep 25, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Creating a role with the same name in the same organization is now allowed after the previous role was soft-deleted, preventing erroneous “duplicate” errors.
    • Improves consistency of role management in multi-tenant setups.
  • Chores

    • Database migration to align uniqueness behavior with soft-delete logic.

@coderabbitai
Copy link

coderabbitai bot commented Sep 25, 2025

Walkthrough

Introduces a migration that replaces an existing hard unique constraint on user_roles with a partial unique index excluding soft-deleted rows, and provides a down migration to revert to the prior constraint.

Changes

Cohort / File(s) Summary
Migration: Partial unique index for user_roles
src/database/migrations/20250925122507-update-unique-user-roles.js
Up: drop existing unique constraint if present; create partial unique index on (title, organization_id, tenant_code) with WHERE deleted_at IS NULL. Down: drop partial index; restore original unique constraint without WHERE clause. Exports up/down functions.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as Migration CLI
  participant DB as Database
  participant MIG as 20250925122507-update-unique-user-roles

  rect rgba(220,245,255,0.5)
    note over CLI,MIG: Up migration
    CLI->>MIG: run up(queryInterface, Sequelize)
    MIG->>DB: DROP CONSTRAINT IF EXISTS unique_title_org_id_tenant_code ON user_roles
    MIG->>DB: CREATE UNIQUE INDEX unique_title_org_id_tenant_code ON user_roles(title, organization_id, tenant_code) WHERE deleted_at IS NULL
    DB-->>MIG: OK
  end

  rect rgba(240,235,255,0.5)
    note over CLI,MIG: Down migration
    CLI->>MIG: run down(queryInterface, Sequelize)
    MIG->>DB: DROP INDEX IF EXISTS unique_title_org_id_tenant_code
    MIG->>DB: ADD UNIQUE CONSTRAINT unique_title_org_id_tenant_code ON user_roles(title, organization_id, tenant_code)
    DB-->>MIG: OK
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop through schemas, ears held high,
Nudging constraints as records fly—
Soft-deletes whisper, “Let me be,”
A partial index sets them free.
Unique again where rows still live,
Down we go, should you un-sieve. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely and accurately summarizes the primary change—a database migration to create a partial unique index on user roles with soft-delete semantics—providing clear context without extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch user-role-unique

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5b1348 and 6ad81de.

📒 Files selected for processing (1)
  • src/database/migrations/20250925122507-update-unique-user-roles.js (1 hunks)

@aks30 aks30 merged commit 00e09ab into develop Sep 29, 2025
1 of 2 checks passed
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