add unique index to prevent multiple orgs per user

This commit is contained in:
Vikhyath Mondreti
2026-01-08 12:57:19 -08:00
parent b071eb4dea
commit 49da60adaa
4 changed files with 9343 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
DROP INDEX "member_user_id_idx";--> statement-breakpoint
CREATE UNIQUE INDEX "member_user_id_unique" ON "member" USING btree ("user_id");

File diff suppressed because it is too large Load Diff

View File

@@ -946,6 +946,13 @@
"when": 1767737974016,
"tag": "0135_stormy_puff_adder",
"breakpoints": true
},
{
"idx": 136,
"version": "7",
"when": 1767905804764,
"tag": "0136_pretty_jack_flag",
"breakpoints": true
}
]
}

View File

@@ -824,7 +824,7 @@ export const member = pgTable(
createdAt: timestamp('created_at').defaultNow().notNull(),
},
(table) => ({
userIdIdx: index('member_user_id_idx').on(table.userId),
userIdUnique: uniqueIndex('member_user_id_unique').on(table.userId), // Users can only belong to one org
organizationIdIdx: index('member_organization_id_idx').on(table.organizationId),
})
)