// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: pool_provision_ladders.sql package entitlements import ( "context" "database/sql" "github.com/google/uuid" ) const anyActiveLadderAttachment = `-- name: AnyActiveLadderAttachment :one SELECT EXISTS(SELECT 1 FROM core.pool_provision_ladders WHERE status = 'active') ` // Empty-validation-domain probe: the topology health strip claims health // only when at least one active attachment existed for the checks to cover. func (q *Queries) AnyActiveLadderAttachment(ctx context.Context) (bool, error) { row := q.db.QueryRowContext(ctx, anyActiveLadderAttachment) var exists bool err := row.Scan(&exists) return exists, err } const countActiveAttachmentsByLadder = `-- name: CountActiveAttachmentsByLadder :one SELECT COUNT(*) FROM core.pool_provision_ladders WHERE plan_ladder_id = $1 AND status = 'active' ` func (q *Queries) CountActiveAttachmentsByLadder(ctx context.Context, planLadderID string) (int64, error) { row := q.db.QueryRowContext(ctx, countActiveAttachmentsByLadder, planLadderID) var count int64 err := row.Scan(&count) return count, err } const countActiveAttachmentsByTier = `-- name: CountActiveAttachmentsByTier :one SELECT COUNT(*) FROM core.pool_provision_ladders WHERE plan_ladder_id = $1 AND product_id = $2 AND status = 'active' ` type CountActiveAttachmentsByTierParams struct { PlanLadderID string `json:"plan_ladder_id"` ProductID string `json:"product_id"` } func (q *Queries) CountActiveAttachmentsByTier(ctx context.Context, arg CountActiveAttachmentsByTierParams) (int64, error) { row := q.db.QueryRowContext(ctx, countActiveAttachmentsByTier, arg.PlanLadderID, arg.ProductID) var count int64 err := row.Scan(&count) return count, err } const getActiveAttachmentsByPool = `-- name: GetActiveAttachmentsByPool :many SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id, provision_ladder_id FROM core.pool_provision_ladders WHERE pool_id = $1 AND status = 'active' ORDER BY activated_at DESC ` func (q *Queries) GetActiveAttachmentsByPool(ctx context.Context, poolID string) ([]PoolProvisionLadder, error) { rows, err := q.db.QueryContext(ctx, getActiveAttachmentsByPool, poolID) if err != nil { return nil, err } defer rows.Close() items := []PoolProvisionLadder{} for rows.Next() { var i PoolProvisionLadder if err := rows.Scan( &i.ProvisionID, &i.PlanLadderID, &i.PoolID, &i.Status, &i.ActivatedAt, &i.EndedAt, &i.CreatedAt, &i.UpdatedAt, &i.ProductID, &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 getActiveLadderAttachmentByPoolLadder = `-- name: GetActiveLadderAttachmentByPoolLadder :one SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id, provision_ladder_id FROM core.pool_provision_ladders WHERE pool_id = $1 AND plan_ladder_id = $2 AND status = 'active' LIMIT 1 ` type GetActiveLadderAttachmentByPoolLadderParams struct { PoolID string `json:"pool_id"` PlanLadderID string `json:"plan_ladder_id"` } // Writes to core.pool_provision_ladders 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) GetActiveLadderAttachmentByPoolLadder(ctx context.Context, arg GetActiveLadderAttachmentByPoolLadderParams) (PoolProvisionLadder, error) { row := q.db.QueryRowContext(ctx, getActiveLadderAttachmentByPoolLadder, arg.PoolID, arg.PlanLadderID) var i PoolProvisionLadder err := row.Scan( &i.ProvisionID, &i.PlanLadderID, &i.PoolID, &i.Status, &i.ActivatedAt, &i.EndedAt, &i.CreatedAt, &i.UpdatedAt, &i.ProductID, &i.ProvisionLadderID, ) return i, err } const getLadderAttachmentsByPool = `-- name: GetLadderAttachmentsByPool :many SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id, provision_ladder_id FROM core.pool_provision_ladders WHERE pool_id = $1 ORDER BY activated_at DESC ` func (q *Queries) GetLadderAttachmentsByPool(ctx context.Context, poolID string) ([]PoolProvisionLadder, error) { rows, err := q.db.QueryContext(ctx, getLadderAttachmentsByPool, poolID) if err != nil { return nil, err } defer rows.Close() items := []PoolProvisionLadder{} for rows.Next() { var i PoolProvisionLadder if err := rows.Scan( &i.ProvisionID, &i.PlanLadderID, &i.PoolID, &i.Status, &i.ActivatedAt, &i.EndedAt, &i.CreatedAt, &i.UpdatedAt, &i.ProductID, &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 getLadderAttachmentsByProvision = `-- name: GetLadderAttachmentsByProvision :many SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id, provision_ladder_id FROM core.pool_provision_ladders WHERE provision_id = $1 ORDER BY activated_at ASC ` func (q *Queries) GetLadderAttachmentsByProvision(ctx context.Context, provisionID string) ([]PoolProvisionLadder, error) { rows, err := q.db.QueryContext(ctx, getLadderAttachmentsByProvision, provisionID) if err != nil { return nil, err } defer rows.Close() items := []PoolProvisionLadder{} for rows.Next() { var i PoolProvisionLadder if err := rows.Scan( &i.ProvisionID, &i.PlanLadderID, &i.PoolID, &i.Status, &i.ActivatedAt, &i.EndedAt, &i.CreatedAt, &i.UpdatedAt, &i.ProductID, &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 getLivePlanAttachmentsWithSourceByPool = `-- name: GetLivePlanAttachmentsWithSourceByPool :many SELECT l.provision_ladder_id, l.plan_ladder_id, l.provision_id, l.status AS attachment_status, p.product_id, p.grant_id, p.subscription_id, p.purchase_id, g.grant_reason FROM core.pool_provision_ladders l JOIN core.pool_provisions p ON p.provision_id = l.provision_id LEFT JOIN core.grants g ON g.grant_id = p.grant_id WHERE l.pool_id = $1 AND l.status IN ('active', 'suspended') ORDER BY l.activated_at DESC ` type GetLivePlanAttachmentsWithSourceByPoolRow struct { ProvisionLadderID string `json:"provision_ladder_id"` PlanLadderID string `json:"plan_ladder_id"` ProvisionID string `json:"provision_id"` AttachmentStatus string `json:"attachment_status"` ProductID string `json:"product_id"` GrantID uuid.NullUUID `json:"grant_id"` SubscriptionID uuid.NullUUID `json:"subscription_id"` PurchaseID uuid.NullUUID `json:"purchase_id"` GrantReason sql.NullString `json:"grant_reason"` } // Live (active|suspended) plan-ladder attachments for a pool together with // their source provenance, for the org-type default-change classification: // a grant-sourced row with grant_reason = 'default' marks the pool as holding // the outgoing default (bucket 2); any other live row is another source's // plan (bucket 3); no rows at all is a plan-less pool (bucket 1). func (q *Queries) GetLivePlanAttachmentsWithSourceByPool(ctx context.Context, poolID string) ([]GetLivePlanAttachmentsWithSourceByPoolRow, error) { rows, err := q.db.QueryContext(ctx, getLivePlanAttachmentsWithSourceByPool, poolID) if err != nil { return nil, err } defer rows.Close() items := []GetLivePlanAttachmentsWithSourceByPoolRow{} for rows.Next() { var i GetLivePlanAttachmentsWithSourceByPoolRow if err := rows.Scan( &i.ProvisionLadderID, &i.PlanLadderID, &i.ProvisionID, &i.AttachmentStatus, &i.ProductID, &i.GrantID, &i.SubscriptionID, &i.PurchaseID, &i.GrantReason, ); 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 listLivePlanPositionsByOrgType = `-- name: ListLivePlanPositionsByOrgType :many SELECT o.org_id, o.name, rp.pool_id, l.provision_ladder_id, l.plan_ladder_id, l.provision_id, l.status AS attachment_status, p.product_id, p.grant_id, p.subscription_id, p.purchase_id, g.grant_reason FROM core.organizations o LEFT JOIN core.resource_pools rp ON rp.org_id = o.org_id AND rp.pool_type = 'default' AND rp.status = 'active' LEFT JOIN core.pool_provision_ladders l ON l.pool_id = rp.pool_id AND l.status IN ('active', 'suspended') LEFT JOIN core.pool_provisions p ON p.provision_id = l.provision_id LEFT JOIN core.grants g ON g.grant_id = p.grant_id WHERE o.org_type = $1 ORDER BY o.name, o.org_id ` type ListLivePlanPositionsByOrgTypeRow struct { OrgID string `json:"org_id"` Name string `json:"name"` PoolID uuid.NullUUID `json:"pool_id"` ProvisionLadderID uuid.NullUUID `json:"provision_ladder_id"` PlanLadderID uuid.NullUUID `json:"plan_ladder_id"` ProvisionID uuid.NullUUID `json:"provision_id"` AttachmentStatus sql.NullString `json:"attachment_status"` ProductID uuid.NullUUID `json:"product_id"` GrantID uuid.NullUUID `json:"grant_id"` SubscriptionID uuid.NullUUID `json:"subscription_id"` PurchaseID uuid.NullUUID `json:"purchase_id"` GrantReason sql.NullString `json:"grant_reason"` } // The whole population for the org-type default-change classification in one // round trip: one row per (org, live plan attachment), plus a row with NULL // pool for orgs lacking a default pool and a row with NULL attachment for // plan-less pools (LEFT JOINs). Replaces a per-org query pair, which does not // scale past a few hundred organizations of one type. func (q *Queries) ListLivePlanPositionsByOrgType(ctx context.Context, orgType string) ([]ListLivePlanPositionsByOrgTypeRow, error) { rows, err := q.db.QueryContext(ctx, listLivePlanPositionsByOrgType, orgType) if err != nil { return nil, err } defer rows.Close() items := []ListLivePlanPositionsByOrgTypeRow{} for rows.Next() { var i ListLivePlanPositionsByOrgTypeRow if err := rows.Scan( &i.OrgID, &i.Name, &i.PoolID, &i.ProvisionLadderID, &i.PlanLadderID, &i.ProvisionID, &i.AttachmentStatus, &i.ProductID, &i.GrantID, &i.SubscriptionID, &i.PurchaseID, &i.GrantReason, ); 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 listLiveTierHoldersByLadderProduct = `-- name: ListLiveTierHoldersByLadderProduct :many SELECT l.provision_ladder_id, l.provision_id, l.status AS attachment_status, p.product_id, p.grant_id, p.subscription_id, p.purchase_id, g.grant_reason, rp.pool_id, o.org_id, o.name FROM core.pool_provision_ladders l JOIN core.pool_provisions p ON p.provision_id = l.provision_id JOIN core.resource_pools rp ON rp.pool_id = l.pool_id JOIN core.organizations o ON o.org_id = rp.org_id LEFT JOIN core.grants g ON g.grant_id = p.grant_id WHERE l.plan_ladder_id = $1 AND p.product_id = $2 AND l.status IN ('active', 'suspended') ORDER BY o.name, o.org_id ` type ListLiveTierHoldersByLadderProductParams struct { PlanLadderID string `json:"plan_ladder_id"` ProductID string `json:"product_id"` } type ListLiveTierHoldersByLadderProductRow struct { ProvisionLadderID string `json:"provision_ladder_id"` ProvisionID string `json:"provision_id"` AttachmentStatus string `json:"attachment_status"` ProductID string `json:"product_id"` GrantID uuid.NullUUID `json:"grant_id"` SubscriptionID uuid.NullUUID `json:"subscription_id"` PurchaseID uuid.NullUUID `json:"purchase_id"` GrantReason sql.NullString `json:"grant_reason"` PoolID string `json:"pool_id"` OrgID string `json:"org_id"` Name string `json:"name"` } // The tier-removal preview/commit population in one round trip: every live // (active|suspended) junction on this ladder whose provision delivers this // product, with the org name and grant provenance so holders classify // per position source (default-sourced needs a disposition; any other source // is align-shrunk and never force-ended). func (q *Queries) ListLiveTierHoldersByLadderProduct(ctx context.Context, arg ListLiveTierHoldersByLadderProductParams) ([]ListLiveTierHoldersByLadderProductRow, error) { rows, err := q.db.QueryContext(ctx, listLiveTierHoldersByLadderProduct, arg.PlanLadderID, arg.ProductID) if err != nil { return nil, err } defer rows.Close() items := []ListLiveTierHoldersByLadderProductRow{} for rows.Next() { var i ListLiveTierHoldersByLadderProductRow if err := rows.Scan( &i.ProvisionLadderID, &i.ProvisionID, &i.AttachmentStatus, &i.ProductID, &i.GrantID, &i.SubscriptionID, &i.PurchaseID, &i.GrantReason, &i.PoolID, &i.OrgID, &i.Name, ); 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 }