Skip to content

Commit e3b41b1

Browse files
committed
fix: organization names are not unique
1 parent 72ff424 commit e3b41b1

File tree

1 file changed

+13
-34
lines changed

1 file changed

+13
-34
lines changed

crates/infera-management-core/src/repository/organization.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,13 @@ impl<S: StorageBackend> OrganizationRepository<S> {
4646
.await
4747
.map_err(|e| Error::Internal(format!("Failed to start transaction: {}", e)))?;
4848

49-
// Check name uniqueness
50-
let name_key = Self::org_name_index_key(&org.name);
51-
if self
52-
.storage
53-
.get(&name_key)
54-
.await
55-
.map_err(|e| Error::Internal(format!("Failed to check name uniqueness: {}", e)))?
56-
.is_some()
57-
{
58-
return Err(Error::AlreadyExists(format!(
59-
"Organization name '{}' is already in use",
60-
org.name
61-
)));
62-
}
63-
6449
// Store organization record
65-
txn.set(Self::org_key(org.id), org_data);
50+
let org_key = Self::org_key(org.id);
51+
txn.set(org_key, org_data);
6652

67-
// Store name index
53+
// Store name index for lookup (not enforcing uniqueness)
54+
// Note: If multiple orgs have the same name, this will point to the last one created
55+
let name_key = Self::org_name_index_key(&org.name);
6856
txn.set(name_key, org.id.to_le_bytes().to_vec());
6957

7058
// Increment global count
@@ -147,28 +135,14 @@ impl<S: StorageBackend> OrganizationRepository<S> {
147135
.await
148136
.map_err(|e| Error::Internal(format!("Failed to start transaction: {}", e)))?;
149137

150-
// Check new name uniqueness
151-
let new_name_key = Self::org_name_index_key(&org.name);
152-
if self
153-
.storage
154-
.get(&new_name_key)
155-
.await
156-
.map_err(|e| Error::Internal(format!("Failed to check name uniqueness: {}", e)))?
157-
.is_some()
158-
{
159-
return Err(Error::AlreadyExists(format!(
160-
"Organization name '{}' is already in use",
161-
org.name
162-
)));
163-
}
164-
165138
// Update organization record
166139
txn.set(Self::org_key(org.id), org_data);
167140

168141
// Delete old name index
169142
txn.delete(Self::org_name_index_key(&old_org.name));
170143

171-
// Create new name index
144+
// Create new name index (not enforcing uniqueness)
145+
let new_name_key = Self::org_name_index_key(&org.name);
172146
txn.set(new_name_key, org.id.to_le_bytes().to_vec());
173147

174148
txn.commit().await.map_err(|e| {
@@ -556,7 +530,12 @@ mod tests {
556530
let org2 =
557531
Organization::new(101, "Test Org".to_string(), OrganizationTier::TierDevV1).unwrap();
558532
let result = repo.create(org2).await;
559-
assert!(result.is_err());
533+
// Duplicate names are now allowed
534+
assert!(result.is_ok());
535+
536+
// Verify both organizations exist
537+
assert!(repo.get(100).await.unwrap().is_some());
538+
assert!(repo.get(101).await.unwrap().is_some());
560539
}
561540

562541
#[tokio::test]

0 commit comments

Comments
 (0)