Files
lincodex/backend/internal/adapter/secondary/postgres/sqlc/privacy_cohort.sql.go
T

359 lines
13 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: privacy_cohort.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const listVisibleCandidateViewSources = `-- name: ListVisibleCandidateViewSources :many
SELECT
effective.user_id,
effective.fields,
claim.kind,
claim.ordinal,
CASE
WHEN claim.kind = 'experience' THEN jsonb_build_object(
'employer_name', NULL::text,
'specialization', claim.value ->> 'specialization',
'started_on', claim.value ->> 'started_on',
'ended_on', claim.value -> 'ended_on',
'summary', NULL::text
)
ELSE claim.value
END AS safe_value,
claim.status,
claim.origin,
claim.trust_level,
claim.extraction_version,
claim.confirmed_at,
COALESCE(questionnaire.work_formats, '{}'::text[]) AS work_formats,
COALESCE(
(
SELECT jsonb_agg(
jsonb_build_object(
'first_index', overlap.first_index,
'second_index', overlap.second_index,
'first_period', jsonb_build_object(
'started_on', overlap.first_started_on,
'ended_on', overlap.first_ended_on
),
'second_period', jsonb_build_object(
'started_on', overlap.second_started_on,
'ended_on', overlap.second_ended_on
)
) ORDER BY overlap.first_index, overlap.second_index
)::text
FROM candidate_profile_overlap_confirmations AS overlap
WHERE overlap.user_id = effective.user_id
),
'[]'::text
) AS parallel_period_acknowledgements,
COALESCE(
(
SELECT jsonb_agg(
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
ORDER BY category.specialization
)::text
FROM candidate_assessment_categories AS category
WHERE category.candidate_id = effective.user_id
),
'[]'::text
) AS confirmed_categories
FROM candidate_effective_publications AS effective
LEFT JOIN candidate_profile_claims AS claim
ON claim.user_id = effective.user_id
AND claim.kind IN ('stack', 'role', 'experience')
LEFT JOIN candidate_questionnaires AS questionnaire
ON questionnaire.user_id = effective.user_id
WHERE NOT EXISTS (
SELECT 1
FROM candidate_hidden_organizations AS hidden
WHERE hidden.user_id = effective.user_id
AND hidden.organization_id = $1
)
ORDER BY effective.user_id, claim.kind, claim.ordinal
`
type ListVisibleCandidateViewSourcesRow struct {
UserID pgtype.UUID
Fields []string
Kind pgtype.Text
Ordinal pgtype.Int2
SafeValue interface{}
Status pgtype.Text
Origin pgtype.Text
TrustLevel pgtype.Int2
ExtractionVersion pgtype.Text
ConfirmedAt pgtype.Timestamptz
WorkFormats []string
ParallelPeriodAcknowledgements interface{}
ConfirmedCategories interface{}
}
// Organization-facing anonymous candidate projection inputs. The calling
// usecase has already authorized the active organization membership. This
// single statement snapshot filters both revoked/unpublished C2 states and
// candidates hidden from this organization before any profile value is read.
// The projection reads only stack, declared role, and experience dates. It
// deliberately excludes names, contacts, salary, location, soft skills,
// employer names, summaries, and imported excerpts. The only assessment data
// is the current category (specialization and grade) of the separate current
// category table; it carries no attempt, score, review, policy, or history.
func (q *Queries) ListVisibleCandidateViewSources(ctx context.Context, organizationID pgtype.UUID) ([]ListVisibleCandidateViewSourcesRow, error) {
rows, err := q.db.Query(ctx, listVisibleCandidateViewSources, organizationID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListVisibleCandidateViewSourcesRow
for rows.Next() {
var i ListVisibleCandidateViewSourcesRow
if err := rows.Scan(
&i.UserID,
&i.Fields,
&i.Kind,
&i.Ordinal,
&i.SafeValue,
&i.Status,
&i.Origin,
&i.TrustLevel,
&i.ExtractionVersion,
&i.ConfirmedAt,
&i.WorkFormats,
&i.ParallelPeriodAcknowledgements,
&i.ConfirmedCategories,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const lockCandidateAccountForView = `-- name: LockCandidateAccountForView :one
SELECT users.id
FROM users
WHERE users.id = $1
FOR SHARE
`
// Lock the account before an organization checks candidate visibility. The
// hidden-organization insert trigger takes FOR NO KEY UPDATE on this row, so
// a hide either commits before the later visibility recheck or waits for the
// read transaction to finish.
func (q *Queries) LockCandidateAccountForView(ctx context.Context, candidateID pgtype.UUID) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, lockCandidateAccountForView, candidateID)
var id pgtype.UUID
err := row.Scan(&id)
return id, err
}
const lockCurrentC2ForView = `-- name: LockCurrentC2ForView :one
SELECT consent_records.id
FROM consent_records
WHERE
consent_records.subject_id = $1
AND consent_records.purpose = 'c2'
AND consent_records.revoked_at IS NULL
ORDER BY consent_records.granted_at DESC, consent_records.id DESC
LIMIT 1
FOR SHARE
`
// Lock the current C2 before locking the publication. C2 revocation updates
// this row before it locks the publication, so preserving this order avoids
// a lock inversion and makes the current consent stable through the read.
func (q *Queries) LockCurrentC2ForView(ctx context.Context, candidateID pgtype.UUID) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, lockCurrentC2ForView, candidateID)
var id pgtype.UUID
err := row.Scan(&id)
return id, err
}
const lockPublicationForCandidatePreview = `-- name: LockPublicationForCandidatePreview :one
SELECT candidate_publications.user_id
FROM candidate_publications
INNER JOIN consent_records
ON consent_records.id = candidate_publications.consent_record_id
WHERE
candidate_publications.user_id = $1
AND candidate_publications.state = 'published'
AND consent_records.subject_id = candidate_publications.user_id
AND consent_records.purpose = 'c2'
AND consent_records.revoked_at IS NULL
FOR SHARE OF candidate_publications, consent_records
`
// Lock a candidate's current publication for the private preview. This has
// no organization context and never enters the employer read quota or audit.
func (q *Queries) LockPublicationForCandidatePreview(ctx context.Context, candidateID pgtype.UUID) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, lockPublicationForCandidatePreview, candidateID)
var user_id pgtype.UUID
err := row.Scan(&user_id)
return user_id, err
}
const lockVisiblePublicationForView = `-- name: LockVisiblePublicationForView :one
SELECT candidate_publications.user_id
FROM candidate_publications
INNER JOIN consent_records
ON consent_records.id = candidate_publications.consent_record_id
WHERE
candidate_publications.user_id = $1
AND candidate_publications.state = 'published'
AND candidate_publications.consent_record_id = $2
AND consent_records.subject_id = candidate_publications.user_id
AND consent_records.purpose = 'c2'
AND consent_records.revoked_at IS NULL
AND NOT EXISTS (
SELECT 1
FROM candidate_hidden_organizations AS hidden
WHERE
hidden.user_id = candidate_publications.user_id
AND hidden.organization_id = $3
)
FOR SHARE OF candidate_publications, consent_records
`
type LockVisiblePublicationForViewParams struct {
CandidateID pgtype.UUID
ConsentRecordID pgtype.UUID
OrganizationID pgtype.UUID
}
// Lock and recheck one candidate's exact current publication only after the
// active C2 row is share-locked. No row includes unpublished, revoked, stale
// publication, and organization-hidden states.
func (q *Queries) LockVisiblePublicationForView(ctx context.Context, arg LockVisiblePublicationForViewParams) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, lockVisiblePublicationForView, arg.CandidateID, arg.ConsentRecordID, arg.OrganizationID)
var user_id pgtype.UUID
err := row.Scan(&user_id)
return user_id, err
}
const readCandidateViewSourceForPreview = `-- name: ReadCandidateViewSourceForPreview :many
SELECT
effective.user_id,
effective.fields,
claim.kind,
claim.ordinal,
CASE
WHEN claim.kind = 'experience' THEN jsonb_build_object(
'employer_name', NULL::text,
'specialization', claim.value ->> 'specialization',
'started_on', claim.value ->> 'started_on',
'ended_on', claim.value -> 'ended_on',
'summary', NULL::text
)
ELSE claim.value
END AS safe_value,
claim.status,
claim.origin,
claim.trust_level,
claim.extraction_version,
claim.confirmed_at,
COALESCE(questionnaire.work_formats, '{}'::text[]) AS work_formats,
COALESCE(
(
SELECT jsonb_agg(
jsonb_build_object(
'first_index', overlap.first_index,
'second_index', overlap.second_index,
'first_period', jsonb_build_object(
'started_on', overlap.first_started_on,
'ended_on', overlap.first_ended_on
),
'second_period', jsonb_build_object(
'started_on', overlap.second_started_on,
'ended_on', overlap.second_ended_on
)
) ORDER BY overlap.first_index, overlap.second_index
)::text
FROM candidate_profile_overlap_confirmations AS overlap
WHERE overlap.user_id = effective.user_id
),
'[]'::text
) AS parallel_period_acknowledgements,
COALESCE(
(
SELECT jsonb_agg(
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
ORDER BY category.specialization
)::text
FROM candidate_assessment_categories AS category
WHERE category.candidate_id = effective.user_id
),
'[]'::text
) AS confirmed_categories
FROM candidate_effective_publications AS effective
LEFT JOIN candidate_profile_claims AS claim
ON claim.user_id = effective.user_id
AND claim.kind IN ('stack', 'role', 'experience')
LEFT JOIN candidate_questionnaires AS questionnaire
ON questionnaire.user_id = effective.user_id
WHERE effective.user_id = $1
ORDER BY effective.user_id, claim.kind, claim.ordinal
`
type ReadCandidateViewSourceForPreviewRow struct {
UserID pgtype.UUID
Fields []string
Kind pgtype.Text
Ordinal pgtype.Int2
SafeValue interface{}
Status pgtype.Text
Origin pgtype.Text
TrustLevel pgtype.Int2
ExtractionVersion pgtype.Text
ConfirmedAt pgtype.Timestamptz
WorkFormats []string
ParallelPeriodAcknowledgements interface{}
ConfirmedCategories interface{}
}
// Read the candidate's current private projection inputs after the caller
// locks its active C2 and publication. It selects only fields allowed in the
// anonymous-card projection and is never used for employer visibility.
func (q *Queries) ReadCandidateViewSourceForPreview(ctx context.Context, candidateID pgtype.UUID) ([]ReadCandidateViewSourceForPreviewRow, error) {
rows, err := q.db.Query(ctx, readCandidateViewSourceForPreview, candidateID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ReadCandidateViewSourceForPreviewRow
for rows.Next() {
var i ReadCandidateViewSourceForPreviewRow
if err := rows.Scan(
&i.UserID,
&i.Fields,
&i.Kind,
&i.Ordinal,
&i.SafeValue,
&i.Status,
&i.Origin,
&i.TrustLevel,
&i.ExtractionVersion,
&i.ConfirmedAt,
&i.WorkFormats,
&i.ParallelPeriodAcknowledgements,
&i.ConfirmedCategories,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}