Replace product-kind branching and direct position writes with enclosed database functions driven by structural product shape. Migrate grant and provision data, unify operator issuance, update subscription and expiry flows, and add migration and integration proofs.
171 lines
4.5 KiB
Go
171 lines
4.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: pool_provision_transitions.sql
|
|
|
|
package entitlements
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const listRecentTransitions = `-- name: ListRecentTransitions :many
|
|
SELECT
|
|
t.transition_id,
|
|
t.pool_id,
|
|
rp.org_id,
|
|
t.transition_type,
|
|
t.actor_type,
|
|
t.actor_id,
|
|
t.from_rank,
|
|
t.to_rank,
|
|
t.effective_at
|
|
FROM core.pool_provision_transitions t
|
|
JOIN core.resource_pools rp ON rp.pool_id = t.pool_id
|
|
ORDER BY t.effective_at DESC
|
|
LIMIT $1
|
|
`
|
|
|
|
type ListRecentTransitionsRow struct {
|
|
TransitionID string `json:"transition_id"`
|
|
PoolID string `json:"pool_id"`
|
|
OrgID string `json:"org_id"`
|
|
TransitionType string `json:"transition_type"`
|
|
ActorType string `json:"actor_type"`
|
|
ActorID uuid.NullUUID `json:"actor_id"`
|
|
FromRank sql.NullInt32 `json:"from_rank"`
|
|
ToRank sql.NullInt32 `json:"to_rank"`
|
|
EffectiveAt time.Time `json:"effective_at"`
|
|
}
|
|
|
|
// Recent transitions for the operator landing activity timeline. Joins to
|
|
// core.resource_pools to resolve the org_id (same schema, safe for
|
|
// sqlc). Operator-actor transitions carry actor_id; system/webhook actors
|
|
// don't, so person_id is nullable in the result.
|
|
func (q *Queries) ListRecentTransitions(ctx context.Context, limit int32) ([]ListRecentTransitionsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listRecentTransitions, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListRecentTransitionsRow{}
|
|
for rows.Next() {
|
|
var i ListRecentTransitionsRow
|
|
if err := rows.Scan(
|
|
&i.TransitionID,
|
|
&i.PoolID,
|
|
&i.OrgID,
|
|
&i.TransitionType,
|
|
&i.ActorType,
|
|
&i.ActorID,
|
|
&i.FromRank,
|
|
&i.ToRank,
|
|
&i.EffectiveAt,
|
|
); 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 listTransitionsByPool = `-- name: ListTransitionsByPool :many
|
|
|
|
SELECT transition_id, pool_id, provision_id, plan_ladder_id, from_rank, to_rank, transition_type, actor_type, actor_id, reason, effective_at, created_at, provision_ladder_id FROM core.pool_provision_transitions
|
|
WHERE pool_id = $1
|
|
ORDER BY effective_at DESC, created_at DESC
|
|
`
|
|
|
|
// Writes to core.pool_provision_transitions go through the conferral functions
|
|
// (queries/conferral.sql) alone; core_writer holds no direct DML on this
|
|
// table (migration 00005 enclosure). Only read paths live here.
|
|
func (q *Queries) ListTransitionsByPool(ctx context.Context, poolID string) ([]PoolProvisionTransition, error) {
|
|
rows, err := q.db.QueryContext(ctx, listTransitionsByPool, poolID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []PoolProvisionTransition{}
|
|
for rows.Next() {
|
|
var i PoolProvisionTransition
|
|
if err := rows.Scan(
|
|
&i.TransitionID,
|
|
&i.PoolID,
|
|
&i.ProvisionID,
|
|
&i.PlanLadderID,
|
|
&i.FromRank,
|
|
&i.ToRank,
|
|
&i.TransitionType,
|
|
&i.ActorType,
|
|
&i.ActorID,
|
|
&i.Reason,
|
|
&i.EffectiveAt,
|
|
&i.CreatedAt,
|
|
&i.ProvisionLadderID,
|
|
); 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 listTransitionsByProvision = `-- name: ListTransitionsByProvision :many
|
|
SELECT transition_id, pool_id, provision_id, plan_ladder_id, from_rank, to_rank, transition_type, actor_type, actor_id, reason, effective_at, created_at, provision_ladder_id FROM core.pool_provision_transitions
|
|
WHERE provision_id = $1
|
|
ORDER BY effective_at ASC, created_at ASC
|
|
`
|
|
|
|
func (q *Queries) ListTransitionsByProvision(ctx context.Context, provisionID uuid.NullUUID) ([]PoolProvisionTransition, error) {
|
|
rows, err := q.db.QueryContext(ctx, listTransitionsByProvision, provisionID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []PoolProvisionTransition{}
|
|
for rows.Next() {
|
|
var i PoolProvisionTransition
|
|
if err := rows.Scan(
|
|
&i.TransitionID,
|
|
&i.PoolID,
|
|
&i.ProvisionID,
|
|
&i.PlanLadderID,
|
|
&i.FromRank,
|
|
&i.ToRank,
|
|
&i.TransitionType,
|
|
&i.ActorType,
|
|
&i.ActorID,
|
|
&i.Reason,
|
|
&i.EffectiveAt,
|
|
&i.CreatedAt,
|
|
&i.ProvisionLadderID,
|
|
); 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
|
|
}
|