404 lines
13 KiB
Go
404 lines
13 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: assessment_results.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const getAssessmentAttemptResultHistoryEntry = `-- name: GetAssessmentAttemptResultHistoryEntry :one
|
|
SELECT schema_version, result_snapshot::text,
|
|
COALESCE(category_decision::text, '')::text AS category_decision, current_confirmed_grade
|
|
FROM assessment_attempt_results
|
|
WHERE user_id = $1 AND attempt_id = $2
|
|
`
|
|
|
|
type GetAssessmentAttemptResultHistoryEntryParams struct {
|
|
UserID pgtype.UUID
|
|
AttemptID pgtype.UUID
|
|
}
|
|
|
|
type GetAssessmentAttemptResultHistoryEntryRow struct {
|
|
SchemaVersion int16
|
|
ResultSnapshot string
|
|
CategoryDecision string
|
|
CurrentConfirmedGrade pgtype.Text
|
|
}
|
|
|
|
// Returns both immutable result versions. NULL category fields identify a
|
|
// legacy v1 record and must not be reconstructed from current state.
|
|
func (q *Queries) GetAssessmentAttemptResultHistoryEntry(ctx context.Context, arg GetAssessmentAttemptResultHistoryEntryParams) (GetAssessmentAttemptResultHistoryEntryRow, error) {
|
|
row := q.db.QueryRow(ctx, getAssessmentAttemptResultHistoryEntry, arg.UserID, arg.AttemptID)
|
|
var i GetAssessmentAttemptResultHistoryEntryRow
|
|
err := row.Scan(
|
|
&i.SchemaVersion,
|
|
&i.ResultSnapshot,
|
|
&i.CategoryDecision,
|
|
&i.CurrentConfirmedGrade,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCandidateAssessmentCategory = `-- name: GetCandidateAssessmentCategory :one
|
|
SELECT candidate_id, specialization, grade, source_attempt_id, source_review_id,
|
|
product_policy_version_id, product_policy_version, grading_policy_version_id,
|
|
opening_id, opening_manifest_sha256, source, calibration_status, assigned_at
|
|
FROM candidate_assessment_categories
|
|
WHERE candidate_id = $1 AND specialization = $2
|
|
`
|
|
|
|
type GetCandidateAssessmentCategoryParams struct {
|
|
CandidateID pgtype.UUID
|
|
Specialization string
|
|
}
|
|
|
|
func (q *Queries) GetCandidateAssessmentCategory(ctx context.Context, arg GetCandidateAssessmentCategoryParams) (CandidateAssessmentCategory, error) {
|
|
row := q.db.QueryRow(ctx, getCandidateAssessmentCategory, arg.CandidateID, arg.Specialization)
|
|
var i CandidateAssessmentCategory
|
|
err := row.Scan(
|
|
&i.CandidateID,
|
|
&i.Specialization,
|
|
&i.Grade,
|
|
&i.SourceAttemptID,
|
|
&i.SourceReviewID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.Source,
|
|
&i.CalibrationStatus,
|
|
&i.AssignedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getSyntheticCategoryReview = `-- name: GetSyntheticCategoryReview :one
|
|
SELECT review.id, review.opening_id, review.category, review.source,
|
|
review.opening_manifest_sha256, review.product_policy_version_id,
|
|
review.product_policy_version, review.reviewed_by, review.reviewed_at
|
|
FROM assessment_synthetic_category_reviews AS review
|
|
JOIN assessment_category_openings AS opening ON opening.id = review.opening_id
|
|
WHERE review.opening_id = $1
|
|
AND review.category = $2
|
|
AND review.source = 'synthetic_demo'
|
|
AND review.opening_manifest_sha256 = $3
|
|
AND review.product_policy_version_id = $4
|
|
AND review.product_policy_version = $5
|
|
AND opening.policy_version_id = $6
|
|
`
|
|
|
|
type GetSyntheticCategoryReviewParams struct {
|
|
OpeningID pgtype.UUID
|
|
Category string
|
|
OpeningManifestSha256 []byte
|
|
ProductPolicyVersionID pgtype.UUID
|
|
ProductPolicyVersion int32
|
|
GradingPolicyVersionID pgtype.UUID
|
|
}
|
|
|
|
func (q *Queries) GetSyntheticCategoryReview(ctx context.Context, arg GetSyntheticCategoryReviewParams) (AssessmentSyntheticCategoryReview, error) {
|
|
row := q.db.QueryRow(ctx, getSyntheticCategoryReview,
|
|
arg.OpeningID,
|
|
arg.Category,
|
|
arg.OpeningManifestSha256,
|
|
arg.ProductPolicyVersionID,
|
|
arg.ProductPolicyVersion,
|
|
arg.GradingPolicyVersionID,
|
|
)
|
|
var i AssessmentSyntheticCategoryReview
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OpeningID,
|
|
&i.Category,
|
|
&i.Source,
|
|
&i.OpeningManifestSha256,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.ReviewedBy,
|
|
&i.ReviewedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertAssessmentAttemptResultV2 = `-- name: InsertAssessmentAttemptResultV2 :exec
|
|
INSERT INTO assessment_attempt_results (
|
|
attempt_id, user_id, result_snapshot, schema_version, category_decision,
|
|
current_confirmed_grade, kind, mode, outcome, product_policy_version_id,
|
|
product_policy_version, grading_policy_version_id, opening_id,
|
|
opening_manifest_sha256, training_binding_id, training_manifest_sha256,
|
|
bank_version, algorithm_version, rationale_rule, pass_mark_basis_points,
|
|
scored_items, raw_score, pass_points, decided_at
|
|
) VALUES (
|
|
$1, $2, $3, 2,
|
|
$4::jsonb, $5,
|
|
$6, $7, $8, $9,
|
|
$10, $11, $12,
|
|
$13, NULL, NULL, $14,
|
|
$15, $16, $17,
|
|
$18, $19, $20, $21
|
|
)
|
|
`
|
|
|
|
type InsertAssessmentAttemptResultV2Params struct {
|
|
AttemptID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
ResultSnapshot []byte
|
|
CategoryDecision []byte
|
|
CurrentConfirmedGrade pgtype.Text
|
|
Kind string
|
|
Mode string
|
|
Outcome string
|
|
ProductPolicyVersionID pgtype.UUID
|
|
ProductPolicyVersion int32
|
|
GradingPolicyVersionID pgtype.UUID
|
|
OpeningID pgtype.UUID
|
|
OpeningManifestSha256 []byte
|
|
BankVersion string
|
|
AlgorithmVersion string
|
|
RationaleRule string
|
|
PassMarkBasisPoints pgtype.Int4
|
|
ScoredItems pgtype.Int2
|
|
RawScore pgtype.Int2
|
|
PassPoints pgtype.Int2
|
|
DecidedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Stores the category decision and current grade captured at real-attempt
|
|
// finalization. The base result document remains its original v1 shape.
|
|
func (q *Queries) InsertAssessmentAttemptResultV2(ctx context.Context, arg InsertAssessmentAttemptResultV2Params) error {
|
|
_, err := q.db.Exec(ctx, insertAssessmentAttemptResultV2,
|
|
arg.AttemptID,
|
|
arg.UserID,
|
|
arg.ResultSnapshot,
|
|
arg.CategoryDecision,
|
|
arg.CurrentConfirmedGrade,
|
|
arg.Kind,
|
|
arg.Mode,
|
|
arg.Outcome,
|
|
arg.ProductPolicyVersionID,
|
|
arg.ProductPolicyVersion,
|
|
arg.GradingPolicyVersionID,
|
|
arg.OpeningID,
|
|
arg.OpeningManifestSha256,
|
|
arg.BankVersion,
|
|
arg.AlgorithmVersion,
|
|
arg.RationaleRule,
|
|
arg.PassMarkBasisPoints,
|
|
arg.ScoredItems,
|
|
arg.RawScore,
|
|
arg.PassPoints,
|
|
arg.DecidedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertSyntheticCategoryReview = `-- name: InsertSyntheticCategoryReview :execrows
|
|
INSERT INTO assessment_synthetic_category_reviews (
|
|
id, opening_id, category, source, opening_manifest_sha256,
|
|
product_policy_version_id, product_policy_version, reviewed_by, reviewed_at
|
|
) VALUES (
|
|
$1, $2, $3, $4,
|
|
$5, $6,
|
|
$7, $8, $9
|
|
)
|
|
ON CONFLICT ON CONSTRAINT assessment_synthetic_category_reviews_exact_source_key DO NOTHING
|
|
`
|
|
|
|
type InsertSyntheticCategoryReviewParams struct {
|
|
ID pgtype.UUID
|
|
OpeningID pgtype.UUID
|
|
Category string
|
|
Source string
|
|
OpeningManifestSha256 []byte
|
|
ProductPolicyVersionID pgtype.UUID
|
|
ProductPolicyVersion int32
|
|
ReviewedBy string
|
|
ReviewedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// The application accepts only a validated immutable review snapshot. The
|
|
// trigger independently checks the source opening, manifest and policy. A
|
|
// concurrent or repeated attestation of the same exact source inserts nothing,
|
|
// and the caller reads the stored one.
|
|
func (q *Queries) InsertSyntheticCategoryReview(ctx context.Context, arg InsertSyntheticCategoryReviewParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, insertSyntheticCategoryReview,
|
|
arg.ID,
|
|
arg.OpeningID,
|
|
arg.Category,
|
|
arg.Source,
|
|
arg.OpeningManifestSha256,
|
|
arg.ProductPolicyVersionID,
|
|
arg.ProductPolicyVersion,
|
|
arg.ReviewedBy,
|
|
arg.ReviewedAt,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const listCandidateAssessmentResults = `-- name: ListCandidateAssessmentResults :many
|
|
SELECT attempt_id, user_id, schema_version, result_snapshot::text,
|
|
COALESCE(category_decision::text, '')::text AS category_decision, current_confirmed_grade, decided_at
|
|
FROM assessment_attempt_results
|
|
WHERE user_id = $1
|
|
AND kind IN ('root', 'corrective')
|
|
AND ($2::timestamptz IS NULL OR
|
|
(decided_at, attempt_id) <
|
|
($2::timestamptz, $3::uuid))
|
|
ORDER BY decided_at DESC, attempt_id DESC
|
|
LIMIT $4::integer + 1
|
|
`
|
|
|
|
type ListCandidateAssessmentResultsParams struct {
|
|
UserID pgtype.UUID
|
|
CursorDecidedAt pgtype.Timestamptz
|
|
CursorAttemptID pgtype.UUID
|
|
LimitCount int32
|
|
}
|
|
|
|
type ListCandidateAssessmentResultsRow struct {
|
|
AttemptID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
SchemaVersion int16
|
|
ResultSnapshot string
|
|
CategoryDecision string
|
|
CurrentConfirmedGrade pgtype.Text
|
|
DecidedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// The caller validates and signs an opaque owner-bound cursor. This query
|
|
// applies the keyset to the same stable order and fetches one extra row.
|
|
func (q *Queries) ListCandidateAssessmentResults(ctx context.Context, arg ListCandidateAssessmentResultsParams) ([]ListCandidateAssessmentResultsRow, error) {
|
|
rows, err := q.db.Query(ctx, listCandidateAssessmentResults,
|
|
arg.UserID,
|
|
arg.CursorDecidedAt,
|
|
arg.CursorAttemptID,
|
|
arg.LimitCount,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListCandidateAssessmentResultsRow
|
|
for rows.Next() {
|
|
var i ListCandidateAssessmentResultsRow
|
|
if err := rows.Scan(
|
|
&i.AttemptID,
|
|
&i.UserID,
|
|
&i.SchemaVersion,
|
|
&i.ResultSnapshot,
|
|
&i.CategoryDecision,
|
|
&i.CurrentConfirmedGrade,
|
|
&i.DecidedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const lockCandidateAssessmentCategory = `-- name: LockCandidateAssessmentCategory :exec
|
|
SELECT pg_advisory_xact_lock(hashtextextended(
|
|
'lincodex.assessment.category:candidate:' || $1::text || ':' || $2::text,
|
|
0
|
|
))
|
|
`
|
|
|
|
type LockCandidateAssessmentCategoryParams struct {
|
|
CandidateID string
|
|
Specialization string
|
|
}
|
|
|
|
// Acquired after C3, candidate/specialization scope, and attempt row locks.
|
|
// This independent lock serializes current category upgrades for one scope.
|
|
func (q *Queries) LockCandidateAssessmentCategory(ctx context.Context, arg LockCandidateAssessmentCategoryParams) error {
|
|
_, err := q.db.Exec(ctx, lockCandidateAssessmentCategory, arg.CandidateID, arg.Specialization)
|
|
return err
|
|
}
|
|
|
|
const saveCandidateAssessmentCategory = `-- name: SaveCandidateAssessmentCategory :execrows
|
|
INSERT INTO candidate_assessment_categories (
|
|
candidate_id, specialization, grade, source_attempt_id, source_review_id,
|
|
product_policy_version_id, product_policy_version, grading_policy_version_id,
|
|
opening_id, opening_manifest_sha256, source, calibration_status, assigned_at
|
|
) VALUES (
|
|
$1, $2, $3, $4,
|
|
$5, $6, $7,
|
|
(
|
|
SELECT opening.policy_version_id
|
|
FROM assessment_category_openings AS opening
|
|
WHERE opening.id = $8
|
|
),
|
|
$8, $9,
|
|
$10, $11, $12
|
|
)
|
|
ON CONFLICT (candidate_id, specialization) DO UPDATE SET
|
|
grade = EXCLUDED.grade,
|
|
source_attempt_id = EXCLUDED.source_attempt_id,
|
|
source_review_id = EXCLUDED.source_review_id,
|
|
product_policy_version_id = EXCLUDED.product_policy_version_id,
|
|
product_policy_version = EXCLUDED.product_policy_version,
|
|
grading_policy_version_id = EXCLUDED.grading_policy_version_id,
|
|
opening_id = EXCLUDED.opening_id,
|
|
opening_manifest_sha256 = EXCLUDED.opening_manifest_sha256,
|
|
source = EXCLUDED.source,
|
|
calibration_status = EXCLUDED.calibration_status,
|
|
assigned_at = EXCLUDED.assigned_at
|
|
WHERE CASE candidate_assessment_categories.grade
|
|
WHEN 'intern' THEN 0 WHEN 'junior' THEN 1 WHEN 'middle' THEN 2 WHEN 'senior' THEN 3 ELSE -1 END
|
|
< CASE EXCLUDED.grade
|
|
WHEN 'intern' THEN 0 WHEN 'junior' THEN 1 WHEN 'middle' THEN 2 WHEN 'senior' THEN 3 ELSE -1 END
|
|
`
|
|
|
|
type SaveCandidateAssessmentCategoryParams struct {
|
|
CandidateID pgtype.UUID
|
|
Specialization string
|
|
Grade string
|
|
SourceAttemptID pgtype.UUID
|
|
SourceReviewID pgtype.UUID
|
|
ProductPolicyVersionID pgtype.UUID
|
|
ProductPolicyVersion int32
|
|
OpeningID pgtype.UUID
|
|
OpeningManifestSha256 []byte
|
|
Source string
|
|
CalibrationStatus string
|
|
AssignedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Only strict grade upgrades replace the current row. The trigger enforces
|
|
// the same monotonic rule as a final guard against adapter mistakes. The
|
|
// grading policy is read from the immutable opening, and the guard trigger
|
|
// compares it with the policy captured in the assigned result.
|
|
func (q *Queries) SaveCandidateAssessmentCategory(ctx context.Context, arg SaveCandidateAssessmentCategoryParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, saveCandidateAssessmentCategory,
|
|
arg.CandidateID,
|
|
arg.Specialization,
|
|
arg.Grade,
|
|
arg.SourceAttemptID,
|
|
arg.SourceReviewID,
|
|
arg.ProductPolicyVersionID,
|
|
arg.ProductPolicyVersion,
|
|
arg.OpeningID,
|
|
arg.OpeningManifestSha256,
|
|
arg.Source,
|
|
arg.CalibrationStatus,
|
|
arg.AssignedAt,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|