Files
member-console/internal/entitlements/boolean_entitlements.sql.go
T
cgalo5758 3727ff31d8 Add entitlement set rule change ledger and preview flow
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.
2026-09-15 03:53:28 -05:00

196 lines
5.7 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: boolean_entitlements.sql
package entitlements
import (
"context"
"github.com/lib/pq"
)
const getBooleanEntitlementByPoolAndResource = `-- name: GetBooleanEntitlementByPoolAndResource :one
SELECT pool_id, resource_key, granted, created_at, updated_at FROM core.boolean_entitlements
WHERE pool_id = $1 AND resource_key = $2
`
type GetBooleanEntitlementByPoolAndResourceParams struct {
PoolID string `json:"pool_id"`
ResourceKey string `json:"resource_key"`
}
func (q *Queries) GetBooleanEntitlementByPoolAndResource(ctx context.Context, arg GetBooleanEntitlementByPoolAndResourceParams) (BooleanEntitlement, error) {
row := q.db.QueryRowContext(ctx, getBooleanEntitlementByPoolAndResource, arg.PoolID, arg.ResourceKey)
var i BooleanEntitlement
err := row.Scan(
&i.PoolID,
&i.ResourceKey,
&i.Granted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const lapseBooleanEntitlement = `-- name: LapseBooleanEntitlement :execrows
UPDATE core.boolean_entitlements
SET granted = FALSE
WHERE pool_id = $1 AND resource_key = $2
`
type LapseBooleanEntitlementParams struct {
PoolID string `json:"pool_id"`
ResourceKey string `json:"resource_key"`
}
// Update-only by design: a lapse never creates a row. Absence of a row means
// the key was never conferred; granted = FALSE means conferred, then lapsed.
func (q *Queries) LapseBooleanEntitlement(ctx context.Context, arg LapseBooleanEntitlementParams) (int64, error) {
result, err := q.db.ExecContext(ctx, lapseBooleanEntitlement, arg.PoolID, arg.ResourceKey)
if err != nil {
return 0, err
}
return result.RowsAffected()
}
const listBooleanEntitlementStateForPools = `-- name: ListBooleanEntitlementStateForPools :many
SELECT be.pool_id, be.resource_key, be.granted
FROM core.boolean_entitlements be
WHERE be.pool_id = ANY($1::uuid[])
ORDER BY be.pool_id ASC, be.resource_key ASC
`
type ListBooleanEntitlementStateForPoolsRow struct {
PoolID string `json:"pool_id"`
ResourceKey string `json:"resource_key"`
Granted bool `json:"granted"`
}
// Read-only per-pool boolean state for a batch of pools, the boolean half of
// what the preview folds.
func (q *Queries) ListBooleanEntitlementStateForPools(ctx context.Context, poolIds []string) ([]ListBooleanEntitlementStateForPoolsRow, error) {
rows, err := q.db.QueryContext(ctx, listBooleanEntitlementStateForPools, pq.Array(poolIds))
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListBooleanEntitlementStateForPoolsRow{}
for rows.Next() {
var i ListBooleanEntitlementStateForPoolsRow
if err := rows.Scan(&i.PoolID, &i.ResourceKey, &i.Granted); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listBooleanEntitlementsByPoolID = `-- name: ListBooleanEntitlementsByPoolID :many
SELECT pool_id, resource_key, granted, created_at, updated_at FROM core.boolean_entitlements
WHERE pool_id = $1
ORDER BY resource_key ASC
`
func (q *Queries) ListBooleanEntitlementsByPoolID(ctx context.Context, poolID string) ([]BooleanEntitlement, error) {
rows, err := q.db.QueryContext(ctx, listBooleanEntitlementsByPoolID, poolID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []BooleanEntitlement{}
for rows.Next() {
var i BooleanEntitlement
if err := rows.Scan(
&i.PoolID,
&i.ResourceKey,
&i.Granted,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listPoolsGrantedBooleanKey = `-- name: ListPoolsGrantedBooleanKey :many
SELECT be.pool_id, rp.org_id, o.name AS org_name
FROM core.boolean_entitlements be
JOIN core.resource_pools rp ON rp.pool_id = be.pool_id
JOIN core.organizations o ON o.org_id = rp.org_id
WHERE be.resource_key = $1 AND be.granted = TRUE
ORDER BY o.name ASC, be.pool_id ASC
`
type ListPoolsGrantedBooleanKeyRow struct {
PoolID string `json:"pool_id"`
OrgID string `json:"org_id"`
OrgName string `json:"org_name"`
}
func (q *Queries) ListPoolsGrantedBooleanKey(ctx context.Context, resourceKey string) ([]ListPoolsGrantedBooleanKeyRow, error) {
rows, err := q.db.QueryContext(ctx, listPoolsGrantedBooleanKey, resourceKey)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListPoolsGrantedBooleanKeyRow{}
for rows.Next() {
var i ListPoolsGrantedBooleanKeyRow
if err := rows.Scan(&i.PoolID, &i.OrgID, &i.OrgName); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const upsertBooleanEntitlementGranted = `-- name: UpsertBooleanEntitlementGranted :one
INSERT INTO core.boolean_entitlements (pool_id, resource_key, granted)
VALUES ($1, $2, TRUE)
ON CONFLICT (pool_id, resource_key) DO UPDATE SET granted = TRUE
RETURNING pool_id, resource_key, granted, created_at, updated_at
`
type UpsertBooleanEntitlementGrantedParams struct {
PoolID string `json:"pool_id"`
ResourceKey string `json:"resource_key"`
}
func (q *Queries) UpsertBooleanEntitlementGranted(ctx context.Context, arg UpsertBooleanEntitlementGrantedParams) (BooleanEntitlement, error) {
row := q.db.QueryRowContext(ctx, upsertBooleanEntitlementGranted, arg.PoolID, arg.ResourceKey)
var i BooleanEntitlement
err := row.Scan(
&i.PoolID,
&i.ResourceKey,
&i.Granted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}