Files
member-console/internal/entitlements/queries/entitlement_sets.sql
T
cgalo5758 dd3962990b Adopt entity keys and add invoice numbers
Replace the entity slugs on organizations, workspaces, resource pools,
and
plan ladders with nullable `key` columns and add keys to products,
prices,
and entitlement sets. Rename `providers.slug` to `provider` and add
partial
unique indexes for system and org role names.

Assign invoice numbers per billing account from a gapless transactional
counter; Stripe's number moves to the invoice mapping as an external
reference.

Seeds, fixtures, and the operator lookup address rows by key, and the
returning-login resync no longer blanks a display name when the IdP
sends
no `name` claim.
2026-08-29 20:12:04 -05:00

37 lines
1.2 KiB
SQL

-- name: GetEntitlementSetByID :one
SELECT * FROM core.entitlement_sets
WHERE set_id = $1;
-- name: ListEntitlementSets :many
SELECT * FROM core.entitlement_sets
ORDER BY name ASC;
-- name: ListActiveEntitlementSets :many
SELECT * FROM core.entitlement_sets
WHERE is_active = TRUE
ORDER BY name ASC;
-- name: CreateEntitlementSet :one
-- `key` is the optional declarative address (entity-keys §3), root-scoped.
-- The operator create form does not collect one, so a UI-created set leaves
-- it NULL; a seed or a configuration loader supplies it.
INSERT INTO core.entitlement_sets (name, description, is_active, key)
VALUES ($1, $2, $3, sqlc.narg(key))
RETURNING *;
-- name: GetEntitlementSetByKey :one
-- Root key resolver (entity-keys §5). uq_entitlement_sets_key guarantees at
-- most one row matches.
SELECT * FROM core.entitlement_sets
WHERE key = $1;
-- name: UpdateEntitlementSet :one
UPDATE core.entitlement_sets
SET name = $2, description = $3, is_active = $4
WHERE set_id = $1
RETURNING *;
-- name: AnyActiveEntitlementSet :one
-- Setup-checklist existence probe: the whole-table answer, not a lookup.
SELECT EXISTS(SELECT 1 FROM core.entitlement_sets WHERE is_active = TRUE);