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.
123 lines
3.2 KiB
Go
123 lines
3.2 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: resource_keys.sql
|
|
|
|
package entitlements
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const getResourceKey = `-- name: GetResourceKey :one
|
|
SELECT resource_key, display_name, description, unit, created_at, provider, kind, over_limit_behavior, over_limit_consequence FROM core.resource_keys
|
|
WHERE resource_key = $1
|
|
`
|
|
|
|
// Single-key lookup for the rule-authoring handler: rule_type is derived
|
|
// server-side from the key's kind, never taken from client input.
|
|
func (q *Queries) GetResourceKey(ctx context.Context, resourceKey string) (ResourceKey, error) {
|
|
row := q.db.QueryRowContext(ctx, getResourceKey, resourceKey)
|
|
var i ResourceKey
|
|
err := row.Scan(
|
|
&i.ResourceKey,
|
|
&i.DisplayName,
|
|
&i.Description,
|
|
&i.Unit,
|
|
&i.CreatedAt,
|
|
&i.Provider,
|
|
&i.Kind,
|
|
&i.OverLimitBehavior,
|
|
&i.OverLimitConsequence,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listResourceKeyLabels = `-- name: ListResourceKeyLabels :many
|
|
SELECT rk.resource_key, rk.display_name, rk.unit,
|
|
COALESCE(p.display_name, '') AS provider_display_name
|
|
FROM core.resource_keys rk
|
|
LEFT JOIN core.providers p ON p.provider = rk.provider
|
|
ORDER BY rk.resource_key ASC
|
|
`
|
|
|
|
type ListResourceKeyLabelsRow struct {
|
|
ResourceKey string `json:"resource_key"`
|
|
DisplayName string `json:"display_name"`
|
|
Unit string `json:"unit"`
|
|
ProviderDisplayName string `json:"provider_display_name"`
|
|
}
|
|
|
|
// Display metadata for entitlement rendering: each key's human-friendly
|
|
// label plus its owning integration's display name. LEFT JOIN because
|
|
// provider NULL = platform-owned/pooled (see the resource_keys DDL
|
|
// comment); such keys render un-attributed.
|
|
func (q *Queries) ListResourceKeyLabels(ctx context.Context) ([]ListResourceKeyLabelsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listResourceKeyLabels)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListResourceKeyLabelsRow{}
|
|
for rows.Next() {
|
|
var i ListResourceKeyLabelsRow
|
|
if err := rows.Scan(
|
|
&i.ResourceKey,
|
|
&i.DisplayName,
|
|
&i.Unit,
|
|
&i.ProviderDisplayName,
|
|
); 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 listResourceKeys = `-- name: ListResourceKeys :many
|
|
SELECT resource_key, display_name, description, unit, created_at, provider, kind, over_limit_behavior, over_limit_consequence FROM core.resource_keys
|
|
ORDER BY resource_key ASC
|
|
`
|
|
|
|
func (q *Queries) ListResourceKeys(ctx context.Context) ([]ResourceKey, error) {
|
|
rows, err := q.db.QueryContext(ctx, listResourceKeys)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ResourceKey{}
|
|
for rows.Next() {
|
|
var i ResourceKey
|
|
if err := rows.Scan(
|
|
&i.ResourceKey,
|
|
&i.DisplayName,
|
|
&i.Description,
|
|
&i.Unit,
|
|
&i.CreatedAt,
|
|
&i.Provider,
|
|
&i.Kind,
|
|
&i.OverLimitBehavior,
|
|
&i.OverLimitConsequence,
|
|
); 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
|
|
}
|