B4 — Positions + skills + requirements editor

Positions (schedulable seats) CRUD + requirements editor. Governing rule:
a position with no is_core skill refuses to save as publishable.
Schema (src/db/schema.ts):
- skills table (B4 prerequisite of position_skills): id, slug (unique),
  name, category_id/technology_id/function_id FKs, dedupe_key
  (category|technology|function, NULLs -> ''), mentor_min_level (default
  'expert'), stale_after_days (default 120), recert_required, sort_order,
  active, created_at, updated_at. All FKs ON DELETE RESTRICT.
- position_skills join: position_id, skill_id, weight, required_level,
  is_core; PK (position_id, skill_id).
- roles (positions) gained active (default true) + updated_at for
  soft-delete/pickers/audit.
Data layer (src/db/positions.ts): list/create/update/deactivate for
positions and skills; getPositionSkills (skills merged into
position_skills in JS); setPositionSkills (replaces the whole set);
dedupeKey() helper.
Domain (src/domain/positions.ts + .test.ts): pure publishability rule —
isPublishable(skills) = has >=1 is_core skill. 8 tests named after the
rule.
API:
- src/app/api/dev/skills/route.ts — GET/POST/PATCH (slug + dedupe_key
  generated at create; slug frozen on update).
- src/app/api/dev/positions/route.ts — GET/POST/PATCH (rename/edit or
  deactivate via active:false).
- src/app/api/dev/positions/requirements/route.ts — GET (list a
  position's requirements) + POST (set requirements; enforces the
  publishability gate: published:true with no core skill -> 400).
Migration drizzle/0004_hesitant_ezekiel.sql.
Verification: typecheck ✓ lint ✓ test ✓ (44, +8) build ✓ db:migrate ✓;
runtime smoke /tmp/b4.sh (24 checks) — publish-with-core 200,
publish-without-core 400, weight-out-of-range 400, rename slug frozen,
deactivate hides from picker but row persists.
Decisions: skills table is a B4 prerequisite; requirements editor takes
positionId in the body (Next 15.5.29 rejects an explicitly-typed
{ params: { id } } route-handler second arg); publishability gate lives
in the domain and is enforced in the route; join resolved in JS
(drizzle 0.45.4 exports no join).
This commit is contained in:
Tiel Coder
2026-11-18 01:34:24 +00:00
parent 9f7a65b136
commit 5c789f63cc
11 changed files with 2821 additions and 6 deletions
+40 -1
View File
@@ -228,4 +228,43 @@ Build log for Media Team Hub. One unit per commit, top to bottom. Append after e
- **`purchasedOn` uses `mode: "string"`.** The API passes an ISO date string; a `mode: "date"` column expects a `Date` object (TS2769).
- **No catalog seed yet.** Per ARCHITECTURE, the only seeded artifact is `seed/catalog.json` (loaded on first boot) — delivered in a later unit. The four tables start empty; this unit is the data layer other units consume.
**Next: B4 — positions (schedulable seats) + skills.****
**Next: B4 — positions (schedulable seats) + skills.**
---
## B4 — Positions + skills + requirements editor — DONE 2026-11-18
**Scope (from BUILD-PLAN.md):** positions (schedulable seats) CRUD + requirements editor (skill, weight, required level, core). Governing rule under test: **a position with no `is_core` skill refuses to save as publishable.** ARCHITECTURE §4.3 — positions deactivate only, slugs frozen, FKs `ON DELETE RESTRICT`.
**Delivered:**
- `src/db/schema.ts` — two new tables:
- **`skills`** (B4 prerequisite of `position_skills`): `id, slug (unique), name, category_id (FK), technology_id (FK), function_id (FK), dedupe_key (unique), description, mentor_min_level (default 'expert'), stale_after_days (default 120), recert_required, sort_order, active, created_at, updated_at`. `dedupe_key = category|technology|function` (NULLs → ""). All FKs `ON DELETE RESTRICT`.
- **`position_skills`** (join): `position_id (FK), skill_id (FK), weight, required_level, is_core`, PK `(position_id, skill_id)`.
- `roles` (positions) gained `active` (default true) + `updated_at` for soft-delete/pickers/audit.
- `src/db/positions.ts` — data layer: `listPositions`, `createPosition`, `updatePosition`, `deactivatePosition`, `listSkills`, `createSkill`, `updateSkill`, `deactivateSkill`, `getPositionSkills` (skills joined into position_skills in JS), `setPositionSkills` (replaces the whole set), `dedupeKey()` helper.
- `src/domain/positions.ts` — pure publishability rule: `isPublishable(skills)` = has ≥1 `is_core` skill.
- `src/domain/positions.test.ts` — 8 tests named after the rule (no-core publish refused; no-core unpublished allowed; weight range).
- `src/app/api/dev/skills/route.ts` — GET (list, `?active=`), POST (create, slug+dedupe_key generated), PATCH (rename/edit or deactivate).
- `src/app/api/dev/positions/route.ts` — GET (list), POST (create), PATCH (rename/edit or deactivate).
- `src/app/api/dev/positions/requirements/route.ts` — GET (list a position's requirements), POST (set requirements; enforces the publishability gate).
- Migration `drizzle/0004_hesitant_ezekiel.sql`.
**Verification (all exit 0):**
- `pnpm typecheck` ✓ · `pnpm lint` ✓ · `pnpm test` ✓ (**44** total, +8 for B4 domain) · `pnpm build` ✓
- `pnpm db:migrate` ✓ → `skills`, `position_skills`, `roles.active`/`updated_at` present on :5433
- Runtime smoke against live app + Postgres on :5433 (**24 checks**, `/tmp/b4.sh`):
- seed category → skill → position (slugs + dedupe_key generated) ✓
- requirements round-trip (empty → 0) ✓
- publish **with** a core skill → 200 (core/weight/name joined) ✓
- publish **without** any core skill → **400** (the B4 rule); same set as `published:false` → 200 ✓
- weight out of range (9) → 400 ✓
- rename → slug frozen ✓; deactivate → hidden from `?active=true` picker, row persists in DB ✓
**Decisions:**
- **Skills table is a B4 prerequisite.** `position_skills` needs `skills` to exist, so B4 builds the `skills` table (composed from the four catalog tables) up front. The name-composition UI is C1; this unit only creates skills with an explicit name.
- **Requirements editor takes `positionId` in the body, not a URL param.** Next 15.5.29's route-handler context validation rejects an explicitly-typed `{ params: { id: string } }` second argument (it expects `Promise<any>` for the async-params feature). Body-based stays consistent with the catalog route and avoids the dynamic-route context typing rabbit hole.
- **Publishability gate in the domain, enforced in the route.** The pure rule lives in `src/domain/positions.ts`; the route calls it and returns 400 when a `published:true` payload has no core skill — so the rule and the code cannot drift.
- **`join` resolved in JS.** Drizzle 0.45.4 exports no `join` from `drizzle-orm` or `drizzle-orm/pg-core`. `getPositionSkills` fetches `position_skills` then the referenced `skills` and merges in JS.
- **No skill/position seed yet.** Per ARCHITECTURE the only seeded artifact is `seed/catalog.json` (later unit). Tables start empty; this unit is the data layer + API other units consume.
**Next: B5 — user_skills + verified levels (who has what, and at what level).****