Files
member-console/internal/organization/queries/members.sql
T
cgalo5758 b0072d8971 Consolidate domain tables into core schema
Squash the pre-production migration history into fresh core, fedwiki,
and stripe baselines and reduce the canonical source list to those
three streams.

Update sqlc configs, generated queries, raw SQL, tests, and docs while
keeping provider tables schema-qualified.

BREAKING: existing local database volumes must be wiped because goose
version history restarts from the new baselines.
2026-07-05 20:10:23 -05:00

59 lines
1.8 KiB
SQL

-- name: CreateOrgMember :one
INSERT INTO core.org_members (org_id, person_id, role_id)
VALUES ($1, $2, $3)
RETURNING *;
-- name: GetOrgMemberByPersonAndOrg :one
SELECT * FROM core.org_members
WHERE person_id = $1 AND org_id = $2;
-- name: GetOrgMembersByOrgID :many
SELECT om.*, p.display_name, p.primary_email, r.role_name
FROM core.org_members om
JOIN core.persons p ON p.person_id = om.person_id
JOIN core.roles r ON r.role_id = om.role_id
WHERE om.org_id = $1
ORDER BY p.display_name;
-- name: ListActiveMembersByOrgID :many
-- Operator composite's Members section. Active members only (status='active',
-- excluding removed/historical rows). Defensive LIMIT 200 per design D5;
-- pagination is YAGNI until a real org pushes 50+ members.
SELECT
om.org_member_id,
om.person_id,
om.role_id,
om.joined_at,
p.display_name,
p.primary_email,
r.role_name
FROM core.org_members om
JOIN core.persons p ON p.person_id = om.person_id
JOIN core.roles r ON r.role_id = om.role_id
WHERE om.org_id = $1
AND om.status = 'active'
ORDER BY p.display_name ASC
LIMIT 200;
-- name: ListActiveMembershipsByPersonID :many
-- Person-detail "Org memberships" section. Returns each org the person
-- belongs to (active memberships only) with the org's display fields and
-- the person's role at that org. Sorted by joined_at DESC so the most
-- recent membership appears first — operators usually want "what's the
-- person doing now" rather than "where did they start."
SELECT
om.org_member_id,
om.org_id,
om.role_id,
om.joined_at,
o.name AS org_name,
o.slug AS org_slug,
r.role_name
FROM core.org_members om
JOIN core.organizations o ON o.org_id = om.org_id
JOIN core.roles r ON r.role_id = om.role_id
WHERE om.person_id = $1
AND om.status = 'active'
ORDER BY om.joined_at DESC
LIMIT 200;