fix(organizations): allow organization name reuse after deletion#340
fix(organizations): allow organization name reuse after deletion#340PierreLeGuen merged 6 commits intomainfrom
Conversation
Replace the hard unique constraint on name with a partial unique index that only applies to active organizations. This allows users to create organizations with names that were previously used by soft-deleted organizations. Fixes #337
Summary of ChangesHello @PierreLeGuen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug where organization names could not be reused after an organization was soft-deleted, leading to a Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
This comment was marked as resolved.
This comment was marked as resolved.
- Add 'refinery:no-transaction' to run migration outside transaction - Use CREATE UNIQUE INDEX CONCURRENTLY to avoid locking the table during index creation on large tables
There was a problem hiding this comment.
Code Review
This pull request modifies the database migration script V0040__fix_organization_name_unique_constraint.sql to change the unique constraint on the organizations table's name column. The original constraint is dropped, and a new partial unique index unique_organization_name_active_only is created that only applies to active organizations (is_active = true). The review comment suggests using CREATE INDEX CONCURRENTLY to avoid locking the table during index creation, which could cause downtime, and also notes that this command cannot be executed within a transaction block.
crates/database/src/migrations/sql/V0040__fix_organization_name_unique_constraint.sql
Outdated
Show resolved
Hide resolved
Address review feedback: - Add IF EXISTS to DROP CONSTRAINT for idempotent, production-safe migration (follows pattern from V0012) - Add E2E test that validates the fix for #337: 1. Creates an organization 2. Deletes it 3. Re-creates with same name (should succeed)
|
@claude review |
Code Review - PR #340Acknowledgment of previous feedback: The critical issue from the previous review (missing IF EXISTS) has been addressed in commit 05bf341. That issue is now RESOLVED ✓ Analysis SummaryI've analyzed this PR focusing on critical issues. The changes implement a partial unique index for organization names to allow reuse after soft deletion. All previous concerns have been addressed. What's Working Well
Critical Issues FoundNone - All critical issues from previous review have been resolved. Rolling Deployment Safety ✓This migration is safe for rolling deployments:
Minor Observations (non-blocking)
Verdict: ✅ APPROVEDNo critical issues found. This PR is safe to merge. The migration correctly implements a partial unique index following established patterns (V0012), handles concurrent deployment scenarios safely, and includes comprehensive test coverage for the fix. |
Change '-- refinery:no-transaction' to '-- no-transaction' which is the correct format recognized by refinery 0.9.x for non-transactional migrations.
Refinery 0.9.0 always wraps migrations in transactions (see tokio_postgres.rs:42). CREATE INDEX CONCURRENTLY cannot run inside a transaction, so we must use regular CREATE INDEX. For the organizations table (typically small), the brief lock during index creation is acceptable.
Summary
Fixes #337 - Cannot Reuse Name of a Removed Organization
Problem
When creating a new organization with a name that was previously used by a removed/deleted organization, the
POST /v1/organizationsendpoint returns a409 Conflicterror: "Organization already exists".This occurs because the organizations table uses soft deletion (
is_active = false) but has a hard unique constraint onnamethat doesn't account for inactive organizations.Solution
Replace the existing unique constraint with a partial unique index that only applies to active organizations:
This follows the established pattern used in V0012 for the models table's
public_nameconstraint.Changes
V0040__fix_organization_name_unique_constraint.sqlis_active = true)