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:
@@ -0,0 +1,41 @@
|
||||
CREATE TABLE "position_skills" (
|
||||
"position_id" text NOT NULL,
|
||||
"skill_id" text NOT NULL,
|
||||
"weight" integer DEFAULT 1 NOT NULL,
|
||||
"required_level" text,
|
||||
"is_core" boolean DEFAULT false NOT NULL,
|
||||
CONSTRAINT "position_skills_pk" PRIMARY KEY("position_id","skill_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "skills" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"slug" text NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"category_id" text NOT NULL,
|
||||
"technology_id" text,
|
||||
"function_id" text,
|
||||
"dedupe_key" text NOT NULL,
|
||||
"description" text,
|
||||
"mentor_min_level" text DEFAULT 'expert' NOT NULL,
|
||||
"stale_after_days" integer DEFAULT 120 NOT NULL,
|
||||
"recert_required" boolean DEFAULT false NOT NULL,
|
||||
"sort_order" integer DEFAULT 0 NOT NULL,
|
||||
"active" boolean DEFAULT true NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone,
|
||||
CONSTRAINT "skills_slug_unique" UNIQUE("slug"),
|
||||
CONSTRAINT "skills_dedupe_key_unique" UNIQUE("dedupe_key")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "roles" ADD COLUMN "active" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "roles" ADD COLUMN "updated_at" timestamp with time zone;--> statement-breakpoint
|
||||
ALTER TABLE "position_skills" ADD CONSTRAINT "position_skills_position_id_roles_id_fk" FOREIGN KEY ("position_id") REFERENCES "public"."roles"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "position_skills" ADD CONSTRAINT "position_skills_skill_id_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."skills"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "skills" ADD CONSTRAINT "skills_category_id_skill_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."skill_categories"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "skills" ADD CONSTRAINT "skills_technology_id_technologies_id_fk" FOREIGN KEY ("technology_id") REFERENCES "public"."technologies"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "skills" ADD CONSTRAINT "skills_function_id_functions_id_fk" FOREIGN KEY ("function_id") REFERENCES "public"."functions"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "position_skills_skill_idx" ON "position_skills" USING btree ("skill_id");--> statement-breakpoint
|
||||
CREATE INDEX "skills_slug_idx" ON "skills" USING btree ("slug");--> statement-breakpoint
|
||||
CREATE INDEX "skills_active_idx" ON "skills" USING btree ("active");--> statement-breakpoint
|
||||
CREATE INDEX "skills_category_idx" ON "skills" USING btree ("category_id");--> statement-breakpoint
|
||||
CREATE INDEX "roles_active_idx" ON "roles" USING btree ("active");
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,13 @@
|
||||
"when": 1794961261600,
|
||||
"tag": "0003_whole_crystal",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "7",
|
||||
"when": 1794964903255,
|
||||
"tag": "0004_hesitant_ezekiel",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user