Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/platform/database/dbgen/sourcing.sql.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 39df94f92b2a33f852481fe1954dabed841524bb |
| Branch | w0-aedt-compliance |
| Path or archive member | internal/platform/database/dbgen/sourcing.sql.go |
| Original SHA-256 | 8ffe5ac398496622efacd269a40e0a1900b75ec4e316d1a861be7d2a029496c8 |
| Git blob SHA | 8b76ecfd9956aa5bbbce6f3faa6d1c83f2022695 |
| Reading-copy SHA-256 | 8ffe5ac398496622efacd269a40e0a1900b75ec4e316d1a861be7d2a029496c8 |
Recovered source transcript
Download complete source text ↓222 lines · 6.4 KB
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: sourcing.sql
package dbgen
import (
"context"
"time"
"github.com/google/uuid"
)
const deleteExternalCandidate = `-- name: DeleteExternalCandidate :execrows
DELETE FROM candidates WHERE id = $1 AND source = 'external'
`
func (q *Queries) DeleteExternalCandidate(ctx context.Context, id uuid.UUID) (int64, error) {
result, err := q.db.Exec(ctx, deleteExternalCandidate, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const deleteSlateMembersForCandidate = `-- name: DeleteSlateMembersForCandidate :exec
DELETE FROM slate_members WHERE candidate_id = $1
`
// Erasure must also remove slate placements of the sourced person; slate_members has no ON DELETE rule
// so the candidate delete would otherwise fail. RLS scopes this to the caller's org.
func (q *Queries) DeleteSlateMembersForCandidate(ctx context.Context, candidateID uuid.UUID) error {
_, err := q.db.Exec(ctx, deleteSlateMembersForCandidate, candidateID)
return err
}
const detachSourcingLog = `-- name: DetachSourcingLog :exec
UPDATE sourcing_log SET candidate_id = NULL WHERE candidate_id = $1
`
func (q *Queries) DetachSourcingLog(ctx context.Context, candidateID *uuid.UUID) error {
_, err := q.db.Exec(ctx, detachSourcingLog, candidateID)
return err
}
const insertSourcingLog = `-- name: InsertSourcingLog :exec
INSERT INTO sourcing_log (organization_id, candidate_id, external_id, source, provider, query, legal_basis)
VALUES ($1, $2, $3, $4, $5, $6, $7)
`
type InsertSourcingLogParams struct {
OrganizationID uuid.UUID `json:"organization_id"`
CandidateID *uuid.UUID `json:"candidate_id"`
ExternalID string `json:"external_id"`
Source string `json:"source"`
Provider string `json:"provider"`
Query string `json:"query"`
LegalBasis string `json:"legal_basis"`
}
func (q *Queries) InsertSourcingLog(ctx context.Context, arg InsertSourcingLogParams) error {
_, err := q.db.Exec(ctx, insertSourcingLog,
arg.OrganizationID,
arg.CandidateID,
arg.ExternalID,
arg.Source,
arg.Provider,
arg.Query,
arg.LegalBasis,
)
return err
}
const listExternalCandidates = `-- name: ListExternalCandidates :many
SELECT id, full_name, email, headline, location, years_experience, available, external_id, created_at
FROM candidates
WHERE source = 'external' AND deleted_at IS NULL
ORDER BY created_at DESC
LIMIT $1
`
type ListExternalCandidatesRow struct {
ID uuid.UUID `json:"id"`
FullName string `json:"full_name"`
Email *string `json:"email"`
Headline *string `json:"headline"`
Location *string `json:"location"`
YearsExperience int32 `json:"years_experience"`
Available bool `json:"available"`
ExternalID *string `json:"external_id"`
CreatedAt time.Time `json:"created_at"`
}
func (q *Queries) ListExternalCandidates(ctx context.Context, limit int32) ([]ListExternalCandidatesRow, error) {
rows, err := q.db.Query(ctx, listExternalCandidates, limit)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListExternalCandidatesRow{}
for rows.Next() {
var i ListExternalCandidatesRow
if err := rows.Scan(
&i.ID,
&i.FullName,
&i.Email,
&i.Headline,
&i.Location,
&i.YearsExperience,
&i.Available,
&i.ExternalID,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSourcingLog = `-- name: ListSourcingLog :many
SELECT id, candidate_id, external_id, source, provider, query, legal_basis, collected_at
FROM sourcing_log
ORDER BY collected_at DESC
LIMIT $1
`
type ListSourcingLogRow struct {
ID uuid.UUID `json:"id"`
CandidateID *uuid.UUID `json:"candidate_id"`
ExternalID string `json:"external_id"`
Source string `json:"source"`
Provider string `json:"provider"`
Query string `json:"query"`
LegalBasis string `json:"legal_basis"`
CollectedAt time.Time `json:"collected_at"`
}
func (q *Queries) ListSourcingLog(ctx context.Context, limit int32) ([]ListSourcingLogRow, error) {
rows, err := q.db.Query(ctx, listSourcingLog, limit)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListSourcingLogRow{}
for rows.Next() {
var i ListSourcingLogRow
if err := rows.Scan(
&i.ID,
&i.CandidateID,
&i.ExternalID,
&i.Source,
&i.Provider,
&i.Query,
&i.LegalBasis,
&i.CollectedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const upsertExternalCandidate = `-- name: UpsertExternalCandidate :one
INSERT INTO candidates (
organization_id, full_name, email, headline,
clearance_level, clearance_poly, clearance_status,
years_experience, location, remote, relocatable, available, source, external_id
) VALUES (
$1, $2, $3, $4,
'unknown', 'none', 'unknown',
$5, $6, $7, false, true, 'external', $8
)
ON CONFLICT (organization_id, external_id) WHERE external_id IS NOT NULL DO UPDATE SET
full_name = EXCLUDED.full_name,
email = EXCLUDED.email,
headline = EXCLUDED.headline,
years_experience = EXCLUDED.years_experience,
location = EXCLUDED.location,
remote = EXCLUDED.remote,
updated_at = now()
RETURNING id
`
type UpsertExternalCandidateParams struct {
OrganizationID uuid.UUID `json:"organization_id"`
FullName string `json:"full_name"`
Email *string `json:"email"`
Headline *string `json:"headline"`
YearsExperience int32 `json:"years_experience"`
Location *string `json:"location"`
Remote bool `json:"remote"`
ExternalID *string `json:"external_id"`
}
// External candidate sourcing. The import command (cmd/import-candidates) writes as the migrator role
// with an explicit organization_id; the delete path runs as the app role inside a tenant tx (RLS).
func (q *Queries) UpsertExternalCandidate(ctx context.Context, arg UpsertExternalCandidateParams) (uuid.UUID, error) {
row := q.db.QueryRow(ctx, upsertExternalCandidate,
arg.OrganizationID,
arg.FullName,
arg.Email,
arg.Headline,
arg.YearsExperience,
arg.Location,
arg.Remote,
arg.ExternalID,
)
var id uuid.UUID
err := row.Scan(&id)
return id, err
}