Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/platform/database/dbgen/teaching.sql.go |
| Original SHA-256 | 3e9edd481317dc08e3ea1c0376aeb5de9082db992b7adb575fc7b93ea36798ae |
| Git blob SHA | 3a3345991f92b975d747fba679fdc52807681ec6 |
| Reading-copy SHA-256 | 3e9edd481317dc08e3ea1c0376aeb5de9082db992b7adb575fc7b93ea36798ae |
Every recorded occurrence
These 14 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | ws8-teaching-loop | c823f0fb6bb2aba0f39001eb6de96f4000d9321f | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | ws9-bench-ingestion | f585a9ef32fa554663ce1fba9a414a54b6e49cf0 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/platform/database/dbgen/teaching.sql.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓601 lines · 22.5 KB
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: teaching.sql
package dbgen
import (
"context"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shopspring/decimal"
)
const approveProposalTx = `-- name: ApproveProposalTx :one
UPDATE curation_proposals
SET status = 'approved', approver = $2, approved_at = now()
WHERE id = $1
AND status = 'pending'
RETURNING id, kind, from_skill_id, to_skill_id, relation, proposed_strength,
evidence_observations, evidence_successes, model_version, status, approver, approved_at, created_at
`
type ApproveProposalTxParams struct {
ID uuid.UUID `json:"id"`
Approver *uuid.UUID `json:"approver"`
}
// The first of two human steps. Set status to approved and record the approver and approved_at, but ONLY when
// the proposal is still pending, so a double submit or a concurrent approval cannot move an already decided
// proposal. Returns the row only on a real transition; zero rows means it was not pending. Migrator pool.
func (q *Queries) ApproveProposalTx(ctx context.Context, arg ApproveProposalTxParams) (CurationProposal, error) {
row := q.db.QueryRow(ctx, approveProposalTx, arg.ID, arg.Approver)
var i CurationProposal
err := row.Scan(
&i.ID,
&i.Kind,
&i.FromSkillID,
&i.ToSkillID,
&i.Relation,
&i.ProposedStrength,
&i.EvidenceObservations,
&i.EvidenceSuccesses,
&i.ModelVersion,
&i.Status,
&i.Approver,
&i.ApprovedAt,
&i.CreatedAt,
)
return i, err
}
const getActiveProposalForPair = `-- name: GetActiveProposalForPair :one
SELECT id, kind, status, from_skill_id, to_skill_id, relation, proposed_strength
FROM curation_proposals
WHERE from_skill_id = $1
AND to_skill_id = $2
AND relation = $3
AND status IN ('pending', 'approved')
LIMIT 1
`
type GetActiveProposalForPairParams struct {
FromSkillID *uuid.UUID `json:"from_skill_id"`
ToSkillID *uuid.UUID `json:"to_skill_id"`
Relation *string `json:"relation"`
}
type GetActiveProposalForPairRow struct {
ID uuid.UUID `json:"id"`
Kind string `json:"kind"`
Status string `json:"status"`
FromSkillID *uuid.UUID `json:"from_skill_id"`
ToSkillID *uuid.UUID `json:"to_skill_id"`
Relation *string `json:"relation"`
ProposedStrength *decimal.Decimal `json:"proposed_strength"`
}
// Idempotency guard for the proposal generator: returns the existing proposal for a (from_skill_id,
// to_skill_id, relation) triple that is still pending or already approved, so the generator never creates a
// duplicate suggestion for a pair a human is already deciding or has already decided. A rejected proposal is
// intentionally NOT matched here, so a human who rejected a pair can see it proposed again if the evidence
// recurs (the human stays in control either way). Migrator pool, the global table.
func (q *Queries) GetActiveProposalForPair(ctx context.Context, arg GetActiveProposalForPairParams) (GetActiveProposalForPairRow, error) {
row := q.db.QueryRow(ctx, getActiveProposalForPair, arg.FromSkillID, arg.ToSkillID, arg.Relation)
var i GetActiveProposalForPairRow
err := row.Scan(
&i.ID,
&i.Kind,
&i.Status,
&i.FromSkillID,
&i.ToSkillID,
&i.Relation,
&i.ProposedStrength,
)
return i, err
}
const getLatestDpBudgetLedger = `-- name: GetLatestDpBudgetLedger :one
SELECT id, model_version, tenant_id, rdp_orders, accumulated_rdp, epsilon_at_delta, delta,
contributing_tenant_count, released_at
FROM dp_budget_ledger
WHERE model_version = $1
AND coalesce(tenant_id, '00000000-0000-0000-0000-000000000000'::uuid)
= coalesce($2::uuid, '00000000-0000-0000-0000-000000000000'::uuid)
ORDER BY released_at DESC, id DESC
LIMIT 1
`
type GetLatestDpBudgetLedgerParams struct {
ModelVersion string `json:"model_version"`
TenantID *uuid.UUID `json:"tenant_id"`
}
// The hard spend gate read. It returns the most recent ledger row for one (model_version, tenant_id) budget
// key, which carries the running accumulated RDP after every release composed so far. The gate adds the
// candidate release's per order RDP to this accumulation, reconverts to epsilon at the configured delta, and
// refuses the release (writing nothing) if it would exceed the budget. coalesce maps a NULL tenant_id (the
// cross tenant cohort) onto the fixed nil uuid so the cross tenant releases share one budget key space, the
// same convention the aggregates table uses. Ordered released_at then id descending so the newest composed
// accumulation is row one; zero rows means this is the first release on a fresh budget. dp_budget_ledger is a
// global migrator owned table the app role can only SELECT, so this read runs through the migrator pool.
func (q *Queries) GetLatestDpBudgetLedger(ctx context.Context, arg GetLatestDpBudgetLedgerParams) (DpBudgetLedger, error) {
row := q.db.QueryRow(ctx, getLatestDpBudgetLedger, arg.ModelVersion, arg.TenantID)
var i DpBudgetLedger
err := row.Scan(
&i.ID,
&i.ModelVersion,
&i.TenantID,
&i.RdpOrders,
&i.AccumulatedRdp,
&i.EpsilonAtDelta,
&i.Delta,
&i.ContributingTenantCount,
&i.ReleasedAt,
)
return i, err
}
const getProposal = `-- name: GetProposal :one
SELECT id, kind, from_skill_id, to_skill_id, relation, proposed_strength,
evidence_observations, evidence_successes, model_version, status, approver, approved_at, created_at
FROM curation_proposals
WHERE id = $1
`
// Read one proposal by id for the approve and verify handlers. Migrator pool, the global table.
func (q *Queries) GetProposal(ctx context.Context, id uuid.UUID) (CurationProposal, error) {
row := q.db.QueryRow(ctx, getProposal, id)
var i CurationProposal
err := row.Scan(
&i.ID,
&i.Kind,
&i.FromSkillID,
&i.ToSkillID,
&i.Relation,
&i.ProposedStrength,
&i.EvidenceObservations,
&i.EvidenceSuccesses,
&i.ModelVersion,
&i.Status,
&i.Approver,
&i.ApprovedAt,
&i.CreatedAt,
)
return i, err
}
const insertCurationProposal = `-- name: InsertCurationProposal :one
INSERT INTO curation_proposals (
kind, from_skill_id, to_skill_id, relation, proposed_strength,
evidence_observations, evidence_successes, model_version
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, kind, from_skill_id, to_skill_id, relation, proposed_strength,
evidence_observations, evidence_successes, model_version, status, approver, approved_at, created_at
`
type InsertCurationProposalParams struct {
Kind string `json:"kind"`
FromSkillID *uuid.UUID `json:"from_skill_id"`
ToSkillID *uuid.UUID `json:"to_skill_id"`
Relation *string `json:"relation"`
ProposedStrength *decimal.Decimal `json:"proposed_strength"`
EvidenceObservations int32 `json:"evidence_observations"`
EvidenceSuccesses int32 `json:"evidence_successes"`
ModelVersion string `json:"model_version"`
}
// Create a pending curation proposal. Never auto applied and never auto rejected: status defaults to pending,
// approver and approved_at stay NULL until a human acts. Migrator pool only, because curation_proposals is a
// global migrator owned table the app role can only SELECT.
func (q *Queries) InsertCurationProposal(ctx context.Context, arg InsertCurationProposalParams) (CurationProposal, error) {
row := q.db.QueryRow(ctx, insertCurationProposal,
arg.Kind,
arg.FromSkillID,
arg.ToSkillID,
arg.Relation,
arg.ProposedStrength,
arg.EvidenceObservations,
arg.EvidenceSuccesses,
arg.ModelVersion,
)
var i CurationProposal
err := row.Scan(
&i.ID,
&i.Kind,
&i.FromSkillID,
&i.ToSkillID,
&i.Relation,
&i.ProposedStrength,
&i.EvidenceObservations,
&i.EvidenceSuccesses,
&i.ModelVersion,
&i.Status,
&i.Approver,
&i.ApprovedAt,
&i.CreatedAt,
)
return i, err
}
const insertDpBudgetLedger = `-- name: InsertDpBudgetLedger :one
INSERT INTO dp_budget_ledger (
model_version, tenant_id, rdp_orders, accumulated_rdp, epsilon_at_delta, delta,
contributing_tenant_count
) VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, model_version, tenant_id, rdp_orders, accumulated_rdp, epsilon_at_delta, delta,
contributing_tenant_count, released_at
`
type InsertDpBudgetLedgerParams struct {
ModelVersion string `json:"model_version"`
TenantID *uuid.UUID `json:"tenant_id"`
RdpOrders []byte `json:"rdp_orders"`
AccumulatedRdp decimal.Decimal `json:"accumulated_rdp"`
EpsilonAtDelta decimal.Decimal `json:"epsilon_at_delta"`
Delta decimal.Decimal `json:"delta"`
ContributingTenantCount int32 `json:"contributing_tenant_count"`
}
// Record one differential privacy release in the append only budget ledger. The gate inserts this ONLY after
// it has confirmed the release stays within budget, so a persisted row is by construction an in budget,
// already audited release. rdp_orders is the jsonb map of Renyi order to the per order accumulated RDP at
// this release; accumulated_rdp is the running RDP over the worst case (max over the grid converted) used for
// the human readable summary; epsilon_at_delta is the converted epsilon (the min over orders) at the target
// delta; delta is that target; contributing_tenant_count is the number of live non test distinct
// organizations in the cohort, sourced from the production flag, never a literal. The spent epsilon columns
// are numeric so the audit record is bit stable while the grid math ran in float64. dp_budget_ledger is a
// global migrator owned table the app role can only SELECT, so this write runs through the migrator pool.
func (q *Queries) InsertDpBudgetLedger(ctx context.Context, arg InsertDpBudgetLedgerParams) (DpBudgetLedger, error) {
row := q.db.QueryRow(ctx, insertDpBudgetLedger,
arg.ModelVersion,
arg.TenantID,
arg.RdpOrders,
arg.AccumulatedRdp,
arg.EpsilonAtDelta,
arg.Delta,
arg.ContributingTenantCount,
)
var i DpBudgetLedger
err := row.Scan(
&i.ID,
&i.ModelVersion,
&i.TenantID,
&i.RdpOrders,
&i.AccumulatedRdp,
&i.EpsilonAtDelta,
&i.Delta,
&i.ContributingTenantCount,
&i.ReleasedAt,
)
return i, err
}
const listPendingProposals = `-- name: ListPendingProposals :many
SELECT id, kind, from_skill_id, to_skill_id, relation, proposed_strength,
evidence_observations, evidence_successes, model_version, status, approver, approved_at, created_at
FROM curation_proposals
WHERE status = 'pending'
ORDER BY created_at, id
`
// The /compliance surface of proposals awaiting the first human step. Migrator pool, the global table, gated
// behind the compliance or operator role at the handler. Ordered oldest first so the queue is a stable list.
func (q *Queries) ListPendingProposals(ctx context.Context) ([]CurationProposal, error) {
rows, err := q.db.Query(ctx, listPendingProposals)
if err != nil {
return nil, err
}
defer rows.Close()
items := []CurationProposal{}
for rows.Next() {
var i CurationProposal
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.FromSkillID,
&i.ToSkillID,
&i.Relation,
&i.ProposedStrength,
&i.EvidenceObservations,
&i.EvidenceSuccesses,
&i.ModelVersion,
&i.Status,
&i.Approver,
&i.ApprovedAt,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSlateDecisionEvidenceForOrg = `-- name: ListSlateDecisionEvidenceForOrg :many
SELECT
sm.candidate_id,
sm.decision,
sm.clearance_score,
sm.experience_score,
sm.gap_summary,
s.requirement_id,
r.required_level,
ce.matched_skills
FROM slate_members sm
JOIN slates s
ON s.organization_id = sm.organization_id
AND s.id = sm.slate_id
JOIN requirements r
ON r.organization_id = s.organization_id
AND r.id = s.requirement_id
LEFT JOIN candidate_evaluations ce
ON ce.organization_id = sm.organization_id
AND ce.candidate_id = sm.candidate_id
AND ce.requirement_id = s.requirement_id
ORDER BY sm.slate_id, sm.candidate_id
`
type ListSlateDecisionEvidenceForOrgRow struct {
CandidateID uuid.UUID `json:"candidate_id"`
Decision string `json:"decision"`
ClearanceScore decimal.Decimal `json:"clearance_score"`
ExperienceScore decimal.Decimal `json:"experience_score"`
GapSummary []byte `json:"gap_summary"`
RequirementID uuid.UUID `json:"requirement_id"`
RequiredLevel string `json:"required_level"`
MatchedSkills []byte `json:"matched_skills"`
}
// The WS8 in tenant teaching read. It returns ONLY the contents free craft evidence the producer folds
// into scrub.TeachingSignal counts: the reviewer decision on each slate member, the stored sub scores that
// reveal a clearance gap (clearance_score) or an experience shortfall (experience_score), the frozen gap
// summary, and the matched skills evidence (per skill similarity and whether the match was exact or a
// semantic substitution) from the candidate's persisted evaluation. It carries NO name, NO email, NO free
// text resume, only the decision label, the scores, and the jsonb match evidence the engine itself froze.
//
// Both slate_members and candidate_evaluations are RLS scoped, and the producer runs this inside
// RunInTenantTx on the app pool, so the join is scoped to the caller's org by Postgres Row Level Security
// and can never read another tenant's decisions. candidate_evaluations is LEFT joined on the pair
// (organization_id, candidate_id, requirement_id): a slate member that was never screened through
// screenMATCH has no stored evaluation, so the matched skills evidence is then NULL and the producer folds
// only what slate_members alone supports (the clearance and experience patterns), never fabricating a
// skill substitution it cannot see.
func (q *Queries) ListSlateDecisionEvidenceForOrg(ctx context.Context) ([]ListSlateDecisionEvidenceForOrgRow, error) {
rows, err := q.db.Query(ctx, listSlateDecisionEvidenceForOrg)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListSlateDecisionEvidenceForOrgRow{}
for rows.Next() {
var i ListSlateDecisionEvidenceForOrgRow
if err := rows.Scan(
&i.CandidateID,
&i.Decision,
&i.ClearanceScore,
&i.ExperienceScore,
&i.GapSummary,
&i.RequirementID,
&i.RequiredLevel,
&i.MatchedSkills,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listTeachingAggregatesForTenant = `-- name: ListTeachingAggregatesForTenant :many
SELECT id, tenant_id, dp_applied, pattern, band, outcome, model_version, observations, successes,
window_start, window_end, created_at
FROM teaching_signal_aggregates
WHERE tenant_id = $1
AND dp_applied = false
AND model_version = $2
`
type ListTeachingAggregatesForTenantParams struct {
TenantID *uuid.UUID `json:"tenant_id"`
ModelVersion string `json:"model_version"`
}
// The cross cutting GOVERNANCE CONFIDENCE the proposal generator reads: this tenant's own folded craft counts
// for the live in tenant rows (dp_applied false). The generator uses these to confirm a craft pattern is
// reliably approved at a band before it ever proposes a curated edge, so the specific recurring pair (read
// from the tenant's own evaluations) is only proposed when the contents free aggregate also supports it.
// These rows carry NO PII and no candidate id, only the counts. Migrator pool, the global table; the tenant
// is passed explicitly because this read is governance confidence, not the RLS scoped evaluation scan.
func (q *Queries) ListTeachingAggregatesForTenant(ctx context.Context, arg ListTeachingAggregatesForTenantParams) ([]TeachingSignalAggregate, error) {
rows, err := q.db.Query(ctx, listTeachingAggregatesForTenant, arg.TenantID, arg.ModelVersion)
if err != nil {
return nil, err
}
defer rows.Close()
items := []TeachingSignalAggregate{}
for rows.Next() {
var i TeachingSignalAggregate
if err := rows.Scan(
&i.ID,
&i.TenantID,
&i.DpApplied,
&i.Pattern,
&i.Band,
&i.Outcome,
&i.ModelVersion,
&i.Observations,
&i.Successes,
&i.WindowStart,
&i.WindowEnd,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const resolveSkillIDByName = `-- name: ResolveSkillIDByName :one
SELECT id FROM skills WHERE lower(name) = lower(trim($1))
`
// Resolve a skill name to its global skills.id, lower cased and trimmed, so a matched_skills entry that
// carries a candidate or required skill NAME but no id can still be turned into the id the proposal and the
// staged edge need. The skills table is global reference data the app role may SELECT; the proposal generator
// runs this through the same RLS scoped app tx that read the org's evaluations (the read is the only app
// pool step, the proposal WRITE goes through the migrator pool).
func (q *Queries) ResolveSkillIDByName(ctx context.Context, btrim string) (uuid.UUID, error) {
row := q.db.QueryRow(ctx, resolveSkillIDByName, btrim)
var id uuid.UUID
err := row.Scan(&id)
return id, err
}
const stageSubstitutesForEdge = `-- name: StageSubstitutesForEdge :one
INSERT INTO skill_relationships (from_skill_id, to_skill_id, relation, strength, source, verified_at)
VALUES ($1, $2, 'substitutes_for', $3, 'ws8_curation', NULL)
ON CONFLICT (from_skill_id, to_skill_id, relation) DO UPDATE SET source = skill_relationships.source
RETURNING id, from_skill_id, to_skill_id, relation, strength, verified_at
`
type StageSubstitutesForEdgeParams struct {
FromSkillID uuid.UUID `json:"from_skill_id"`
ToSkillID uuid.UUID `json:"to_skill_id"`
Strength decimal.Decimal `json:"strength"`
}
type StageSubstitutesForEdgeRow struct {
ID uuid.UUID `json:"id"`
FromSkillID uuid.UUID `json:"from_skill_id"`
ToSkillID uuid.UUID `json:"to_skill_id"`
Relation string `json:"relation"`
Strength decimal.Decimal `json:"strength"`
VerifiedAt *time.Time `json:"verified_at"`
}
// Insert the staged, INERT skill_relationships edge that an approval creates. verified_at is left NULL, so the
// resolver (which loads only verified_at IS NOT NULL edges) ignores it and no score changes. A SECOND distinct
// human action later sets verified_at to activate it. On a conflicting (from, to, relation) that already
// exists, do nothing and return the existing row, so an approval is idempotent against a manually seeded edge.
// Migrator pool only (skill_relationships is global, the app role has SELECT only).
func (q *Queries) StageSubstitutesForEdge(ctx context.Context, arg StageSubstitutesForEdgeParams) (StageSubstitutesForEdgeRow, error) {
row := q.db.QueryRow(ctx, stageSubstitutesForEdge, arg.FromSkillID, arg.ToSkillID, arg.Strength)
var i StageSubstitutesForEdgeRow
err := row.Scan(
&i.ID,
&i.FromSkillID,
&i.ToSkillID,
&i.Relation,
&i.Strength,
&i.VerifiedAt,
)
return i, err
}
const upsertTeachingSignalAggregate = `-- name: UpsertTeachingSignalAggregate :exec
INSERT INTO teaching_signal_aggregates (
tenant_id, dp_applied, pattern, band, outcome, model_version,
observations, successes, window_start, window_end
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
ON CONFLICT (
coalesce(tenant_id, '00000000-0000-0000-0000-000000000000'::uuid),
pattern, band, outcome, model_version, window_start
) DO UPDATE SET
observations = EXCLUDED.observations,
successes = EXCLUDED.successes,
window_end = EXCLUDED.window_end,
dp_applied = EXCLUDED.dp_applied
`
type UpsertTeachingSignalAggregateParams struct {
TenantID *uuid.UUID `json:"tenant_id"`
DpApplied bool `json:"dp_applied"`
Pattern string `json:"pattern"`
Band string `json:"band"`
Outcome string `json:"outcome"`
ModelVersion string `json:"model_version"`
Observations int32 `json:"observations"`
Successes int32 `json:"successes"`
WindowStart pgtype.Date `json:"window_start"`
WindowEnd pgtype.Date `json:"window_end"`
}
// Persist one folded per tenant craft aggregate into the global teaching_signal_aggregates table. This is
// a GLOBAL migrator owned table (app has SELECT only), so the producer runs this through the migrator pool
// seam, never the app role. The unique key is (coalesce(tenant_id, the nil uuid), pattern, band, outcome,
// model_version, window_start), so a rerun over the same window for the same tenant refreshes the counts in
// place rather than inserting a duplicate, and a forked engine model version lands as a distinct row rather
// than silently overwriting a prior version's aggregate. The live in tenant rows always carry tenant_id set
// and dp_applied false; the flag on cross tenant path writes tenant_id NULL, dp_applied true rows later.
func (q *Queries) UpsertTeachingSignalAggregate(ctx context.Context, arg UpsertTeachingSignalAggregateParams) error {
_, err := q.db.Exec(ctx, upsertTeachingSignalAggregate,
arg.TenantID,
arg.DpApplied,
arg.Pattern,
arg.Band,
arg.Outcome,
arg.ModelVersion,
arg.Observations,
arg.Successes,
arg.WindowStart,
arg.WindowEnd,
)
return err
}
const verifyStagedEdge = `-- name: VerifyStagedEdge :one
UPDATE skill_relationships
SET verified_at = now(), verifier = $2
WHERE id = $1
AND verified_at IS NULL
RETURNING id, from_skill_id, to_skill_id, relation, strength, verified_at, verifier
`
type VerifyStagedEdgeParams struct {
ID uuid.UUID `json:"id"`
Verifier *uuid.UUID `json:"verifier"`
}
type VerifyStagedEdgeRow struct {
ID uuid.UUID `json:"id"`
FromSkillID uuid.UUID `json:"from_skill_id"`
ToSkillID uuid.UUID `json:"to_skill_id"`
Relation string `json:"relation"`
Strength decimal.Decimal `json:"strength"`
VerifiedAt *time.Time `json:"verified_at"`
Verifier *uuid.UUID `json:"verifier"`
}
// The second of two human steps. Activate a staged edge by setting verified_at and recording the verifier,
// ONLY when it is still unverified, so a double submit cannot re activate or change the verifier of an already
// live edge. The resolver reads verified_at IS NOT NULL edges, so this single write is what makes the edge
// live across tenants. The engine math is byte identical: only the resolver reference set grew. Migrator pool.
func (q *Queries) VerifyStagedEdge(ctx context.Context, arg VerifyStagedEdgeParams) (VerifyStagedEdgeRow, error) {
row := q.db.QueryRow(ctx, verifyStagedEdge, arg.ID, arg.Verifier)
var i VerifyStagedEdgeRow
err := row.Scan(
&i.ID,
&i.FromSkillID,
&i.ToSkillID,
&i.Relation,
&i.Strength,
&i.VerifiedAt,
&i.Verifier,
)
return i, err
}