C3 — Admin skills matrix + verify-level modal

Adds the append-only skill_assessments history and the verify path, so a
level can only move together with the row recording who moved it, from
what level, and the comfort they saw.
This commit is contained in:
Tiel Coder
2026-11-18 04:19:04 +00:00
parent a915e4236c
commit bc1dc91e35
10 changed files with 2793 additions and 4 deletions
+49 -4
View File
@@ -54,6 +54,10 @@ export type SmsConsentSource = (typeof SMS_CONSENT_SOURCES)[number];
export const SKILL_LEVELS = ["none", "observer", "assisted", "qualified", "expert"] as const;
export type SkillLevel = (typeof SKILL_LEVELS)[number];
/** Who produced an assessment row — durable evidence for the audit trail. */
export const ASSESSMENT_KINDS = ["self", "mentor", "admin", "quiz"] as const;
export type AssessmentKind = (typeof ASSESSMENT_KINDS)[number];
const DEFAULT_TIMEZONE = "America/New_York";
/* ------------------------------------------------------------------ users */
@@ -502,14 +506,54 @@ export const userSkills = pgTable(
],
);
/* ------------------------------------------- skill_assessments (C3) */
/**
* Append-only progression history (ARCHITECTURE §4.3). Every movement of a
* volunteer's verified level — up or down — writes exactly one row here, and
* there is deliberately no update or delete path: this table is the audit trail
* that answers "why was this person cleared?". `comfort_at_time` snapshots the
* volunteer's self-reported comfort at the moment of the decision, so a later
* slider move cannot rewrite the context the assessor saw.
*/
export const skillAssessments = pgTable(
"skill_assessments",
{
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
skillId: text("skill_id")
.notNull()
.references(() => skills.id, { onDelete: "cascade" }),
/** Mentor/admin who signed off; null for self or quiz assessments. */
assessorId: text("assessor_id").references(() => users.id, { onDelete: "set null" }),
kind: text("kind", { enum: ASSESSMENT_KINDS }).notNull().default("admin"),
/** The verified level before this assessment (server-owned, never client-set). */
levelFrom: text("level_from", { enum: SKILL_LEVELS }).notNull(),
levelTo: text("level_to", { enum: SKILL_LEVELS }).notNull(),
/** Snapshot of `user_skills.self_comfort` when the assessment was recorded. */
comfortAtTime: integer("comfort_at_time"),
notes: text("notes"),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [
index("skill_assessments_user_created_idx").on(table.userId, table.createdAt),
index("skill_assessments_skill_idx").on(table.skillId),
],
);
/* ------------------------------------------------------------- relations */
/**
* Skills compose from the four catalog tables (B3). `skills`,
* `position_skills` and `user_skills` are intentionally excluded from `relations`:
* their FK columns are themselves part of composite/unique keys, which trips
* Drizzle 0.45.4's `one()` typing (see the B2 note). Queried directly until a
* working eager-load pattern exists — the grid render in I2 pre-resolves the joins.
* `position_skills`, `user_skills` and `skill_assessments` are intentionally
* excluded from `relations`: their FK columns are themselves part of
* composite/unique keys, which trips Drizzle 0.45.4's `one()` typing (see the
* B2 note). Queried directly until a working eager-load pattern exists — the
* grid render in I2 pre-resolves the joins.
*/
export const usersRelations = relations(users, ({ many }) => ({
assignments: many(assignments),
@@ -588,6 +632,7 @@ export const schema = {
skills,
positionSkills,
userSkills,
skillAssessments,
};
export type Schema = typeof schema;