principal_membership_projection API Postgres table
Queryable membership and role projection for signed principal states.
Declared in packages/api-shared/src/schema/principalStates.ts
Description
The signed principal state header stores a projectionRoot: a canonical hash of the normalized projection members. This table stores the rows behind that root so the server can answer authorization questions without decrypting the private policy payload. On write, the submitted projection is hashed and must match principalStates.projectionRoot; after insertion, the stored rows are compared back to the submitted projection to make retries idempotent and detect conflicts.
A projection row says that, for one exact principal state hash, a direct member principal has a role. It is historical rather than mutable: successor principal states write new rows under a new stateHash, and callers use the current state's hash when they need current membership.
Indexes:
(userId, principalType, principalId, stateHash)supports finding the principal states a user is a member of.(principalType, principalId, stateHash, userId)is unique so a state cannot contain duplicate rows for the same direct member. The role is intentionally not part of the unique key; a replay that changes onlyroleis a projection conflict. It also serves loading the projection rows of a principal state.
Columns
iduuid- primary key
- not null
- default gen_random_uuid()
Surrogate database primary key. Domain identity is the tuple
(principalType, principalId, stateHash, userId).principal_typetext- not null
Managed principal kind whose state owns this projection, currently
organizationorgroup.principal_iduuid- not null
Stable id of the managed principal whose members are being projected.
state_hashtext- not null
Content address of the signed principal state header this projection belongs to. This joins the rows to
principalStatesand scopes membership to a specific historical version.user_iduuid- not null
Stable id of the direct member, always a user. Principals cannot contain other principals, so there is no member-kind column.
identity_bundle_fingerprinttext- not null
Hex SHA-256 identity-link commitment to the member's user id, trust domain, and signing and encapsulation public keys, committed by
projectionRoot. It cannot change for a member who stays across successor states.roletext- not null
Authorization role for that member in this principal state, currently
memberoradmin. Admin membership authorizes signing successor principal states.created_attimestamp- not null
- default now()
Server-side insertion timestamp. It is not part of the signed projection root.
Indexes
principal_membership_projection_member_state_idx(user_id, principal_type, principal_id, state_hash)principal_membership_projection_state_member_idx(principal_type, principal_id, state_hash, user_id)- unique