Organization Memberships Table
Component Detail
Data Layer
low complexity
Shared Component
backend
0
Dependencies
1
Dependents
0
Entities
0
Integrations
Description
PostgreSQL table storing the many-to-many relationship between users and organizations. Holds role, primary-membership flag, and join timestamp per membership row. A unique constraint on (user_id, organization_id) prevents duplicates.
organization-memberships-table
Responsibilities
- Store one row per (user, organization) membership pair with role and is_primary fields
- Enforce uniqueness of (user_id, organization_id) pairs at the database level
- Support queries by user (all memberships) and by organization (all members) with efficient indexes
Interfaces
INSERT INTO organization_memberships (user_id, organization_id, role, is_primary, joined_at)
SELECT * FROM organization_memberships WHERE organization_id = $1
SELECT * FROM organization_memberships WHERE user_id = $1
UPDATE organization_memberships SET is_primary = false WHERE user_id = $1 AND organization_id != $2
DELETE FROM organization_memberships WHERE user_id = $1 AND organization_id = $2