Add an append-only ledger of entitlement set rule changes with per-pool effect rows, a preview-and-commit rule change flow, and an automatic drain that settles deferred recomputations. Rules gain a tier reduction policy, resource keys declare over-limit behavior, and the materializer now lowers limits when a rule stops applying. Add entitlement set rule change ledger and preview flow Add an append-only ledger of entitlement set rule changes with a preview-and-commit operator flow. Rule writes now go through an enclosed `core.commit_rule_change` function that files an act row and one obligation per carrying pool, with a drain workflow settling deferred recomputations. The preview dry-runs the materializer with a rule overlay and renders per-pool buckets, reduction-policy disclosures, and provider over-limit consequences. Materializing transactions take a shared advisory rendezvous that rule changes hold exclusively, enforced by a possession assertion. Add History and Entitlement changes surfaces, a rule-less warning on five product-selection surfaces, and a `tier_reduction_policy` column that gates FedWiki parking.
30 lines
1.1 KiB
SQL
30 lines
1.1 KiB
SQL
-- name: CreateNumericEntitlement :one
|
|
INSERT INTO core.numeric_entitlements (pool_id, resource_key, entitlement_type, resource_limit)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING *;
|
|
|
|
-- name: GetNumericEntitlementByPoolAndResource :one
|
|
SELECT * FROM core.numeric_entitlements
|
|
WHERE pool_id = $1 AND resource_key = $2;
|
|
|
|
-- name: UpdateNumericEntitlementLimit :one
|
|
UPDATE core.numeric_entitlements
|
|
SET resource_limit = $2
|
|
WHERE entitlement_id = $1
|
|
RETURNING *;
|
|
|
|
-- name: ListNumericEntitlementsByPoolID :many
|
|
SELECT * FROM core.numeric_entitlements
|
|
WHERE pool_id = $1
|
|
ORDER BY resource_key ASC;
|
|
|
|
-- name: ListNumericEntitlementStateForPools :many
|
|
-- Read-only per-pool numeric state for a batch of pools, each row carrying the
|
|
-- usage the limit is read against. The preview folds these without locking.
|
|
SELECT ne.pool_id, ne.resource_key, ne.resource_limit,
|
|
COALESCE(u.current_usage, 0)::BIGINT AS current_usage
|
|
FROM core.numeric_entitlements ne
|
|
LEFT JOIN core.numeric_entitlement_usage u ON u.entitlement_id = ne.entitlement_id
|
|
WHERE ne.pool_id = ANY(sqlc.arg(pool_ids)::uuid[])
|
|
ORDER BY ne.pool_id ASC, ne.resource_key ASC;
|