676751c489
Adds the growth_goals table (ARCHITECTURE §4.3, §5.8.6) with its migration and a pure nextGoalStatus() state machine (requested -> mentor_assigned -> in_progress -> achieved, with pause/resume and decline). Adds validateShadowPairing() (src/domain/shadows.ts): a shadow/trainee slot requires a paired mentor in the same instance who is mentor-ready for that exact skill (C5) — rejects a shadow with no paired mentor, enforced by the pure rule and the chk_shadow_paired CHECK constraint on slots. Verified the migration applies and the CHECK rejects a trainee slot without a paired mentor. 22 tests named after each rule.
19 lines
1.3 KiB
SQL
19 lines
1.3 KiB
SQL
CREATE TABLE "growth_goals" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"skill_id" text NOT NULL,
|
|
"target_level" text NOT NULL,
|
|
"target_date" date,
|
|
"status" text DEFAULT 'requested' NOT NULL,
|
|
"mentor_user_id" text,
|
|
"shadow_count" integer DEFAULT 0 NOT NULL,
|
|
"created_by" text,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "growth_goals" ADD CONSTRAINT "growth_goals_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "growth_goals" ADD CONSTRAINT "growth_goals_skill_id_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."skills"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "growth_goals" ADD CONSTRAINT "growth_goals_mentor_user_id_users_id_fk" FOREIGN KEY ("mentor_user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "growth_goals_user_skill_idx" ON "growth_goals" USING btree ("user_id","skill_id");--> statement-breakpoint
|
|
CREATE INDEX "growth_goals_status_idx" ON "growth_goals" USING btree ("status");--> statement-breakpoint
|
|
ALTER TABLE "slots" ADD CONSTRAINT "chk_shadow_paired" CHECK (not is_trainee_slot or paired_with_user_id is not null); |