404 lines
12 KiB
Go
404 lines
12 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: questionnaire.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const advanceCandidateOnboardingAfterQuestionnaire = `-- name: AdvanceCandidateOnboardingAfterQuestionnaire :exec
|
|
UPDATE users
|
|
SET
|
|
onboarding_step = 'candidate_assessment',
|
|
version = users.version + 1,
|
|
updated_at = GREATEST(users.updated_at, $1::timestamptz)
|
|
WHERE
|
|
users.id = $2
|
|
AND users.scenario = 'candidate'
|
|
AND users.email_verified_at IS NOT NULL
|
|
AND users.onboarding_step = 'candidate_questionnaire'
|
|
`
|
|
|
|
type AdvanceCandidateOnboardingAfterQuestionnaireParams struct {
|
|
At pgtype.Timestamptz
|
|
UserID pgtype.UUID
|
|
}
|
|
|
|
// A questionnaire save advances onboarding only from its own step.
|
|
func (q *Queries) AdvanceCandidateOnboardingAfterQuestionnaire(ctx context.Context, arg AdvanceCandidateOnboardingAfterQuestionnaireParams) error {
|
|
_, err := q.db.Exec(ctx, advanceCandidateOnboardingAfterQuestionnaire, arg.At, arg.UserID)
|
|
return err
|
|
}
|
|
|
|
const advanceCandidateQuestionnaireVersion = `-- name: AdvanceCandidateQuestionnaireVersion :one
|
|
UPDATE candidate_questionnaires
|
|
SET
|
|
version = candidate_questionnaires.version + 1,
|
|
work_formats = $1,
|
|
updated_at = GREATEST(candidate_questionnaires.updated_at, $2::timestamptz)
|
|
WHERE
|
|
candidate_questionnaires.user_id = $3
|
|
AND candidate_questionnaires.version = $4
|
|
RETURNING user_id, version, work_formats, created_at, updated_at
|
|
`
|
|
|
|
type AdvanceCandidateQuestionnaireVersionParams struct {
|
|
WorkFormats []string
|
|
At pgtype.Timestamptz
|
|
UserID pgtype.UUID
|
|
ExpectedVersion int64
|
|
}
|
|
|
|
// Advances an existing questionnaire only at the version read by the caller.
|
|
// The row lock serializes saves for one user; a stale writer returns no row.
|
|
func (q *Queries) AdvanceCandidateQuestionnaireVersion(ctx context.Context, arg AdvanceCandidateQuestionnaireVersionParams) (CandidateQuestionnaire, error) {
|
|
row := q.db.QueryRow(ctx, advanceCandidateQuestionnaireVersion,
|
|
arg.WorkFormats,
|
|
arg.At,
|
|
arg.UserID,
|
|
arg.ExpectedVersion,
|
|
)
|
|
var i CandidateQuestionnaire
|
|
err := row.Scan(
|
|
&i.UserID,
|
|
&i.Version,
|
|
&i.WorkFormats,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteCandidateQuestionnaireSpecializations = `-- name: DeleteCandidateQuestionnaireSpecializations :exec
|
|
DELETE FROM candidate_questionnaire_specializations
|
|
WHERE user_id = $1
|
|
`
|
|
|
|
// Replaces all specialization answers after the version row advanced in the
|
|
// same transaction.
|
|
func (q *Queries) DeleteCandidateQuestionnaireSpecializations(ctx context.Context, userID pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteCandidateQuestionnaireSpecializations, userID)
|
|
return err
|
|
}
|
|
|
|
const insertAssessmentCategoryCatalogBinding = `-- name: InsertAssessmentCategoryCatalogBinding :exec
|
|
INSERT INTO assessment_category_catalog_bindings (
|
|
opening_id,
|
|
specialization,
|
|
grade,
|
|
task_languages,
|
|
published_manifest_sha256,
|
|
reviewed_by,
|
|
reviewed_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
clock_timestamp()
|
|
)
|
|
`
|
|
|
|
type InsertAssessmentCategoryCatalogBindingParams struct {
|
|
OpeningID pgtype.UUID
|
|
Specialization string
|
|
Grade string
|
|
TaskLanguages []string
|
|
PublishedManifestSha256 []byte
|
|
ReviewedBy string
|
|
}
|
|
|
|
// Stores an explicit mapping against a newly-created immutable opening. The
|
|
// insert trigger checks the opening, declared reviewer, current policy, and
|
|
// live coverage; the adapter supplies the fingerprint of the published set.
|
|
func (q *Queries) InsertAssessmentCategoryCatalogBinding(ctx context.Context, arg InsertAssessmentCategoryCatalogBindingParams) error {
|
|
_, err := q.db.Exec(ctx, insertAssessmentCategoryCatalogBinding,
|
|
arg.OpeningID,
|
|
arg.Specialization,
|
|
arg.Grade,
|
|
arg.TaskLanguages,
|
|
arg.PublishedManifestSha256,
|
|
arg.ReviewedBy,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertCandidateQuestionnaire = `-- name: InsertCandidateQuestionnaire :one
|
|
INSERT INTO candidate_questionnaires (
|
|
user_id,
|
|
version,
|
|
work_formats,
|
|
created_at,
|
|
updated_at
|
|
) VALUES (
|
|
$1,
|
|
1,
|
|
$2,
|
|
$3::timestamptz,
|
|
$3::timestamptz
|
|
)
|
|
ON CONFLICT (user_id) DO NOTHING
|
|
RETURNING user_id, version, work_formats, created_at, updated_at
|
|
`
|
|
|
|
type InsertCandidateQuestionnaireParams struct {
|
|
UserID pgtype.UUID
|
|
WorkFormats []string
|
|
At pgtype.Timestamptz
|
|
}
|
|
|
|
// Creates the first saved questionnaire. A missing row is version zero;
|
|
// concurrent first saves race on the primary key and exactly one returns a row.
|
|
func (q *Queries) InsertCandidateQuestionnaire(ctx context.Context, arg InsertCandidateQuestionnaireParams) (CandidateQuestionnaire, error) {
|
|
row := q.db.QueryRow(ctx, insertCandidateQuestionnaire, arg.UserID, arg.WorkFormats, arg.At)
|
|
var i CandidateQuestionnaire
|
|
err := row.Scan(
|
|
&i.UserID,
|
|
&i.Version,
|
|
&i.WorkFormats,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertCandidateQuestionnaireSpecialization = `-- name: InsertCandidateQuestionnaireSpecialization :exec
|
|
INSERT INTO candidate_questionnaire_specializations (
|
|
user_id,
|
|
ordinal,
|
|
specialization,
|
|
self_assessed_grade,
|
|
task_languages,
|
|
stack,
|
|
commercial_months,
|
|
academic_months
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8
|
|
)
|
|
`
|
|
|
|
type InsertCandidateQuestionnaireSpecializationParams struct {
|
|
UserID pgtype.UUID
|
|
Ordinal int16
|
|
Specialization string
|
|
SelfAssessedGrade string
|
|
TaskLanguages []string
|
|
Stack []string
|
|
CommercialMonths pgtype.Int4
|
|
AcademicMonths pgtype.Int4
|
|
}
|
|
|
|
func (q *Queries) InsertCandidateQuestionnaireSpecialization(ctx context.Context, arg InsertCandidateQuestionnaireSpecializationParams) error {
|
|
_, err := q.db.Exec(ctx, insertCandidateQuestionnaireSpecialization,
|
|
arg.UserID,
|
|
arg.Ordinal,
|
|
arg.Specialization,
|
|
arg.SelfAssessedGrade,
|
|
arg.TaskLanguages,
|
|
arg.Stack,
|
|
arg.CommercialMonths,
|
|
arg.AcademicMonths,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listCurrentSpecializationAvailability = `-- name: ListCurrentSpecializationAvailability :many
|
|
WITH current_policy AS (
|
|
SELECT id
|
|
FROM policy_versions
|
|
WHERE policy_key = 'product' AND effective_at <= statement_timestamp()
|
|
ORDER BY version DESC
|
|
LIMIT 1
|
|
), current_openings AS (
|
|
SELECT DISTINCT ON (category)
|
|
id,
|
|
category,
|
|
policy_version_id,
|
|
required_families,
|
|
opened_at
|
|
FROM assessment_category_openings
|
|
ORDER BY category, opened_at DESC, id DESC
|
|
)
|
|
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,
|
|
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
|
|
ORDER BY opening.category
|
|
`
|
|
|
|
type ListCurrentSpecializationAvailabilityRow struct {
|
|
OpeningID pgtype.UUID
|
|
Category string
|
|
PolicyVersionID pgtype.UUID
|
|
RequiredFamilies int32
|
|
PublishedCount int32
|
|
EffectivePolicyID pgtype.UUID
|
|
Specialization string
|
|
Grade string
|
|
TaskLanguages []string
|
|
PublishedManifestSha256 []byte
|
|
PublishedManifest string
|
|
}
|
|
|
|
// Produces current catalog availability in one PostgreSQL statement snapshot.
|
|
// The adapter compares the ordered live family manifest with the pinned
|
|
// fingerprint; stale bindings are omitted fail-closed.
|
|
func (q *Queries) ListCurrentSpecializationAvailability(ctx context.Context) ([]ListCurrentSpecializationAvailabilityRow, error) {
|
|
rows, err := q.db.Query(ctx, listCurrentSpecializationAvailability)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListCurrentSpecializationAvailabilityRow
|
|
for rows.Next() {
|
|
var i ListCurrentSpecializationAvailabilityRow
|
|
if err := rows.Scan(
|
|
&i.OpeningID,
|
|
&i.Category,
|
|
&i.PolicyVersionID,
|
|
&i.RequiredFamilies,
|
|
&i.PublishedCount,
|
|
&i.EffectivePolicyID,
|
|
&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 readCandidateQuestionnaire = `-- name: ReadCandidateQuestionnaire :one
|
|
SELECT
|
|
questionnaire.user_id,
|
|
questionnaire.version,
|
|
questionnaire.work_formats,
|
|
questionnaire.created_at,
|
|
questionnaire.updated_at,
|
|
COALESCE((
|
|
SELECT jsonb_agg(
|
|
jsonb_build_object(
|
|
'ordinal', specialization.ordinal,
|
|
'specialization', specialization.specialization,
|
|
'self_assessed_grade', specialization.self_assessed_grade,
|
|
'task_languages', specialization.task_languages,
|
|
'stack', specialization.stack,
|
|
'commercial_months', specialization.commercial_months,
|
|
'academic_months', specialization.academic_months
|
|
) ORDER BY specialization.ordinal
|
|
)
|
|
FROM candidate_questionnaire_specializations AS specialization
|
|
WHERE specialization.user_id = questionnaire.user_id
|
|
), '[]'::jsonb)::text AS specializations
|
|
FROM candidate_questionnaires AS questionnaire
|
|
WHERE questionnaire.user_id = $1
|
|
`
|
|
|
|
type ReadCandidateQuestionnaireRow struct {
|
|
UserID pgtype.UUID
|
|
Version int64
|
|
WorkFormats []string
|
|
CreatedAt pgtype.Timestamptz
|
|
UpdatedAt pgtype.Timestamptz
|
|
Specializations string
|
|
}
|
|
|
|
// Reads the aggregate and its ordered specializations in one statement so a
|
|
// response never pairs a version with another version's answers.
|
|
func (q *Queries) ReadCandidateQuestionnaire(ctx context.Context, userID pgtype.UUID) (ReadCandidateQuestionnaireRow, error) {
|
|
row := q.db.QueryRow(ctx, readCandidateQuestionnaire, userID)
|
|
var i ReadCandidateQuestionnaireRow
|
|
err := row.Scan(
|
|
&i.UserID,
|
|
&i.Version,
|
|
&i.WorkFormats,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Specializations,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const readPublishedAssessmentCategoryManifest = `-- name: ReadPublishedAssessmentCategoryManifest :many
|
|
SELECT family_key, version, content_sha256
|
|
FROM assessment_families
|
|
WHERE category = $1 AND lifecycle = 'published'
|
|
ORDER BY family_key, version
|
|
`
|
|
|
|
type ReadPublishedAssessmentCategoryManifestRow struct {
|
|
FamilyKey string
|
|
Version int32
|
|
ContentSha256 []byte
|
|
}
|
|
|
|
// Lists the exact published bank manifest while the category advisory lock is
|
|
// held by OpenCategory. Published families have passed the independent-review
|
|
// constraint before this read.
|
|
func (q *Queries) ReadPublishedAssessmentCategoryManifest(ctx context.Context, category string) ([]ReadPublishedAssessmentCategoryManifestRow, error) {
|
|
rows, err := q.db.Query(ctx, readPublishedAssessmentCategoryManifest, category)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ReadPublishedAssessmentCategoryManifestRow
|
|
for rows.Next() {
|
|
var i ReadPublishedAssessmentCategoryManifestRow
|
|
if err := rows.Scan(&i.FamilyKey, &i.Version, &i.ContentSha256); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|