Add default_plan_ladder_id with a forward data migration and update the runtime to resolve the ladder's rank-0 tier at use-time. Regenerate sqlc, update auto-provisioning, ReapplyDefaultsForPool, operator UI and tests; add GetTierByLadderRank and pool/provision query helpers. Add a CSP-safe confirm-action modal and wire operator actions to it. Close plan-sole-writer safety gaps and serialize IssueGrant with a FOR UPDATE pool lock to prevent ladder races.
40 lines
1.3 KiB
SQL
40 lines
1.3 KiB
SQL
-- name: CreatePoolProvision :one
|
|
INSERT INTO entitlements.pool_provisions (pool_id, grant_id, entitlement_set_id, quantity)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING *;
|
|
|
|
-- name: UpdatePoolProvisionStatus :one
|
|
UPDATE entitlements.pool_provisions
|
|
SET status = @status::VARCHAR(20),
|
|
ended_at = CASE WHEN @status::VARCHAR(20) = 'ended' THEN NOW() ELSE ended_at END,
|
|
suspended_at = CASE WHEN @status::VARCHAR(20) = 'suspended' THEN NOW() ELSE suspended_at END
|
|
WHERE provision_id = @provision_id
|
|
RETURNING *;
|
|
|
|
-- name: GetPoolProvisionsByPoolID :many
|
|
SELECT * FROM entitlements.pool_provisions
|
|
WHERE pool_id = $1
|
|
ORDER BY created_at ASC;
|
|
|
|
-- name: GetActivePoolProvisionsByPoolID :many
|
|
SELECT * FROM entitlements.pool_provisions
|
|
WHERE pool_id = $1 AND status = 'active'
|
|
ORDER BY created_at ASC;
|
|
|
|
-- name: GetPoolProvisionByGrantID :one
|
|
SELECT * FROM entitlements.pool_provisions
|
|
WHERE grant_id = $1;
|
|
|
|
-- name: CreateSubscriptionPoolProvision :one
|
|
INSERT INTO entitlements.pool_provisions (pool_id, subscription_id, billing_account_id, entitlement_set_id, quantity)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING *;
|
|
|
|
-- name: GetPoolProvisionByProvisionID :one
|
|
SELECT * FROM entitlements.pool_provisions
|
|
WHERE provision_id = $1;
|
|
|
|
-- name: GetPoolProvisionBySubscriptionID :one
|
|
SELECT * FROM entitlements.pool_provisions
|
|
WHERE subscription_id = $1;
|