1320 lines
37 KiB
Go
1320 lines
37 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: assessment_attempts.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const countRootAssessmentAttemptsSince = `-- name: CountRootAssessmentAttemptsSince :one
|
|
SELECT count(*)::bigint
|
|
FROM assessment_attempts AS attempt
|
|
LEFT JOIN assessment_attempt_results AS result
|
|
ON result.attempt_id = attempt.id AND result.user_id = attempt.user_id
|
|
WHERE attempt.user_id = $1
|
|
AND attempt.kind = 'root'
|
|
AND attempt.created_at >= $2::timestamptz
|
|
AND ($3::text IS NULL OR attempt.specialization = $3::text)
|
|
AND attempt.state <> 'insufficient_bank'
|
|
AND COALESCE(result.result_snapshot->>'not_determined_reason', '')
|
|
NOT IN ('insufficient_bank', 'sandbox_unavailable')
|
|
`
|
|
|
|
type CountRootAssessmentAttemptsSinceParams struct {
|
|
UserID pgtype.UUID
|
|
Since pgtype.Timestamptz
|
|
Specialization pgtype.Text
|
|
}
|
|
|
|
// Counts root attempts only; the caller applies the effective policy's
|
|
// configured window and the product's approved accounting scope.
|
|
func (q *Queries) CountRootAssessmentAttemptsSince(ctx context.Context, arg CountRootAssessmentAttemptsSinceParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countRootAssessmentAttemptsSince, arg.UserID, arg.Since, arg.Specialization)
|
|
var column_1 int64
|
|
err := row.Scan(&column_1)
|
|
return column_1, err
|
|
}
|
|
|
|
const deleteAssessmentAttemptIdempotencyOutcome = `-- name: DeleteAssessmentAttemptIdempotencyOutcome :exec
|
|
DELETE FROM assessment_attempt_idempotency_outcomes
|
|
WHERE scope_hash = $1
|
|
`
|
|
|
|
// A newly reserved generic idempotency window can replace an expired typed
|
|
// outcome before the new immutable response is inserted.
|
|
func (q *Queries) DeleteAssessmentAttemptIdempotencyOutcome(ctx context.Context, scopeHash []byte) error {
|
|
_, err := q.db.Exec(ctx, deleteAssessmentAttemptIdempotencyOutcome, scopeHash)
|
|
return err
|
|
}
|
|
|
|
const getActiveAssessmentAttemptForSpecialization = `-- name: GetActiveAssessmentAttemptForSpecialization :one
|
|
SELECT
|
|
id, user_id, kind, mode, state, outcome, bank_category, specialization,
|
|
target_grade, task_language, root_attempt_id, 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, created_at, updated_at, expires_at,
|
|
chain_deadline, idle_timeout_seconds, max_sessions, sessions_used,
|
|
session_started_at, last_activity_at, version, ended_at
|
|
FROM assessment_attempts
|
|
WHERE user_id = $1
|
|
AND specialization = $2
|
|
AND kind IN ('root', 'corrective')
|
|
AND state IN ('in_progress', 'practice_pending', 'additional_practice_pending', 'ready_to_finalize')
|
|
ORDER BY created_at DESC, id DESC
|
|
LIMIT 1
|
|
FOR UPDATE
|
|
`
|
|
|
|
type GetActiveAssessmentAttemptForSpecializationParams struct {
|
|
UserID pgtype.UUID
|
|
Specialization pgtype.Text
|
|
}
|
|
|
|
// Locks the active real attempt after LockAssessmentAttemptScope.
|
|
func (q *Queries) GetActiveAssessmentAttemptForSpecialization(ctx context.Context, arg GetActiveAssessmentAttemptForSpecializationParams) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, getActiveAssessmentAttemptForSpecialization, arg.UserID, arg.Specialization)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getActiveTrainingAssessmentAttempt = `-- name: GetActiveTrainingAssessmentAttempt :one
|
|
SELECT
|
|
id, user_id, kind, mode, state, outcome, bank_category, specialization,
|
|
target_grade, task_language, root_attempt_id, 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, created_at, updated_at, expires_at,
|
|
chain_deadline, idle_timeout_seconds, max_sessions, sessions_used,
|
|
session_started_at, last_activity_at, version, ended_at
|
|
FROM assessment_attempts
|
|
WHERE user_id = $1
|
|
AND kind = 'demo_express'
|
|
AND state IN ('in_progress', 'practice_pending', 'additional_practice_pending', 'ready_to_finalize')
|
|
ORDER BY created_at DESC, id DESC
|
|
LIMIT 1
|
|
FOR UPDATE
|
|
`
|
|
|
|
// Locks the one active express attempt after LockAssessmentAttemptScope.
|
|
func (q *Queries) GetActiveTrainingAssessmentAttempt(ctx context.Context, userID pgtype.UUID) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, getActiveTrainingAssessmentAttempt, userID)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getAssessmentAttemptForCandidate = `-- name: GetAssessmentAttemptForCandidate :one
|
|
SELECT
|
|
id, user_id, kind, mode, state, outcome, bank_category, specialization,
|
|
target_grade, task_language, root_attempt_id, 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, created_at, updated_at, expires_at,
|
|
chain_deadline, idle_timeout_seconds, max_sessions, sessions_used,
|
|
session_started_at, last_activity_at, version, ended_at
|
|
FROM assessment_attempts
|
|
WHERE id = $1 AND user_id = $2
|
|
FOR SHARE
|
|
`
|
|
|
|
type GetAssessmentAttemptForCandidateParams struct {
|
|
ID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
}
|
|
|
|
// Returns a full private attempt only to its candidate.
|
|
func (q *Queries) GetAssessmentAttemptForCandidate(ctx context.Context, arg GetAssessmentAttemptForCandidateParams) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, getAssessmentAttemptForCandidate, arg.ID, arg.UserID)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getAssessmentAttemptIdempotencyOutcome = `-- name: GetAssessmentAttemptIdempotencyOutcome :one
|
|
SELECT operation, status_code, problem_code,
|
|
CAST(COALESCE(response_snapshot::text, ''::text) AS text) AS response_snapshot,
|
|
pending_item_ids
|
|
FROM assessment_attempt_idempotency_outcomes
|
|
WHERE scope_hash = $1
|
|
`
|
|
|
|
type GetAssessmentAttemptIdempotencyOutcomeRow struct {
|
|
Operation string
|
|
StatusCode int16
|
|
ProblemCode pgtype.Text
|
|
ResponseSnapshot string
|
|
PendingItemIds []pgtype.UUID
|
|
}
|
|
|
|
func (q *Queries) GetAssessmentAttemptIdempotencyOutcome(ctx context.Context, scopeHash []byte) (GetAssessmentAttemptIdempotencyOutcomeRow, error) {
|
|
row := q.db.QueryRow(ctx, getAssessmentAttemptIdempotencyOutcome, scopeHash)
|
|
var i GetAssessmentAttemptIdempotencyOutcomeRow
|
|
err := row.Scan(
|
|
&i.Operation,
|
|
&i.StatusCode,
|
|
&i.ProblemCode,
|
|
&i.ResponseSnapshot,
|
|
&i.PendingItemIds,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getAssessmentAttemptKindForCandidate = `-- name: GetAssessmentAttemptKindForCandidate :one
|
|
SELECT kind
|
|
FROM assessment_attempts
|
|
WHERE id = $1 AND user_id = $2
|
|
`
|
|
|
|
type GetAssessmentAttemptKindForCandidateParams struct {
|
|
ID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
}
|
|
|
|
// Reads the immutable attempt kind without locking the row. Session commands
|
|
// use this only to decide whether C3 applies before acquiring the row lock.
|
|
func (q *Queries) GetAssessmentAttemptKindForCandidate(ctx context.Context, arg GetAssessmentAttemptKindForCandidateParams) (string, error) {
|
|
row := q.db.QueryRow(ctx, getAssessmentAttemptKindForCandidate, arg.ID, arg.UserID)
|
|
var kind string
|
|
err := row.Scan(&kind)
|
|
return kind, err
|
|
}
|
|
|
|
const getAssessmentAttemptResult = `-- name: GetAssessmentAttemptResult :one
|
|
SELECT result_snapshot::text AS result_snapshot
|
|
FROM assessment_attempt_results
|
|
WHERE user_id = $1 AND attempt_id = $2
|
|
`
|
|
|
|
type GetAssessmentAttemptResultParams struct {
|
|
UserID pgtype.UUID
|
|
AttemptID pgtype.UUID
|
|
}
|
|
|
|
// Reads a result only for the owning candidate.
|
|
func (q *Queries) GetAssessmentAttemptResult(ctx context.Context, arg GetAssessmentAttemptResultParams) (string, error) {
|
|
row := q.db.QueryRow(ctx, getAssessmentAttemptResult, arg.UserID, arg.AttemptID)
|
|
var result_snapshot string
|
|
err := row.Scan(&result_snapshot)
|
|
return result_snapshot, err
|
|
}
|
|
|
|
const getLatestRootAssessmentAttempt = `-- name: GetLatestRootAssessmentAttempt :one
|
|
SELECT
|
|
attempt.id, attempt.user_id, attempt.kind, attempt.mode, attempt.state, attempt.outcome,
|
|
attempt.bank_category, attempt.specialization, attempt.target_grade, attempt.task_language,
|
|
attempt.root_attempt_id, attempt.product_policy_version_id, attempt.product_policy_version,
|
|
attempt.grading_policy_version_id, attempt.opening_id, attempt.opening_manifest_sha256,
|
|
attempt.training_binding_id, attempt.training_manifest_sha256, attempt.bank_version,
|
|
attempt.algorithm_version, attempt.created_at, attempt.updated_at, attempt.expires_at,
|
|
attempt.chain_deadline, attempt.idle_timeout_seconds, attempt.max_sessions, attempt.sessions_used,
|
|
attempt.session_started_at, attempt.last_activity_at, attempt.version, attempt.ended_at
|
|
FROM assessment_attempts AS attempt
|
|
LEFT JOIN assessment_attempt_results AS result
|
|
ON result.attempt_id = attempt.id AND result.user_id = attempt.user_id
|
|
WHERE attempt.user_id = $1
|
|
AND attempt.specialization = $2
|
|
AND attempt.kind = 'root'
|
|
AND ($3::text IS NULL OR attempt.target_grade = $3::text)
|
|
AND attempt.state <> 'insufficient_bank'
|
|
AND COALESCE(result.result_snapshot->>'not_determined_reason', '')
|
|
NOT IN ('insufficient_bank', 'sandbox_unavailable')
|
|
ORDER BY attempt.created_at DESC, attempt.id DESC
|
|
LIMIT 1
|
|
FOR SHARE OF attempt
|
|
`
|
|
|
|
type GetLatestRootAssessmentAttemptParams struct {
|
|
UserID pgtype.UUID
|
|
Specialization pgtype.Text
|
|
TargetGrade pgtype.Text
|
|
}
|
|
|
|
// Reads the latest root in a specialization, optionally restricted to grade.
|
|
func (q *Queries) GetLatestRootAssessmentAttempt(ctx context.Context, arg GetLatestRootAssessmentAttemptParams) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, getLatestRootAssessmentAttempt, arg.UserID, arg.Specialization, arg.TargetGrade)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertAssessmentAttempt = `-- name: InsertAssessmentAttempt :exec
|
|
INSERT INTO assessment_attempts (
|
|
id,
|
|
user_id,
|
|
kind,
|
|
mode,
|
|
state,
|
|
outcome,
|
|
bank_category,
|
|
specialization,
|
|
target_grade,
|
|
task_language,
|
|
root_attempt_id,
|
|
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,
|
|
created_at,
|
|
updated_at,
|
|
expires_at,
|
|
chain_deadline,
|
|
idle_timeout_seconds,
|
|
max_sessions,
|
|
sessions_used,
|
|
session_started_at,
|
|
last_activity_at,
|
|
version,
|
|
ended_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12,
|
|
$13,
|
|
$14,
|
|
$15,
|
|
$16,
|
|
$17,
|
|
$18,
|
|
$19,
|
|
$20,
|
|
$21,
|
|
$22,
|
|
$23,
|
|
$24,
|
|
$25,
|
|
$26,
|
|
$27,
|
|
$28,
|
|
$29,
|
|
$30,
|
|
$31
|
|
)
|
|
`
|
|
|
|
type InsertAssessmentAttemptParams struct {
|
|
ID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
Kind string
|
|
Mode string
|
|
State string
|
|
Outcome pgtype.Text
|
|
BankCategory string
|
|
Specialization pgtype.Text
|
|
TargetGrade pgtype.Text
|
|
TaskLanguage pgtype.Text
|
|
RootAttemptID pgtype.UUID
|
|
ProductPolicyVersionID pgtype.UUID
|
|
ProductPolicyVersion int32
|
|
GradingPolicyVersionID pgtype.UUID
|
|
OpeningID pgtype.UUID
|
|
OpeningManifestSha256 []byte
|
|
TrainingBindingID pgtype.UUID
|
|
TrainingManifestSha256 []byte
|
|
BankVersion string
|
|
AlgorithmVersion string
|
|
CreatedAt pgtype.Timestamptz
|
|
UpdatedAt pgtype.Timestamptz
|
|
ExpiresAt pgtype.Timestamptz
|
|
ChainDeadline pgtype.Timestamptz
|
|
IdleTimeoutSeconds int32
|
|
MaxSessions int32
|
|
SessionsUsed int32
|
|
SessionStartedAt pgtype.Timestamptz
|
|
LastActivityAt pgtype.Timestamptz
|
|
Version int64
|
|
EndedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Inserts the attempt header. The database guard rechecks the current policy,
|
|
// opening or disjoint training binding, and immutable pins.
|
|
func (q *Queries) InsertAssessmentAttempt(ctx context.Context, arg InsertAssessmentAttemptParams) error {
|
|
_, err := q.db.Exec(ctx, insertAssessmentAttempt,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.Kind,
|
|
arg.Mode,
|
|
arg.State,
|
|
arg.Outcome,
|
|
arg.BankCategory,
|
|
arg.Specialization,
|
|
arg.TargetGrade,
|
|
arg.TaskLanguage,
|
|
arg.RootAttemptID,
|
|
arg.ProductPolicyVersionID,
|
|
arg.ProductPolicyVersion,
|
|
arg.GradingPolicyVersionID,
|
|
arg.OpeningID,
|
|
arg.OpeningManifestSha256,
|
|
arg.TrainingBindingID,
|
|
arg.TrainingManifestSha256,
|
|
arg.BankVersion,
|
|
arg.AlgorithmVersion,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
arg.ExpiresAt,
|
|
arg.ChainDeadline,
|
|
arg.IdleTimeoutSeconds,
|
|
arg.MaxSessions,
|
|
arg.SessionsUsed,
|
|
arg.SessionStartedAt,
|
|
arg.LastActivityAt,
|
|
arg.Version,
|
|
arg.EndedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertAssessmentAttemptIdempotencyOutcome = `-- name: InsertAssessmentAttemptIdempotencyOutcome :exec
|
|
INSERT INTO assessment_attempt_idempotency_outcomes (
|
|
scope_hash, operation, status_code, problem_code, response_snapshot,
|
|
response_schema_version, pending_item_ids, created_at
|
|
) VALUES (
|
|
$1, $2, $3,
|
|
$4, $5, 1,
|
|
$6::uuid[], transaction_timestamp()
|
|
)
|
|
`
|
|
|
|
type InsertAssessmentAttemptIdempotencyOutcomeParams struct {
|
|
ScopeHash []byte
|
|
Operation string
|
|
StatusCode int16
|
|
ProblemCode pgtype.Text
|
|
ResponseSnapshot []byte
|
|
PendingItemIds []pgtype.UUID
|
|
}
|
|
|
|
func (q *Queries) InsertAssessmentAttemptIdempotencyOutcome(ctx context.Context, arg InsertAssessmentAttemptIdempotencyOutcomeParams) error {
|
|
_, err := q.db.Exec(ctx, insertAssessmentAttemptIdempotencyOutcome,
|
|
arg.ScopeHash,
|
|
arg.Operation,
|
|
arg.StatusCode,
|
|
arg.ProblemCode,
|
|
arg.ResponseSnapshot,
|
|
arg.PendingItemIds,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertAssessmentAttemptItem = `-- name: InsertAssessmentAttemptItem :exec
|
|
INSERT INTO assessment_attempt_items (
|
|
id,
|
|
attempt_id,
|
|
ordinal,
|
|
family_id,
|
|
family_key,
|
|
family_version,
|
|
family_content_sha256,
|
|
variant,
|
|
answer,
|
|
answered_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10
|
|
)
|
|
`
|
|
|
|
type InsertAssessmentAttemptItemParams struct {
|
|
ID pgtype.UUID
|
|
AttemptID pgtype.UUID
|
|
Ordinal int32
|
|
FamilyID pgtype.UUID
|
|
FamilyKey string
|
|
FamilyVersion int32
|
|
FamilyContentSha256 []byte
|
|
Variant []byte
|
|
Answer []byte
|
|
AnsweredAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Stores the immutable generated variant and empty answer slot.
|
|
func (q *Queries) InsertAssessmentAttemptItem(ctx context.Context, arg InsertAssessmentAttemptItemParams) error {
|
|
_, err := q.db.Exec(ctx, insertAssessmentAttemptItem,
|
|
arg.ID,
|
|
arg.AttemptID,
|
|
arg.Ordinal,
|
|
arg.FamilyID,
|
|
arg.FamilyKey,
|
|
arg.FamilyVersion,
|
|
arg.FamilyContentSha256,
|
|
arg.Variant,
|
|
arg.Answer,
|
|
arg.AnsweredAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertAssessmentAttemptResult = `-- name: InsertAssessmentAttemptResult :exec
|
|
INSERT INTO assessment_attempt_results (
|
|
attempt_id, user_id, result_snapshot, schema_version, 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::jsonb, 1,
|
|
$4, $5, $6,
|
|
$7, $8,
|
|
$9, $10, $11,
|
|
$12, $13,
|
|
$14, $15, $16,
|
|
$17, $18, $19,
|
|
$20, $21
|
|
)
|
|
`
|
|
|
|
type InsertAssessmentAttemptResultParams struct {
|
|
AttemptID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
ResultSnapshot []byte
|
|
Kind string
|
|
Mode string
|
|
Outcome string
|
|
ProductPolicyVersionID pgtype.UUID
|
|
ProductPolicyVersion int32
|
|
GradingPolicyVersionID pgtype.UUID
|
|
OpeningID pgtype.UUID
|
|
OpeningManifestSha256 []byte
|
|
TrainingBindingID pgtype.UUID
|
|
TrainingManifestSha256 []byte
|
|
BankVersion string
|
|
AlgorithmVersion string
|
|
RationaleRule string
|
|
PassMarkBasisPoints pgtype.Int4
|
|
ScoredItems pgtype.Int2
|
|
RawScore pgtype.Int2
|
|
PassPoints pgtype.Int2
|
|
DecidedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Stores one immutable candidate-visible result with the decision rationale
|
|
// and source versions used by its finalized attempt.
|
|
func (q *Queries) InsertAssessmentAttemptResult(ctx context.Context, arg InsertAssessmentAttemptResultParams) error {
|
|
_, err := q.db.Exec(ctx, insertAssessmentAttemptResult,
|
|
arg.AttemptID,
|
|
arg.UserID,
|
|
arg.ResultSnapshot,
|
|
arg.Kind,
|
|
arg.Mode,
|
|
arg.Outcome,
|
|
arg.ProductPolicyVersionID,
|
|
arg.ProductPolicyVersion,
|
|
arg.GradingPolicyVersionID,
|
|
arg.OpeningID,
|
|
arg.OpeningManifestSha256,
|
|
arg.TrainingBindingID,
|
|
arg.TrainingManifestSha256,
|
|
arg.BankVersion,
|
|
arg.AlgorithmVersion,
|
|
arg.RationaleRule,
|
|
arg.PassMarkBasisPoints,
|
|
arg.ScoredItems,
|
|
arg.RawScore,
|
|
arg.PassPoints,
|
|
arg.DecidedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listAssessmentAttemptChain = `-- name: ListAssessmentAttemptChain :many
|
|
SELECT
|
|
id, user_id, kind, mode, state, outcome, bank_category, specialization,
|
|
target_grade, task_language, root_attempt_id, 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, created_at, updated_at, expires_at,
|
|
chain_deadline, idle_timeout_seconds, max_sessions, sessions_used,
|
|
session_started_at, last_activity_at, version, ended_at
|
|
FROM assessment_attempts
|
|
WHERE user_id = $1
|
|
AND specialization = $2
|
|
AND (id = $3 OR root_attempt_id = $3)
|
|
ORDER BY created_at, id
|
|
FOR SHARE
|
|
`
|
|
|
|
type ListAssessmentAttemptChainParams struct {
|
|
UserID pgtype.UUID
|
|
Specialization pgtype.Text
|
|
RootAttemptID pgtype.UUID
|
|
}
|
|
|
|
// Reads chain headers in creation order. The use case verifies root eligibility
|
|
// and descending target grades in the domain before it creates a correction.
|
|
func (q *Queries) ListAssessmentAttemptChain(ctx context.Context, arg ListAssessmentAttemptChainParams) ([]AssessmentAttempt, error) {
|
|
rows, err := q.db.Query(ctx, listAssessmentAttemptChain, arg.UserID, arg.Specialization, arg.RootAttemptID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AssessmentAttempt
|
|
for rows.Next() {
|
|
var i AssessmentAttempt
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listAssessmentAttemptItems = `-- name: ListAssessmentAttemptItems :many
|
|
SELECT
|
|
id, attempt_id, ordinal, family_id, family_key, family_version,
|
|
family_content_sha256, variant::text AS variant, answer, answered_at
|
|
FROM assessment_attempt_items
|
|
WHERE attempt_id = $1
|
|
ORDER BY ordinal
|
|
`
|
|
|
|
type ListAssessmentAttemptItemsRow struct {
|
|
ID pgtype.UUID
|
|
AttemptID pgtype.UUID
|
|
Ordinal int32
|
|
FamilyID pgtype.UUID
|
|
FamilyKey string
|
|
FamilyVersion int32
|
|
FamilyContentSha256 []byte
|
|
Variant string
|
|
Answer []byte
|
|
AnsweredAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Reads private frozen variants and candidate answer bytes in stable order.
|
|
func (q *Queries) ListAssessmentAttemptItems(ctx context.Context, attemptID pgtype.UUID) ([]ListAssessmentAttemptItemsRow, error) {
|
|
rows, err := q.db.Query(ctx, listAssessmentAttemptItems, attemptID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListAssessmentAttemptItemsRow
|
|
for rows.Next() {
|
|
var i ListAssessmentAttemptItemsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.AttemptID,
|
|
&i.Ordinal,
|
|
&i.FamilyID,
|
|
&i.FamilyKey,
|
|
&i.FamilyVersion,
|
|
&i.FamilyContentSha256,
|
|
&i.Variant,
|
|
&i.Answer,
|
|
&i.AnsweredAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listAssessmentTrainingBindingFamilies = `-- name: ListAssessmentTrainingBindingFamilies :many
|
|
SELECT
|
|
family_id,
|
|
ordinal,
|
|
family_key,
|
|
family_version,
|
|
content_sha256
|
|
FROM assessment_training_bank_binding_families
|
|
WHERE binding_id = $1
|
|
ORDER BY ordinal
|
|
`
|
|
|
|
type ListAssessmentTrainingBindingFamiliesRow struct {
|
|
FamilyID pgtype.UUID
|
|
Ordinal int32
|
|
FamilyKey string
|
|
FamilyVersion int32
|
|
ContentSha256 []byte
|
|
}
|
|
|
|
// Reads the exact family membership pinned by a training binding.
|
|
func (q *Queries) ListAssessmentTrainingBindingFamilies(ctx context.Context, bindingID pgtype.UUID) ([]ListAssessmentTrainingBindingFamiliesRow, error) {
|
|
rows, err := q.db.Query(ctx, listAssessmentTrainingBindingFamilies, bindingID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListAssessmentTrainingBindingFamiliesRow
|
|
for rows.Next() {
|
|
var i ListAssessmentTrainingBindingFamiliesRow
|
|
if err := rows.Scan(
|
|
&i.FamilyID,
|
|
&i.Ordinal,
|
|
&i.FamilyKey,
|
|
&i.FamilyVersion,
|
|
&i.ContentSha256,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listCurrentAssessmentTrainingBindings = `-- name: ListCurrentAssessmentTrainingBindings :many
|
|
SELECT
|
|
binding.id,
|
|
binding.category,
|
|
binding.product_policy_version_id,
|
|
binding.item_count,
|
|
binding.manifest_sha256,
|
|
binding.family_manifest,
|
|
policy.version AS product_policy_version
|
|
FROM assessment_training_bank_bindings AS binding
|
|
JOIN policy_versions AS policy ON policy.id = binding.product_policy_version_id
|
|
WHERE policy.policy_key = 'product'
|
|
AND policy.effective_at <= statement_timestamp()
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM policy_versions AS newer
|
|
WHERE newer.policy_key = 'product'
|
|
AND newer.effective_at <= statement_timestamp()
|
|
AND newer.version > policy.version
|
|
)
|
|
ORDER BY binding.category, binding.created_at DESC, binding.id
|
|
`
|
|
|
|
type ListCurrentAssessmentTrainingBindingsRow struct {
|
|
ID pgtype.UUID
|
|
Category string
|
|
ProductPolicyVersionID pgtype.UUID
|
|
ItemCount int32
|
|
ManifestSha256 []byte
|
|
FamilyManifest []byte
|
|
ProductPolicyVersion int32
|
|
}
|
|
|
|
// Lists explicit immutable training bindings for the effective product
|
|
// policy. Callers reject more than one matching active binding as ambiguous.
|
|
func (q *Queries) ListCurrentAssessmentTrainingBindings(ctx context.Context) ([]ListCurrentAssessmentTrainingBindingsRow, error) {
|
|
rows, err := q.db.Query(ctx, listCurrentAssessmentTrainingBindings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListCurrentAssessmentTrainingBindingsRow
|
|
for rows.Next() {
|
|
var i ListCurrentAssessmentTrainingBindingsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Category,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ItemCount,
|
|
&i.ManifestSha256,
|
|
&i.FamilyManifest,
|
|
&i.ProductPolicyVersion,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const lockAssessmentAttemptForCandidate = `-- name: LockAssessmentAttemptForCandidate :one
|
|
SELECT
|
|
id, user_id, kind, mode, state, outcome, bank_category, specialization,
|
|
target_grade, task_language, root_attempt_id, 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, created_at, updated_at, expires_at,
|
|
chain_deadline, idle_timeout_seconds, max_sessions, sessions_used,
|
|
session_started_at, last_activity_at, version, ended_at
|
|
FROM assessment_attempts
|
|
WHERE id = $1 AND user_id = $2
|
|
FOR UPDATE
|
|
`
|
|
|
|
type LockAssessmentAttemptForCandidateParams struct {
|
|
ID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
}
|
|
|
|
// Locks one owner-scoped attempt while a session command performs its CAS.
|
|
func (q *Queries) LockAssessmentAttemptForCandidate(ctx context.Context, arg LockAssessmentAttemptForCandidateParams) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, lockAssessmentAttemptForCandidate, arg.ID, arg.UserID)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const lockAssessmentAttemptScope = `-- name: LockAssessmentAttemptScope :exec
|
|
WITH candidate_lock AS MATERIALIZED (
|
|
SELECT pg_advisory_xact_lock(hashtextextended(
|
|
'lincodex.assessment.attempt:user:' || $1::text,
|
|
0
|
|
))
|
|
)
|
|
SELECT pg_advisory_xact_lock(hashtextextended(
|
|
'lincodex.assessment.attempt:track:' || $1::text || ':' ||
|
|
COALESCE($2::text, 'training'),
|
|
0
|
|
))
|
|
FROM candidate_lock
|
|
`
|
|
|
|
type LockAssessmentAttemptScopeParams struct {
|
|
UserID string
|
|
Specialization pgtype.Text
|
|
}
|
|
|
|
// Serializes root quota checks for one candidate before taking its optional
|
|
// specialization or training lock. All callers acquire these locks in order.
|
|
func (q *Queries) LockAssessmentAttemptScope(ctx context.Context, arg LockAssessmentAttemptScopeParams) error {
|
|
_, err := q.db.Exec(ctx, lockAssessmentAttemptScope, arg.UserID, arg.Specialization)
|
|
return err
|
|
}
|
|
|
|
const resolveCurrentAssessmentSelection = `-- name: ResolveCurrentAssessmentSelection :many
|
|
WITH current_openings AS (
|
|
SELECT DISTINCT ON (category)
|
|
id,
|
|
category,
|
|
policy_version_id,
|
|
required_families
|
|
FROM assessment_category_openings
|
|
ORDER BY category, opened_at DESC, id DESC
|
|
), current_policy AS (
|
|
SELECT id, version
|
|
FROM policy_versions
|
|
WHERE policy_key = 'product' AND effective_at <= statement_timestamp()
|
|
ORDER BY version DESC
|
|
LIMIT 1
|
|
)
|
|
SELECT
|
|
opening.id AS opening_id,
|
|
opening.category,
|
|
opening.policy_version_id,
|
|
opening.required_families,
|
|
COALESCE((
|
|
SELECT count(DISTINCT family.family_key)::integer
|
|
FROM assessment_families AS family
|
|
WHERE family.category = opening.category AND family.lifecycle = 'published'
|
|
), 0)::integer AS published_count,
|
|
policy.id AS effective_policy_id,
|
|
policy.version AS effective_policy_version,
|
|
binding.specialization,
|
|
binding.grade,
|
|
binding.task_languages,
|
|
binding.published_manifest_sha256,
|
|
COALESCE((
|
|
SELECT jsonb_agg(
|
|
jsonb_build_object(
|
|
'family_key', family.family_key,
|
|
'version', family.version,
|
|
'content_sha256', encode(family.content_sha256, 'hex')
|
|
) ORDER BY family.family_key, family.version
|
|
)
|
|
FROM assessment_families AS family
|
|
WHERE family.category = opening.category AND family.lifecycle = 'published'
|
|
), '[]'::jsonb)::text AS published_manifest
|
|
FROM current_openings AS opening
|
|
JOIN assessment_category_catalog_bindings AS binding
|
|
ON binding.opening_id = opening.id
|
|
LEFT JOIN current_policy AS policy ON true
|
|
WHERE binding.specialization = $1
|
|
AND binding.grade = $2
|
|
AND (
|
|
($3::text IS NULL AND cardinality(binding.task_languages) = 0)
|
|
OR $3::text = ANY(binding.task_languages)
|
|
)
|
|
ORDER BY opening.category
|
|
`
|
|
|
|
type ResolveCurrentAssessmentSelectionParams struct {
|
|
Specialization string
|
|
Grade string
|
|
TaskLanguage pgtype.Text
|
|
}
|
|
|
|
type ResolveCurrentAssessmentSelectionRow struct {
|
|
OpeningID pgtype.UUID
|
|
Category string
|
|
PolicyVersionID pgtype.UUID
|
|
RequiredFamilies int32
|
|
PublishedCount int32
|
|
EffectivePolicyID pgtype.UUID
|
|
EffectivePolicyVersion pgtype.Int4
|
|
Specialization string
|
|
Grade string
|
|
TaskLanguages []string
|
|
PublishedManifestSha256 []byte
|
|
PublishedManifest string
|
|
}
|
|
|
|
// Finds candidate-requested selections across currently opened categories.
|
|
// The adapter validates policy and manifest freshness, locks the category,
|
|
// then runs this query again before it returns any pinned families.
|
|
func (q *Queries) ResolveCurrentAssessmentSelection(ctx context.Context, arg ResolveCurrentAssessmentSelectionParams) ([]ResolveCurrentAssessmentSelectionRow, error) {
|
|
rows, err := q.db.Query(ctx, resolveCurrentAssessmentSelection, arg.Specialization, arg.Grade, arg.TaskLanguage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ResolveCurrentAssessmentSelectionRow
|
|
for rows.Next() {
|
|
var i ResolveCurrentAssessmentSelectionRow
|
|
if err := rows.Scan(
|
|
&i.OpeningID,
|
|
&i.Category,
|
|
&i.PolicyVersionID,
|
|
&i.RequiredFamilies,
|
|
&i.PublishedCount,
|
|
&i.EffectivePolicyID,
|
|
&i.EffectivePolicyVersion,
|
|
&i.Specialization,
|
|
&i.Grade,
|
|
&i.TaskLanguages,
|
|
&i.PublishedManifestSha256,
|
|
&i.PublishedManifest,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateAssessmentAttemptItemAnswer = `-- name: UpdateAssessmentAttemptItemAnswer :one
|
|
UPDATE assessment_attempt_items
|
|
SET answer = $1, answered_at = $2
|
|
WHERE attempt_id = $3
|
|
AND id = $4
|
|
AND answer IS NULL
|
|
RETURNING id
|
|
`
|
|
|
|
type UpdateAssessmentAttemptItemAnswerParams struct {
|
|
Answer []byte
|
|
AnsweredAt pgtype.Timestamptz
|
|
AttemptID pgtype.UUID
|
|
ItemID pgtype.UUID
|
|
}
|
|
|
|
// Stores one final answer before advancing the enclosing attempt version.
|
|
// The caller holds the owner-scoped attempt row lock for the surrounding unit.
|
|
func (q *Queries) UpdateAssessmentAttemptItemAnswer(ctx context.Context, arg UpdateAssessmentAttemptItemAnswerParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, updateAssessmentAttemptItemAnswer,
|
|
arg.Answer,
|
|
arg.AnsweredAt,
|
|
arg.AttemptID,
|
|
arg.ItemID,
|
|
)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const updateAssessmentAttemptSession = `-- name: UpdateAssessmentAttemptSession :one
|
|
UPDATE assessment_attempts
|
|
SET
|
|
state = $1,
|
|
outcome = $2,
|
|
updated_at = $3,
|
|
sessions_used = $4,
|
|
session_started_at = $5,
|
|
last_activity_at = $6,
|
|
version = $7,
|
|
ended_at = $8
|
|
WHERE id = $9
|
|
AND user_id = $10
|
|
AND version = $11
|
|
RETURNING
|
|
id, user_id, kind, mode, state, outcome, bank_category, specialization,
|
|
target_grade, task_language, root_attempt_id, 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, created_at, updated_at, expires_at,
|
|
chain_deadline, idle_timeout_seconds, max_sessions, sessions_used,
|
|
session_started_at, last_activity_at, version, ended_at
|
|
`
|
|
|
|
type UpdateAssessmentAttemptSessionParams struct {
|
|
State string
|
|
Outcome pgtype.Text
|
|
UpdatedAt pgtype.Timestamptz
|
|
SessionsUsed int32
|
|
SessionStartedAt pgtype.Timestamptz
|
|
LastActivityAt pgtype.Timestamptz
|
|
Version int64
|
|
EndedAt pgtype.Timestamptz
|
|
ID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
ExpectedVersion int64
|
|
}
|
|
|
|
// Applies a versioned session transition after the attempt row is locked.
|
|
func (q *Queries) UpdateAssessmentAttemptSession(ctx context.Context, arg UpdateAssessmentAttemptSessionParams) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, updateAssessmentAttemptSession,
|
|
arg.State,
|
|
arg.Outcome,
|
|
arg.UpdatedAt,
|
|
arg.SessionsUsed,
|
|
arg.SessionStartedAt,
|
|
arg.LastActivityAt,
|
|
arg.Version,
|
|
arg.EndedAt,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.ExpectedVersion,
|
|
)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateAssessmentAttemptTransition = `-- name: UpdateAssessmentAttemptTransition :one
|
|
UPDATE assessment_attempts
|
|
SET
|
|
state = $1,
|
|
outcome = $2,
|
|
updated_at = $3,
|
|
last_activity_at = $4,
|
|
version = $5,
|
|
ended_at = $6
|
|
WHERE id = $7
|
|
AND user_id = $8
|
|
AND version = $9
|
|
RETURNING
|
|
id, user_id, kind, mode, state, outcome, bank_category, specialization,
|
|
target_grade, task_language, root_attempt_id, 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, created_at, updated_at, expires_at,
|
|
chain_deadline, idle_timeout_seconds, max_sessions, sessions_used,
|
|
session_started_at, last_activity_at, version, ended_at
|
|
`
|
|
|
|
type UpdateAssessmentAttemptTransitionParams struct {
|
|
State string
|
|
Outcome pgtype.Text
|
|
UpdatedAt pgtype.Timestamptz
|
|
LastActivityAt pgtype.Timestamptz
|
|
Version int64
|
|
EndedAt pgtype.Timestamptz
|
|
ID pgtype.UUID
|
|
UserID pgtype.UUID
|
|
ExpectedVersion int64
|
|
}
|
|
|
|
// Applies an answer, expiry, or finalization transition after the attempt row
|
|
// is locked. Session limits and all immutable pins remain unchanged.
|
|
func (q *Queries) UpdateAssessmentAttemptTransition(ctx context.Context, arg UpdateAssessmentAttemptTransitionParams) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, updateAssessmentAttemptTransition,
|
|
arg.State,
|
|
arg.Outcome,
|
|
arg.UpdatedAt,
|
|
arg.LastActivityAt,
|
|
arg.Version,
|
|
arg.EndedAt,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.ExpectedVersion,
|
|
)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Kind,
|
|
&i.Mode,
|
|
&i.State,
|
|
&i.Outcome,
|
|
&i.BankCategory,
|
|
&i.Specialization,
|
|
&i.TargetGrade,
|
|
&i.TaskLanguage,
|
|
&i.RootAttemptID,
|
|
&i.ProductPolicyVersionID,
|
|
&i.ProductPolicyVersion,
|
|
&i.GradingPolicyVersionID,
|
|
&i.OpeningID,
|
|
&i.OpeningManifestSha256,
|
|
&i.TrainingBindingID,
|
|
&i.TrainingManifestSha256,
|
|
&i.BankVersion,
|
|
&i.AlgorithmVersion,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
&i.ChainDeadline,
|
|
&i.IdleTimeoutSeconds,
|
|
&i.MaxSessions,
|
|
&i.SessionsUsed,
|
|
&i.SessionStartedAt,
|
|
&i.LastActivityAt,
|
|
&i.Version,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|