ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / internal/platform/database/dbgen/mission_tags.sql.go

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / internal/platform/database/dbgen/mission_tags.sql.go
DateNot specified in source
RepositoryJanady13/missionmatch
Revision2178e7298d0e5d9af83afa12402fd587f0ba6ed8
Branchfeature/aioe-upgrade
Path or archive memberinternal/platform/database/dbgen/mission_tags.sql.go
Original SHA-256e0e7f00113640a8d22e99024a2a1dc7a9eafff5c3babac58a2a9db1511bd0363
Git blob SHA74f2bbdbd8d6ed643c9312aedd87a51df8cf6949
Reading-copy SHA-256e0e7f00113640a8d22e99024a2a1dc7a9eafff5c3babac58a2a9db1511bd0363

Original source ↗

Recovered source transcript

// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: mission_tags.sql package dbgen import ( "context" "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" "github.com/shopspring/decimal" ) const listAllOrganizationIDs = `-- name: ListAllOrganizationIDs :many SELECT id FROM organizations ORDER BY id ` // Every organization id, ordered by id for a byte stable backfill iteration. Read by the BYPASSRLS // migrator role in the tag-missions backfill ONLY to enumerate which tenant contexts to run; the tag // writes themselves run as the application role inside each org's RunInTenantTx, never the migrator bypass. func (q *Queries) ListAllOrganizationIDs(ctx context.Context) ([]uuid.UUID, error) { rows, err := q.db.Query(ctx, listAllOrganizationIDs) if err != nil { return nil, err } defer rows.Close() items := []uuid.UUID{} for rows.Next() { var id uuid.UUID if err := rows.Scan(&id); err != nil { return nil, err } items = append(items, id) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listAwardsForClassify = `-- name: ListAwardsForClassify :many SELECT generated_internal_id AS record_id, description, naics_description, naics_code FROM usaspending_awards ORDER BY generated_internal_id ` type ListAwardsForClassifyRow struct { RecordID string `json:"record_id"` Description string `json:"description"` NaicsDescription string `json:"naics_description"` NaicsCode string `json:"naics_code"` } // Minimal projection of the global usaspending_awards catalog for the missionclass sync pass: the // generated_internal_id (the record_id the tag and incumbent role tables key on), plus the description, // naics_description, and naics_code the classifier reads. Ordered by generated_internal_id for byte // stable iteration. func (q *Queries) ListAwardsForClassify(ctx context.Context) ([]ListAwardsForClassifyRow, error) { rows, err := q.db.Query(ctx, listAwardsForClassify) if err != nil { return nil, err } defer rows.Close() items := []ListAwardsForClassifyRow{} for rows.Next() { var i ListAwardsForClassifyRow if err := rows.Scan( &i.RecordID, &i.Description, &i.NaicsDescription, &i.NaicsCode, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listCandidatesByMission = `-- name: ListCandidatesByMission :many SELECT c.id, c.organization_id, c.full_name, c.email, c.headline, c.clearance_level, c.clearance_poly, c.clearance_status, c.clearance_granted_at, c.clearance_expires_at, c.reinvestigation_due_at, c.years_experience, c.location, c.remote, c.relocatable, c.available, c.resume_embedding, c.search_tsv, c.created_at, c.updated_at, c.deleted_at, c.source, c.external_id, c.anonymized_at, c.clearance_provenance, c.clearance_verified_at, c.clearance_compartments, c.source_first_touch, c.source_last_touch, c.source_detail FROM candidates c JOIN candidate_mission_tags t ON t.candidate_id = c.id WHERE c.deleted_at IS NULL AND t.mission_code = $1 ORDER BY c.created_at DESC, c.id LIMIT $2 ` type ListCandidatesByMissionParams struct { MissionCode string `json:"mission_code"` RowLimit int32 `json:"row_limit"` } // Tenant candidates tagged with a given mission code, RLS scoped to the caller's org through the join on // candidate_mission_tags. id is the trailing unique sort key so created_at ties give a total order and // stable LIMIT paging, the AEDT reproducibility mandate. func (q *Queries) ListCandidatesByMission(ctx context.Context, arg ListCandidatesByMissionParams) ([]Candidate, error) { rows, err := q.db.Query(ctx, listCandidatesByMission, arg.MissionCode, arg.RowLimit) if err != nil { return nil, err } defer rows.Close() items := []Candidate{} for rows.Next() { var i Candidate if err := rows.Scan( &i.ID, &i.OrganizationID, &i.FullName, &i.Email, &i.Headline, &i.ClearanceLevel, &i.ClearancePoly, &i.ClearanceStatus, &i.ClearanceGrantedAt, &i.ClearanceExpiresAt, &i.ReinvestigationDueAt, &i.YearsExperience, &i.Location, &i.Remote, &i.Relocatable, &i.Available, &i.ResumeEmbedding, &i.SearchTsv, &i.CreatedAt, &i.UpdatedAt, &i.DeletedAt, &i.Source, &i.ExternalID, &i.AnonymizedAt, &i.ClearanceProvenance, &i.ClearanceVerifiedAt, &i.ClearanceCompartments, &i.SourceFirstTouch, &i.SourceLastTouch, &i.SourceDetail, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listCandidatesForMissionTagging = `-- name: ListCandidatesForMissionTagging :many SELECT c.id AS candidate_id, COALESCE(c.headline, '')::text AS headline, COALESCE(string_agg(s.name, ' ' ORDER BY s.name), '')::text AS skill_text FROM candidates c LEFT JOIN candidate_skills cs ON cs.candidate_id = c.id LEFT JOIN skills s ON s.id = cs.skill_id WHERE c.deleted_at IS NULL AND c.anonymized_at IS NULL GROUP BY c.id, c.headline ORDER BY c.id ` type ListCandidatesForMissionTaggingRow struct { CandidateID uuid.UUID `json:"candidate_id"` Headline string `json:"headline"` SkillText string `json:"skill_text"` } // Tenant projection the Phase 5a tagging service classifies: each live candidate id, its headline, and the // candidate's skill names joined by single spaces into one text blob. RLS scopes the read to the caller's // org through the candidates row, and the LEFT JOIN keeps a candidate with no skills (the headline still // classifies). headline is coerced to empty text so a NULL never aborts the aggregation. Ordered by id so // the pass iterates byte stably and a re run is reproducible, the AEDT mandate. func (q *Queries) ListCandidatesForMissionTagging(ctx context.Context) ([]ListCandidatesForMissionTaggingRow, error) { rows, err := q.db.Query(ctx, listCandidatesForMissionTagging) if err != nil { return nil, err } defer rows.Close() items := []ListCandidatesForMissionTaggingRow{} for rows.Next() { var i ListCandidatesForMissionTaggingRow if err := rows.Scan(&i.CandidateID, &i.Headline, &i.SkillText); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listIncumbentRolesByRecompete = `-- name: ListIncumbentRolesByRecompete :many SELECT a.generated_internal_id AS record_id, a.recipient_name AS recipient_name, a.awarding_agency AS awarding_agency, a.naics_code AS naics_code, a.award_amount AS award_amount, a.pop_end_date AS pop_end_date, r.labor_category AS labor_category, r.role_count AS role_count, r.evidence AS evidence FROM award_incumbent_roles r JOIN usaspending_awards a ON a.generated_internal_id = r.record_id WHERE r.record_table = 'usaspending_awards' AND ($1::date IS NULL OR a.pop_end_date <= $1::date) ORDER BY a.pop_end_date ASC NULLS LAST, a.generated_internal_id, r.labor_category LIMIT $2::int ` type ListIncumbentRolesByRecompeteParams struct { PopEndBefore pgtype.Date `json:"pop_end_before"` RowLimit int32 `json:"row_limit"` } type ListIncumbentRolesByRecompeteRow struct { RecordID string `json:"record_id"` RecipientName string `json:"recipient_name"` AwardingAgency string `json:"awarding_agency"` NaicsCode string `json:"naics_code"` AwardAmount *decimal.Decimal `json:"award_amount"` PopEndDate pgtype.Date `json:"pop_end_date"` LaborCategory string `json:"labor_category"` RoleCount int32 `json:"role_count"` Evidence string `json:"evidence"` } // Incumbent labor mix mined from award text, joined to its parent USASpending award so each role carries // the award identity (recipient_name, pop_end_date) and its evidence phrase, the traceability the WS7 // acceptance criterion requires. The recompete signal is pop_end_date: awards whose period of performance // is ending are the recompete relevant ones, so rows are ordered by pop_end_date soonest first, then by // the award generated_internal_id and the labor_category as trailing unique tiebreakers for byte stable // output, the AEDT reproducibility mandate. Awards with no pop_end_date sort last. Global reference data, // app SELECT only. The optional pop_end_before bound (NULL means no bound) lets the caller scope to a // recompete window without changing the default which returns the soonest ending awards first. func (q *Queries) ListIncumbentRolesByRecompete(ctx context.Context, arg ListIncumbentRolesByRecompeteParams) ([]ListIncumbentRolesByRecompeteRow, error) { rows, err := q.db.Query(ctx, listIncumbentRolesByRecompete, arg.PopEndBefore, arg.RowLimit) if err != nil { return nil, err } defer rows.Close() items := []ListIncumbentRolesByRecompeteRow{} for rows.Next() { var i ListIncumbentRolesByRecompeteRow if err := rows.Scan( &i.RecordID, &i.RecipientName, &i.AwardingAgency, &i.NaicsCode, &i.AwardAmount, &i.PopEndDate, &i.LaborCategory, &i.RoleCount, &i.Evidence, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listMissionTagsForRecord = `-- name: ListMissionTagsForRecord :many SELECT record_table, record_id, mission_code, mechanism, evidence, confidence, classified_at FROM federal_mission_tags WHERE record_table = $1 AND record_id = $2 ORDER BY mission_code, record_id ` type ListMissionTagsForRecordParams struct { RecordTable string `json:"record_table"` RecordID string `json:"record_id"` } // All mission tags for one global record, ordered by mission code with the record id as a trailing unique // tiebreaker so the output is byte stable for fixed inputs, the AEDT reproducibility mandate. func (q *Queries) ListMissionTagsForRecord(ctx context.Context, arg ListMissionTagsForRecordParams) ([]FederalMissionTag, error) { rows, err := q.db.Query(ctx, listMissionTagsForRecord, arg.RecordTable, arg.RecordID) if err != nil { return nil, err } defer rows.Close() items := []FederalMissionTag{} for rows.Next() { var i FederalMissionTag if err := rows.Scan( &i.RecordTable, &i.RecordID, &i.MissionCode, &i.Mechanism, &i.Evidence, &i.Confidence, &i.ClassifiedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listOpportunityRecordsForClassify = `-- name: ListOpportunityRecordsForClassify :many SELECT id::text AS record_id, title, psc, naics FROM opportunity_records ORDER BY id ` type ListOpportunityRecordsForClassifyRow struct { RecordID string `json:"record_id"` Title string `json:"title"` Psc string `json:"psc"` Naics string `json:"naics"` } // Minimal projection of the global opportunity_records catalog for the missionclass sync pass: the id // carried as text (the record_id federal_mission_tags keys on), plus the title, psc, and naics the // deterministic classifier reads. Ordered by id so the pass iterates byte stably and a re run is // reproducible, the AEDT mandate. Migrator role reads the global catalog directly. func (q *Queries) ListOpportunityRecordsForClassify(ctx context.Context) ([]ListOpportunityRecordsForClassifyRow, error) { rows, err := q.db.Query(ctx, listOpportunityRecordsForClassify) if err != nil { return nil, err } defer rows.Close() items := []ListOpportunityRecordsForClassifyRow{} for rows.Next() { var i ListOpportunityRecordsForClassifyRow if err := rows.Scan( &i.RecordID, &i.Title, &i.Psc, &i.Naics, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listRequirementsForMissionTagging = `-- name: ListRequirementsForMissionTagging :many SELECT r.id AS requirement_id, r.title::text AS title, COALESCE(r.labor_category, '')::text AS labor_category, COALESCE(string_agg(s.name, ' ' ORDER BY s.name), '')::text AS skill_text FROM requirements r LEFT JOIN required_skills rs ON rs.requirement_id = r.id LEFT JOIN skills s ON s.id = rs.skill_id WHERE r.deleted_at IS NULL GROUP BY r.id, r.title, r.labor_category ORDER BY r.id ` type ListRequirementsForMissionTaggingRow struct { RequirementID uuid.UUID `json:"requirement_id"` Title string `json:"title"` LaborCategory string `json:"labor_category"` SkillText string `json:"skill_text"` } // Tenant projection the Phase 5a tagging service classifies for requirements: each live requirement id, its // title, its labor_category (coerced to empty when NULL), and the required skill names joined by single // spaces. RLS scopes the read to the caller's org; the LEFT JOIN keeps a requirement with no required // skills (the title and labor category still classify). Ordered by id for byte stable, reproducible // iteration, the AEDT mandate. func (q *Queries) ListRequirementsForMissionTagging(ctx context.Context) ([]ListRequirementsForMissionTaggingRow, error) { rows, err := q.db.Query(ctx, listRequirementsForMissionTagging) if err != nil { return nil, err } defer rows.Close() items := []ListRequirementsForMissionTaggingRow{} for rows.Next() { var i ListRequirementsForMissionTaggingRow if err := rows.Scan( &i.RequirementID, &i.Title, &i.LaborCategory, &i.SkillText, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listSamForClassify = `-- name: ListSamForClassify :many SELECT notice_id AS record_id, description_url, resource_links FROM sam_opportunities ORDER BY notice_id ` type ListSamForClassifyRow struct { RecordID string `json:"record_id"` DescriptionUrl string `json:"description_url"` ResourceLinks []byte `json:"resource_links"` } // Minimal projection of the cached sam_opportunities catalog for the missionclass sync pass: the // notice_id (the record_id award_incumbent_roles keys on for a SAM notice), plus the description_url and // the resource_links the attachment fetcher needs to mine the incumbent labor mix. Ordered by notice_id // for byte stable iteration. func (q *Queries) ListSamForClassify(ctx context.Context) ([]ListSamForClassifyRow, error) { rows, err := q.db.Query(ctx, listSamForClassify) if err != nil { return nil, err } defer rows.Close() items := []ListSamForClassifyRow{} for rows.Next() { var i ListSamForClassifyRow if err := rows.Scan(&i.RecordID, &i.DescriptionUrl, &i.ResourceLinks); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const missionAliasPairs = `-- name: MissionAliasPairs :many SELECT a.alias_text AS phrase, m.code AS code FROM skill_aliases a JOIN skills s ON s.id = a.skill_id AND s.category = 'mission_area' JOIN mission_areas m ON m.spine_term = s.name UNION SELECT s.name AS phrase, m.code AS code FROM skills s JOIN mission_areas m ON m.spine_term = s.name WHERE s.category = 'mission_area' ORDER BY phrase, code ` type MissionAliasPairsRow struct { Phrase string `json:"phrase"` Code string `json:"code"` } // (phrase, code) pairs that seed the missionclass AliasIndex from real rows. Two unioned sources: every // curated alias whose target skill is a category 'mission_area' skill, and every mission_area skill name // itself. The skill name to code link is mission_areas.spine_term = skills.name, because the mission_area // skills were promoted from the mission_spine terms the mission_areas rows carry. Ordered by phrase then // code for a deterministic build. Global reference data, read by the migrator role. func (q *Queries) MissionAliasPairs(ctx context.Context) ([]MissionAliasPairsRow, error) { rows, err := q.db.Query(ctx, missionAliasPairs) if err != nil { return nil, err } defer rows.Close() items := []MissionAliasPairsRow{} for rows.Next() { var i MissionAliasPairsRow if err := rows.Scan(&i.Phrase, &i.Code); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const upsertAwardIncumbentRole = `-- name: UpsertAwardIncumbentRole :exec INSERT INTO award_incumbent_roles (record_table, record_id, labor_category, role_count, evidence) VALUES ( $1, $2, $3, $4, $5 ) ON CONFLICT (record_table, record_id, labor_category) DO UPDATE SET role_count = EXCLUDED.role_count, evidence = EXCLUDED.evidence, classified_at = now() ` type UpsertAwardIncumbentRoleParams struct { RecordTable string `json:"record_table"` RecordID string `json:"record_id"` LaborCategory string `json:"labor_category"` RoleCount int32 `json:"role_count"` Evidence string `json:"evidence"` } // Idempotent write of an incumbent labor mix row mined from award and solicitation text. ON CONFLICT DO // UPDATE so a re run refreshes the count and evidence for the same record and labor category. func (q *Queries) UpsertAwardIncumbentRole(ctx context.Context, arg UpsertAwardIncumbentRoleParams) error { _, err := q.db.Exec(ctx, upsertAwardIncumbentRole, arg.RecordTable, arg.RecordID, arg.LaborCategory, arg.RoleCount, arg.Evidence, ) return err } const upsertCandidateMissionTag = `-- name: UpsertCandidateMissionTag :exec INSERT INTO candidate_mission_tags (organization_id, candidate_id, mission_code, mechanism, evidence) VALUES ( $1, $2, $3, $4, $5 ) ON CONFLICT (candidate_id, mission_code) DO UPDATE SET mechanism = EXCLUDED.mechanism, evidence = EXCLUDED.evidence ` type UpsertCandidateMissionTagParams struct { OrganizationID uuid.UUID `json:"organization_id"` CandidateID uuid.UUID `json:"candidate_id"` MissionCode string `json:"mission_code"` Mechanism string `json:"mechanism"` Evidence string `json:"evidence"` } // Idempotent write of a tenant candidate mission tag. RLS scopes the write to the caller's org and the // composite FK guarantees the candidate belongs to that org. ON CONFLICT DO UPDATE keeps the sync pass // repeatable, refreshing the mechanism and evidence for an existing candidate and mission code pair. func (q *Queries) UpsertCandidateMissionTag(ctx context.Context, arg UpsertCandidateMissionTagParams) error { _, err := q.db.Exec(ctx, upsertCandidateMissionTag, arg.OrganizationID, arg.CandidateID, arg.MissionCode, arg.Mechanism, arg.Evidence, ) return err } const upsertFederalMissionTag = `-- name: UpsertFederalMissionTag :exec INSERT INTO federal_mission_tags (record_table, record_id, mission_code, mechanism, evidence, confidence) VALUES ( $1, $2, $3, $4, $5, $6 ) ON CONFLICT (record_table, record_id, mission_code) DO UPDATE SET mechanism = EXCLUDED.mechanism, evidence = EXCLUDED.evidence, confidence = EXCLUDED.confidence, classified_at = now() ` type UpsertFederalMissionTagParams struct { RecordTable string `json:"record_table"` RecordID string `json:"record_id"` MissionCode string `json:"mission_code"` Mechanism string `json:"mechanism"` Evidence string `json:"evidence"` Confidence decimal.Decimal `json:"confidence"` } // Idempotent write of a global mission tag from the classification sync pass. ON CONFLICT DO UPDATE so a // re run with the same record and mission code refreshes the mechanism, evidence, and confidence rather // than erroring, which keeps the sync pass safely repeatable. Migrator owned, app SELECT only. func (q *Queries) UpsertFederalMissionTag(ctx context.Context, arg UpsertFederalMissionTagParams) error { _, err := q.db.Exec(ctx, upsertFederalMissionTag, arg.RecordTable, arg.RecordID, arg.MissionCode, arg.Mechanism, arg.Evidence, arg.Confidence, ) return err } const upsertRequirementMissionTag = `-- name: UpsertRequirementMissionTag :exec INSERT INTO requirement_mission_tags (organization_id, requirement_id, mission_code, mechanism, evidence) VALUES ( $1, $2, $3, $4, $5 ) ON CONFLICT (requirement_id, mission_code) DO UPDATE SET mechanism = EXCLUDED.mechanism, evidence = EXCLUDED.evidence ` type UpsertRequirementMissionTagParams struct { OrganizationID uuid.UUID `json:"organization_id"` RequirementID uuid.UUID `json:"requirement_id"` MissionCode string `json:"mission_code"` Mechanism string `json:"mechanism"` Evidence string `json:"evidence"` } // Idempotent write of a tenant requirement mission tag, same isolation guarantees as the candidate path. func (q *Queries) UpsertRequirementMissionTag(ctx context.Context, arg UpsertRequirementMissionTagParams) error { _, err := q.db.Exec(ctx, upsertRequirementMissionTag, arg.OrganizationID, arg.RequirementID, arg.MissionCode, arg.Mechanism, arg.Evidence, ) return err }

Search equations, builds, manuscript text, and recovered sources.