The Rules section is one record table grouped by kind, Limit then Boolean, on fixed columns, edited in place: Edit opens a row's controls in their columns, Add rule opens a dense row above the table, and every change is staged into a tray that lists the deltas with Undo and applies them as one rule-change act. The reduction policy is a column of the rule beside its limit. History shows counts only. Group rows are a quiet heading rather than a divider, the maintainer's pick from four rounds of outside-model ideation. Dense rows align to the top and render each error under its control in every form family (design D16), replacing the below-row error block; the forms library gains the batch form (rows plus one tray) and the RowField dense and label-hidden options. Migration 00019 records the governing reduction policy on effect rows. Archive staged-rule-changes with its spec updates (entitlement-set- management, entitlement-set-history, entitlements, form-library, form-conventions, ui-quality-gate). Screens accepted 2026-09-19.
44 lines
2.1 KiB
SQL
44 lines
2.1 KiB
SQL
-- name: GetActiveRulesBySetID :many
|
|
SELECT * FROM core.entitlement_set_rules
|
|
WHERE set_id = $1 AND is_active = TRUE
|
|
ORDER BY resource_key ASC;
|
|
|
|
-- name: ListEntitlementSetRulesBySetIDs :many
|
|
-- Batch reader for the products list's per-page verdict (product-management
|
|
-- "The verdict per page, from batches, never cached", design D4): active
|
|
-- rules across every entitlement set the page's products reference, one
|
|
-- query instead of one per product (mirrors GetActiveRulesBySetID).
|
|
SELECT * FROM core.entitlement_set_rules
|
|
WHERE set_id = ANY(sqlc.arg(set_ids)::uuid[]) AND is_active = TRUE
|
|
ORDER BY set_id ASC, resource_key ASC;
|
|
|
|
-- name: GetEntitlementSetRule :one
|
|
-- One rule in any state, so a preview and a commit can tell a rule that was
|
|
-- deactivated a moment ago from a rule id that is not on this set. Writes go
|
|
-- through core.commit_rule_change alone (migration 00018 revokes the DML).
|
|
SELECT * FROM core.entitlement_set_rules
|
|
WHERE rule_id = $1;
|
|
|
|
-- name: GetGoverningReductionPolicy :one
|
|
-- The reduction policy governing one pool and one resource key: the strongest
|
|
-- among the active limit rules that fund the pool through its active
|
|
-- provisions, in the order force_reduce, clamp, block, defer. The order is
|
|
-- stated here as an explicit CASE and once more as a list in the Go fold
|
|
-- (entitlements, "The reduction policy governing a pool and key is the
|
|
-- strongest across the rules funding it"); neither compares the values as
|
|
-- text, which is what MIN() did until this query was rewritten.
|
|
SELECT CASE
|
|
WHEN BOOL_OR(r.tier_reduction_policy = 'force_reduce') THEN 'force_reduce'
|
|
WHEN BOOL_OR(r.tier_reduction_policy = 'clamp') THEN 'clamp'
|
|
WHEN BOOL_OR(r.tier_reduction_policy = 'block') THEN 'block'
|
|
WHEN BOOL_OR(r.tier_reduction_policy = 'defer') THEN 'defer'
|
|
END::VARCHAR AS tier_reduction_policy
|
|
FROM core.pool_provisions pp
|
|
JOIN core.entitlement_set_rules r ON r.set_id = pp.entitlement_set_id
|
|
WHERE pp.pool_id = sqlc.arg(pool_id)
|
|
AND pp.status = 'active'
|
|
AND r.is_active
|
|
AND r.rule_type = 'limit'
|
|
AND r.resource_key = sqlc.arg(resource_key)
|
|
HAVING COUNT(*) > 0;
|