Files
member-console/internal/entitlements/numeric_entitlement_contributions.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

101 lines
3.1 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: numeric_entitlement_contributions.sql
package entitlements
import (
"context"
)
const createNumericEntitlementContribution = `-- name: CreateNumericEntitlementContribution :one
INSERT INTO core.numeric_entitlement_contributions (entitlement_id, provision_id, contributed_value, stacking_policy)
VALUES ($1, $2, $3, $4)
RETURNING contribution_id, entitlement_id, provision_id, contributed_value, stacking_policy, created_at, updated_at
`
type CreateNumericEntitlementContributionParams struct {
EntitlementID string `json:"entitlement_id"`
ProvisionID string `json:"provision_id"`
ContributedValue int64 `json:"contributed_value"`
StackingPolicy string `json:"stacking_policy"`
}
func (q *Queries) CreateNumericEntitlementContribution(ctx context.Context, arg CreateNumericEntitlementContributionParams) (NumericEntitlementContribution, error) {
row := q.db.QueryRowContext(ctx, createNumericEntitlementContribution,
arg.EntitlementID,
arg.ProvisionID,
arg.ContributedValue,
arg.StackingPolicy,
)
var i NumericEntitlementContribution
err := row.Scan(
&i.ContributionID,
&i.EntitlementID,
&i.ProvisionID,
&i.ContributedValue,
&i.StackingPolicy,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteContributionsByProvisionID = `-- name: DeleteContributionsByProvisionID :exec
DELETE FROM core.numeric_entitlement_contributions
WHERE entitlement_id = $1 AND provision_id = $2
`
type DeleteContributionsByProvisionIDParams struct {
EntitlementID string `json:"entitlement_id"`
ProvisionID string `json:"provision_id"`
}
// Scoped to one entitlement: a provision that funds several resource keys
// keeps its rows on the keys the caller is not rebuilding.
func (q *Queries) DeleteContributionsByProvisionID(ctx context.Context, arg DeleteContributionsByProvisionIDParams) error {
_, err := q.db.ExecContext(ctx, deleteContributionsByProvisionID, arg.EntitlementID, arg.ProvisionID)
return err
}
const listContributionsByEntitlementID = `-- name: ListContributionsByEntitlementID :many
SELECT contribution_id, entitlement_id, provision_id, contributed_value, stacking_policy, created_at, updated_at FROM core.numeric_entitlement_contributions
WHERE entitlement_id = $1
ORDER BY created_at ASC
`
func (q *Queries) ListContributionsByEntitlementID(ctx context.Context, entitlementID string) ([]NumericEntitlementContribution, error) {
rows, err := q.db.QueryContext(ctx, listContributionsByEntitlementID, entitlementID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []NumericEntitlementContribution{}
for rows.Next() {
var i NumericEntitlementContribution
if err := rows.Scan(
&i.ContributionID,
&i.EntitlementID,
&i.ProvisionID,
&i.ContributedValue,
&i.StackingPolicy,
&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
}