Files
member-console/internal/entitlements/queries/pool_provision_transitions.sql
T
cgalo5758 1a19ebe971 Implement uniform conferral semantics
Replace product-kind branching and direct position writes with enclosed
database functions driven by structural product shape.

Migrate grant and provision data, unify operator issuance, update
subscription and expiry flows, and add migration and integration proofs.
2026-07-11 13:05:53 -05:00

34 lines
1.1 KiB
SQL

-- Writes to core.pool_provision_transitions go through the conferral functions
-- (queries/conferral.sql) alone; core_writer holds no direct DML on this
-- table (migration 00005 enclosure). Only read paths live here.
-- name: ListTransitionsByPool :many
SELECT * FROM core.pool_provision_transitions
WHERE pool_id = $1
ORDER BY effective_at DESC, created_at DESC;
-- name: ListTransitionsByProvision :many
SELECT * FROM core.pool_provision_transitions
WHERE provision_id = $1
ORDER BY effective_at ASC, created_at ASC;
-- name: ListRecentTransitions :many
-- Recent transitions for the operator landing activity timeline. Joins to
-- core.resource_pools to resolve the org_id (same schema, safe for
-- sqlc). Operator-actor transitions carry actor_id; system/webhook actors
-- don't, so person_id is nullable in the result.
SELECT
t.transition_id,
t.pool_id,
rp.org_id,
t.transition_type,
t.actor_type,
t.actor_id,
t.from_rank,
t.to_rank,
t.effective_at
FROM core.pool_provision_transitions t
JOIN core.resource_pools rp ON rp.pool_id = t.pool_id
ORDER BY t.effective_at DESC
LIMIT $1;