Drop redundant schema prefixes from all sqlc-generated Go types. Since each module generates into its own package, the package already provides the namespace — billing.Account is unambiguous without billing.BillingAccount. Changes: - Add rename: blocks to all 6 sqlc.yaml files mapping schema-prefixed names to clean idiomatic names (e.g. BillingBillingAccount → Account, IdentityPerson → Person, OrganizationOrganization → Organization) - Rename billing.billing_accounts → billing.accounts (table name repeated the schema; the schema already provides that context) - Rename integration.integration_outbox → integration.outbox (same reason) - Regenerate all sqlc output across billing, identity, organization, entitlements, stripe, and fedwiki modules - Update all calling code (server, workflows, provisioning, tests) to use the new names - Add internal/db/sqlc_schemas.sql — sqlc-only schema declarations so every module can resolve schema-qualified names without including the full db migrations - Update docs/database-management.md with the naming convention and standard sqlc.yaml template Convention going forward: table names must not repeat the schema name; generated types carry no schema prefix; the Go package provides the namespace (like http.Request, not http.HttpRequest).
163 lines
4.8 KiB
Go
163 lines
4.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: entitlement_set_rules.sql
|
|
|
|
package entitlements
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createEntitlementSetRule = `-- name: CreateEntitlementSetRule :one
|
|
INSERT INTO entitlements.entitlement_set_rules (set_id, rule_type, resource_key, resource_value, resource_per_unit, stacking_policy, reset_period, credit_amount, credit_currency, description)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
RETURNING rule_id, set_id, rule_type, resource_key, resource_value, resource_per_unit, stacking_policy, reset_period, credit_amount, credit_currency, description, is_active, created_at, updated_at
|
|
`
|
|
|
|
type CreateEntitlementSetRuleParams struct {
|
|
SetID string `json:"set_id"`
|
|
RuleType string `json:"rule_type"`
|
|
ResourceKey sql.NullString `json:"resource_key"`
|
|
ResourceValue sql.NullInt64 `json:"resource_value"`
|
|
ResourcePerUnit sql.NullBool `json:"resource_per_unit"`
|
|
StackingPolicy sql.NullString `json:"stacking_policy"`
|
|
ResetPeriod sql.NullString `json:"reset_period"`
|
|
CreditAmount sql.NullInt32 `json:"credit_amount"`
|
|
CreditCurrency sql.NullString `json:"credit_currency"`
|
|
Description sql.NullString `json:"description"`
|
|
}
|
|
|
|
func (q *Queries) CreateEntitlementSetRule(ctx context.Context, arg CreateEntitlementSetRuleParams) (EntitlementSetRule, error) {
|
|
row := q.db.QueryRowContext(ctx, createEntitlementSetRule,
|
|
arg.SetID,
|
|
arg.RuleType,
|
|
arg.ResourceKey,
|
|
arg.ResourceValue,
|
|
arg.ResourcePerUnit,
|
|
arg.StackingPolicy,
|
|
arg.ResetPeriod,
|
|
arg.CreditAmount,
|
|
arg.CreditCurrency,
|
|
arg.Description,
|
|
)
|
|
var i EntitlementSetRule
|
|
err := row.Scan(
|
|
&i.RuleID,
|
|
&i.SetID,
|
|
&i.RuleType,
|
|
&i.ResourceKey,
|
|
&i.ResourceValue,
|
|
&i.ResourcePerUnit,
|
|
&i.StackingPolicy,
|
|
&i.ResetPeriod,
|
|
&i.CreditAmount,
|
|
&i.CreditCurrency,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteEntitlementSetRule = `-- name: DeleteEntitlementSetRule :exec
|
|
DELETE FROM entitlements.entitlement_set_rules
|
|
WHERE rule_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEntitlementSetRule(ctx context.Context, ruleID string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteEntitlementSetRule, ruleID)
|
|
return err
|
|
}
|
|
|
|
const getActiveRulesBySetID = `-- name: GetActiveRulesBySetID :many
|
|
SELECT rule_id, set_id, rule_type, resource_key, resource_value, resource_per_unit, stacking_policy, reset_period, credit_amount, credit_currency, description, is_active, created_at, updated_at FROM entitlements.entitlement_set_rules
|
|
WHERE set_id = $1 AND is_active = TRUE
|
|
ORDER BY resource_key ASC
|
|
`
|
|
|
|
func (q *Queries) GetActiveRulesBySetID(ctx context.Context, setID string) ([]EntitlementSetRule, error) {
|
|
rows, err := q.db.QueryContext(ctx, getActiveRulesBySetID, setID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []EntitlementSetRule{}
|
|
for rows.Next() {
|
|
var i EntitlementSetRule
|
|
if err := rows.Scan(
|
|
&i.RuleID,
|
|
&i.SetID,
|
|
&i.RuleType,
|
|
&i.ResourceKey,
|
|
&i.ResourceValue,
|
|
&i.ResourcePerUnit,
|
|
&i.StackingPolicy,
|
|
&i.ResetPeriod,
|
|
&i.CreditAmount,
|
|
&i.CreditCurrency,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&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 updateEntitlementSetRule = `-- name: UpdateEntitlementSetRule :one
|
|
UPDATE entitlements.entitlement_set_rules
|
|
SET resource_value = $2, resource_per_unit = $3, stacking_policy = $4, description = $5, is_active = $6
|
|
WHERE rule_id = $1
|
|
RETURNING rule_id, set_id, rule_type, resource_key, resource_value, resource_per_unit, stacking_policy, reset_period, credit_amount, credit_currency, description, is_active, created_at, updated_at
|
|
`
|
|
|
|
type UpdateEntitlementSetRuleParams struct {
|
|
RuleID string `json:"rule_id"`
|
|
ResourceValue sql.NullInt64 `json:"resource_value"`
|
|
ResourcePerUnit sql.NullBool `json:"resource_per_unit"`
|
|
StackingPolicy sql.NullString `json:"stacking_policy"`
|
|
Description sql.NullString `json:"description"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) UpdateEntitlementSetRule(ctx context.Context, arg UpdateEntitlementSetRuleParams) (EntitlementSetRule, error) {
|
|
row := q.db.QueryRowContext(ctx, updateEntitlementSetRule,
|
|
arg.RuleID,
|
|
arg.ResourceValue,
|
|
arg.ResourcePerUnit,
|
|
arg.StackingPolicy,
|
|
arg.Description,
|
|
arg.IsActive,
|
|
)
|
|
var i EntitlementSetRule
|
|
err := row.Scan(
|
|
&i.RuleID,
|
|
&i.SetID,
|
|
&i.RuleType,
|
|
&i.ResourceKey,
|
|
&i.ResourceValue,
|
|
&i.ResourcePerUnit,
|
|
&i.StackingPolicy,
|
|
&i.ResetPeriod,
|
|
&i.CreditAmount,
|
|
&i.CreditCurrency,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|