Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Ensure unique username in an organization (#15730)

Hariom Balhara7b249729001d
diff --git a/packages/prisma/migrations/20240711080953_unique_username_in_org/migration.sql b/packages/prisma/migrations/20240711080953_unique_username_in_org/migration.sql
new file mode 100644
index 00000000000..39d5fcb4365
--- /dev/null
+++ b/packages/prisma/migrations/20240711080953_unique_username_in_org/migration.sql
@@ -0,0 +1,8 @@
+/*
+ Warnings:
+
+ - A unique constraint covering the columns `[username,organizationId]` on the table `Profile` will be added. If there are existing duplicate values, this will fail.
+
+*/
+-- CreateIndex
+CREATE UNIQUE INDEX "Profile_username_organizationId_key" ON "Profile"("username", "organizationId");
diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma
index 62c9432f2c1..ae5a0d9cbad 100644
--- a/packages/prisma/schema.prisma
+++ b/packages/prisma/schema.prisma
@@ -349,7 +349,11 @@ model Profile {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
+ // A user can have multiple profiles in different organizations
@@unique([userId, organizationId])
+ // Allow username reuse only across different organizations
+ @@unique([username, organizationId])
+
@@index([uid])
@@index([userId])
@@index([organizationId])