diff --git a/drizzle/0007_funny_zarda.sql b/drizzle/0007_funny_zarda.sql new file mode 100644 index 0000000..41e5920 --- /dev/null +++ b/drizzle/0007_funny_zarda.sql @@ -0,0 +1,19 @@ +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); \ No newline at end of file diff --git a/drizzle/meta/0007_snapshot.json b/drizzle/meta/0007_snapshot.json new file mode 100644 index 0000000..7bb7754 --- /dev/null +++ b/drizzle/meta/0007_snapshot.json @@ -0,0 +1,2307 @@ +{ + "id": "18ddad89-1dac-4d44-8fa2-16bf85fb6f1a", + "prevId": "c4ccc044-4f5d-4977-b199-df91479e1116", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.assignments": { + "name": "assignments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slot_id": { + "name": "slot_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'proposed'" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "assigned_by": { + "name": "assigned_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assigned_at": { + "name": "assigned_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "decline_reason": { + "name": "decline_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "confirmed_via": { + "name": "confirmed_via", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reminder_count": { + "name": "reminder_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "uq_active_assignment": { + "name": "uq_active_assignment", + "columns": [ + { + "expression": "slot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"assignments\".\"status\" IN ('proposed','confirmed','completed')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "assignments_user_idx": { + "name": "assignments_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "assignments_slot_id_slots_id_fk": { + "name": "assignments_slot_id_slots_id_fk", + "tableFrom": "assignments", + "tableTo": "slots", + "columnsFrom": [ + "slot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "assignments_user_id_users_id_fk": { + "name": "assignments_user_id_users_id_fk", + "tableFrom": "assignments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.functions": { + "name": "functions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "functions_slug_idx": { + "name": "functions_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "functions_active_idx": { + "name": "functions_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "functions_category_idx": { + "name": "functions_category_idx", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "functions_category_id_skill_categories_id_fk": { + "name": "functions_category_id_skill_categories_id_fk", + "tableFrom": "functions", + "tableTo": "skill_categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "functions_slug_unique": { + "name": "functions_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.growth_goals": { + "name": "growth_goals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "skill_id": { + "name": "skill_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_level": { + "name": "target_level", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_date": { + "name": "target_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'requested'" + }, + "mentor_user_id": { + "name": "mentor_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shadow_count": { + "name": "shadow_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "growth_goals_user_skill_idx": { + "name": "growth_goals_user_skill_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "skill_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "growth_goals_status_idx": { + "name": "growth_goals_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "growth_goals_user_id_users_id_fk": { + "name": "growth_goals_user_id_users_id_fk", + "tableFrom": "growth_goals", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "growth_goals_skill_id_skills_id_fk": { + "name": "growth_goals_skill_id_skills_id_fk", + "tableFrom": "growth_goals", + "tableTo": "skills", + "columnsFrom": [ + "skill_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "growth_goals_mentor_user_id_users_id_fk": { + "name": "growth_goals_mentor_user_id_users_id_fk", + "tableFrom": "growth_goals", + "tableTo": "users", + "columnsFrom": [ + "mentor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notification_preferences": { + "name": "notification_preferences", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email_enabled": { + "name": "email_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "sms_enabled": { + "name": "sms_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sms_consent_at": { + "name": "sms_consent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "sms_consent_source": { + "name": "sms_consent_source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sms_consent_ip": { + "name": "sms_consent_ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reminder_lead_days": { + "name": "reminder_lead_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 7 + }, + "quiet_hours_start": { + "name": "quiet_hours_start", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'21:00'" + }, + "quiet_hours_end": { + "name": "quiet_hours_end", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'08:00'" + }, + "digest_only": { + "name": "digest_only", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": {}, + "foreignKeys": { + "notification_preferences_user_id_users_id_fk": { + "name": "notification_preferences_user_id_users_id_fk", + "tableFrom": "notification_preferences", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.position_skills": { + "name": "position_skills", + "schema": "", + "columns": { + "position_id": { + "name": "position_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "skill_id": { + "name": "skill_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "weight": { + "name": "weight", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "required_level": { + "name": "required_level", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_core": { + "name": "is_core", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "position_skills_skill_idx": { + "name": "position_skills_skill_idx", + "columns": [ + { + "expression": "skill_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "position_skills_position_id_roles_id_fk": { + "name": "position_skills_position_id_roles_id_fk", + "tableFrom": "position_skills", + "tableTo": "roles", + "columnsFrom": [ + "position_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "position_skills_skill_id_skills_id_fk": { + "name": "position_skills_skill_id_skills_id_fk", + "tableFrom": "position_skills", + "tableTo": "skills", + "columnsFrom": [ + "skill_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "position_skills_pk": { + "name": "position_skills_pk", + "columns": [ + "position_id", + "skill_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color_hex": { + "name": "color_hex", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "call_time_offset_minutes": { + "name": "call_time_offset_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requires_certification": { + "name": "requires_certification", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "default_headcount": { + "name": "default_headcount", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "roles_slug_idx": { + "name": "roles_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "roles_active_idx": { + "name": "roles_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "roles_slug_unique": { + "name": "roles_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.service_instances": { + "name": "service_instances", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "service_id": { + "name": "service_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "occurs_on": { + "name": "occurs_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "is_special": { + "name": "is_special", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "title_override": { + "name": "title_override", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "published_by": { + "name": "published_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "si_service_starts_at_idx": { + "name": "si_service_starts_at_idx", + "columns": [ + { + "expression": "service_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "starts_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "si_occurs_on_idx": { + "name": "si_occurs_on_idx", + "columns": [ + { + "expression": "occurs_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "si_status_idx": { + "name": "si_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "service_instances_service_id_services_id_fk": { + "name": "service_instances_service_id_services_id_fk", + "tableFrom": "service_instances", + "tableTo": "services", + "columnsFrom": [ + "service_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.services": { + "name": "services", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'America/New_York'" + }, + "rrule": { + "name": "rrule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time_local": { + "name": "start_time_local", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "duration_minutes": { + "name": "duration_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 75 + }, + "doors_open_minutes_before": { + "name": "doors_open_minutes_before", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "services_active_idx": { + "name": "services_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "services_name_unique": { + "name": "services_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.skill_assessments": { + "name": "skill_assessments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "skill_id": { + "name": "skill_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "assessor_id": { + "name": "assessor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'admin'" + }, + "level_from": { + "name": "level_from", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "level_to": { + "name": "level_to", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "comfort_at_time": { + "name": "comfort_at_time", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "skill_assessments_user_created_idx": { + "name": "skill_assessments_user_created_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "skill_assessments_skill_idx": { + "name": "skill_assessments_skill_idx", + "columns": [ + { + "expression": "skill_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "skill_assessments_user_id_users_id_fk": { + "name": "skill_assessments_user_id_users_id_fk", + "tableFrom": "skill_assessments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "skill_assessments_skill_id_skills_id_fk": { + "name": "skill_assessments_skill_id_skills_id_fk", + "tableFrom": "skill_assessments", + "tableTo": "skills", + "columnsFrom": [ + "skill_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "skill_assessments_assessor_id_users_id_fk": { + "name": "skill_assessments_assessor_id_users_id_fk", + "tableFrom": "skill_assessments", + "tableTo": "users", + "columnsFrom": [ + "assessor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.skill_categories": { + "name": "skill_categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color_hex": { + "name": "color_hex", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "skill_categories_slug_idx": { + "name": "skill_categories_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "skill_categories_active_idx": { + "name": "skill_categories_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "skill_categories_slug_unique": { + "name": "skill_categories_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.skills": { + "name": "skills", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "technology_id": { + "name": "technology_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "function_id": { + "name": "function_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dedupe_key": { + "name": "dedupe_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mentor_min_level": { + "name": "mentor_min_level", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'expert'" + }, + "stale_after_days": { + "name": "stale_after_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 120 + }, + "recert_required": { + "name": "recert_required", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "skills_slug_idx": { + "name": "skills_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "skills_active_idx": { + "name": "skills_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "skills_category_idx": { + "name": "skills_category_idx", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "skills_category_id_skill_categories_id_fk": { + "name": "skills_category_id_skill_categories_id_fk", + "tableFrom": "skills", + "tableTo": "skill_categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "skills_technology_id_technologies_id_fk": { + "name": "skills_technology_id_technologies_id_fk", + "tableFrom": "skills", + "tableTo": "technologies", + "columnsFrom": [ + "technology_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "skills_function_id_functions_id_fk": { + "name": "skills_function_id_functions_id_fk", + "tableFrom": "skills", + "tableTo": "functions", + "columnsFrom": [ + "function_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "skills_slug_unique": { + "name": "skills_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + }, + "skills_dedupe_key_unique": { + "name": "skills_dedupe_key_unique", + "nullsNotDistinct": false, + "columns": [ + "dedupe_key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slots": { + "name": "slots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "service_instance_id": { + "name": "service_instance_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role_id": { + "name": "role_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slot_index": { + "name": "slot_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "call_time": { + "name": "call_time", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "slot_note": { + "name": "slot_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_trainee_slot": { + "name": "is_trainee_slot", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "paired_with_user_id": { + "name": "paired_with_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "slots_instance_role_idx": { + "name": "slots_instance_role_idx", + "columns": [ + { + "expression": "service_instance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "role_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slot_index", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slots_status_idx": { + "name": "slots_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slots_service_instance_id_service_instances_id_fk": { + "name": "slots_service_instance_id_service_instances_id_fk", + "tableFrom": "slots", + "tableTo": "service_instances", + "columnsFrom": [ + "service_instance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "slots_role_id_roles_id_fk": { + "name": "slots_role_id_roles_id_fk", + "tableFrom": "slots", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "slots_paired_with_user_id_users_id_fk": { + "name": "slots_paired_with_user_id_users_id_fk", + "tableFrom": "slots", + "tableTo": "users", + "columnsFrom": [ + "paired_with_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "chk_slots_single_parent": { + "name": "chk_slots_single_parent", + "value": "(service_instance_id IS NOT NULL) <> (event_id IS NOT NULL)" + }, + "chk_shadow_paired": { + "name": "chk_shadow_paired", + "value": "not is_trainee_slot or paired_with_user_id is not null" + } + }, + "isRLSEnabled": false + }, + "public.technologies": { + "name": "technologies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "model_number": { + "name": "model_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version_label": { + "name": "version_label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "docs_url": { + "name": "docs_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "purchased_on": { + "name": "purchased_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "serial_number": { + "name": "serial_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retired_at": { + "name": "retired_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "successor_technology_id": { + "name": "successor_technology_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "technologies_slug_idx": { + "name": "technologies_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "technologies_active_idx": { + "name": "technologies_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "technologies_vendor_idx": { + "name": "technologies_vendor_idx", + "columns": [ + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "technologies_category_idx": { + "name": "technologies_category_idx", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "technologies_vendor_id_vendors_id_fk": { + "name": "technologies_vendor_id_vendors_id_fk", + "tableFrom": "technologies", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "technologies_category_id_skill_categories_id_fk": { + "name": "technologies_category_id_skill_categories_id_fk", + "tableFrom": "technologies", + "tableTo": "skill_categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "technologies_slug_unique": { + "name": "technologies_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_skills": { + "name": "user_skills", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "skill_id": { + "name": "skill_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "self_comfort": { + "name": "self_comfort", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "self_rated_at": { + "name": "self_rated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "verified_level": { + "name": "verified_level", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "verified_by": { + "name": "verified_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "mentor_opt_in": { + "name": "mentor_opt_in", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_served_on": { + "name": "last_served_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "user_skills_user_skill_idx": { + "name": "user_skills_user_skill_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "skill_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_skills_skill_idx": { + "name": "user_skills_skill_idx", + "columns": [ + { + "expression": "skill_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_skills_user_id_users_id_fk": { + "name": "user_skills_user_id_users_id_fk", + "tableFrom": "user_skills", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_skills_skill_id_skills_id_fk": { + "name": "user_skills_skill_id_skills_id_fk", + "tableFrom": "user_skills", + "tableTo": "skills", + "columnsFrom": [ + "skill_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone_e164": { + "name": "phone_e164", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "first_name": { + "name": "first_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_name": { + "name": "last_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "system_role": { + "name": "system_role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'volunteer'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending_approval'" + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'America/New_York'" + }, + "emergency_contact": { + "name": "emergency_contact", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approved_by": { + "name": "approved_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_served_at": { + "name": "last_served_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "reliability_score": { + "name": "reliability_score", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deactivated_at": { + "name": "deactivated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_email_lower_idx": { + "name": "users_email_lower_idx", + "columns": [ + { + "expression": "lower(\"email\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_status_idx": { + "name": "users_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_system_role_idx": { + "name": "users_system_role_idx", + "columns": [ + { + "expression": "system_role", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendors": { + "name": "vendors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "support_url": { + "name": "support_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "support_phone": { + "name": "support_phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "vendors_slug_idx": { + "name": "vendors_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "vendors_active_idx": { + "name": "vendors_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "vendors_slug_unique": { + "name": "vendors_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 78e568d..54128aa 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -50,6 +50,13 @@ "when": 1794975448394, "tag": "0006_modern_shiver_man", "breakpoints": true + }, + { + "idx": 7, + "version": "7", + "when": 1794976728115, + "tag": "0007_funny_zarda", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/db/schema.ts b/src/db/schema.ts index 422d9e1..b616f5c 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -6,7 +6,8 @@ * * Deliberately NOT here (added in later units, do not add "while I'm in the schema"): * - notification_templates/rules/outbox (later) - * - user_skills, skill_assessments, growth_goals, skill_equivalencies (C1-C6) + * - user_skills (C2), skill_assessments (C3), growth_goals (C6), + * skill_equivalencies (later) * - service_role_requirements, unavailability, events, notifications outbox * * Conventions (ARCHITECTURE §4.2): @@ -58,6 +59,17 @@ export type SkillLevel = (typeof SKILL_LEVELS)[number]; export const ASSESSMENT_KINDS = ["self", "mentor", "admin", "quiz"] as const; export type AssessmentKind = (typeof ASSESSMENT_KINDS)[number]; +/** Growth-goal lifecycle (ARCHITECTURE §5.8.6). */ +export const GOAL_STATUSES = [ + "requested", + "mentor_assigned", + "in_progress", + "achieved", + "paused", + "declined", +] as const; +export type GoalStatus = (typeof GOAL_STATUSES)[number]; + const DEFAULT_TIMEZONE = "America/New_York"; /* ------------------------------------------------------------------ users */ @@ -235,6 +247,13 @@ export const slots = pgTable( "chk_slots_single_parent", sql`(service_instance_id IS NOT NULL) <> (event_id IS NOT NULL)`, ), + // A shadow/trainee slot only exists alongside a mentor in the same instance + // (ARCHITECTURE §5.8.5). The pure validation in src/domain/shadows.ts is the + // first line; this CHECK is the data-layer backstop. + check( + "chk_shadow_paired", + sql`not is_trainee_slot or paired_with_user_id is not null`, + ), ], ); @@ -545,6 +564,40 @@ export const skillAssessments = pgTable( ], ); +/* --------------------------------------------- growth_goals (C6) */ + +/** + * "I want to skill up" (ARCHITECTURE §4.3, §5.8.6). One active goal per + * (user_id, skill_id) — a volunteer can hold many skills at different levels but + * only one open goal per skill. Drives the mentor queue and the growth report. + */ +export const growthGoals = pgTable( + "growth_goals", + { + id: text("id").primaryKey(), + userId: text("user_id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + skillId: text("skill_id") + .notNull() + .references(() => skills.id, { onDelete: "cascade" }), + targetLevel: text("target_level", { enum: SKILL_LEVELS }).notNull(), + targetDate: date("target_date", { mode: "date" }), + status: text("status", { enum: GOAL_STATUSES }).notNull().default("requested"), + mentorUserId: text("mentor_user_id").references(() => users.id, { onDelete: "set null" }), + shadowCount: integer("shadow_count").notNull().default(0), + createdBy: text("created_by"), + createdAt: timestamp("created_at", { mode: "date", withTimezone: true }) + .notNull() + .defaultNow(), + }, + (table) => [ + // One active goal per (user, skill). + uniqueIndex("growth_goals_user_skill_idx").on(table.userId, table.skillId), + index("growth_goals_status_idx").on(table.status), + ], +); + /* ------------------------------------------------------------- relations */ /** @@ -633,6 +686,7 @@ export const schema = { positionSkills, userSkills, skillAssessments, + growthGoals, }; export type Schema = typeof schema; diff --git a/src/domain/growthGoals.test.ts b/src/domain/growthGoals.test.ts new file mode 100644 index 0000000..60d04eb --- /dev/null +++ b/src/domain/growthGoals.test.ts @@ -0,0 +1,79 @@ +import { describe, expect, it } from "vitest"; +import { + canGoalTransition, + nextGoalStatus, + validateGrowthGoal, + type GoalStatus, +} from "./growthGoals"; + +describe("nextGoalStatus — the §5.8.6 lifecycle", () => { + it("requested → mentor_assigned on assignMentor", () => { + expect(nextGoalStatus("requested", "assignMentor")).toBe("mentor_assigned"); + }); + + it("requested → declined when there is no capacity this season", () => { + expect(nextGoalStatus("requested", "decline")).toBe("declined"); + }); + + it("mentor_assigned → in_progress on the first shadow scheduled", () => { + expect(nextGoalStatus("mentor_assigned", "startShadow")).toBe("in_progress"); + }); + + it("in_progress → in_progress when a shadow is completed (self-loop)", () => { + expect(nextGoalStatus("in_progress", "progressShadow")).toBe("in_progress"); + }); + + it("in_progress → achieved when the mentor signs off the target level", () => { + expect(nextGoalStatus("in_progress", "achieve")).toBe("achieved"); + }); + + it("pauses and resumes", () => { + expect(nextGoalStatus("in_progress", "pause")).toBe("paused"); + expect(nextGoalStatus("paused", "resume")).toBe("in_progress"); + }); +}); + +describe("nextGoalStatus — illegal transitions", () => { + it.each([ + ["requested", "achieve"], + ["requested", "startShadow"], + ["in_progress", "assignMentor"], + ["achieved", "pause"], + ["declined", "resume"], + ])("returns null for %s + %s", (from, action) => { + expect(nextGoalStatus(from as GoalStatus, action as never)).toBeNull(); + }); + + it("keeps a terminal goal (achieved / declined) put", () => { + for (const action of [ + "assignMentor", + "decline", + "startShadow", + "progressShadow", + "achieve", + "pause", + "resume", + ] as const) { + expect(nextGoalStatus("achieved", action)).toBeNull(); + expect(nextGoalStatus("declined", action)).toBeNull(); + } + }); + + it("canGoalTransition mirrors nextGoalStatus", () => { + expect(canGoalTransition("requested", "assignMentor")).toBe(true); + expect(canGoalTransition("requested", "achieve")).toBe(false); + }); +}); + +describe("validateGrowthGoal", () => { + it("accepts a real target level and status", () => { + expect( + validateGrowthGoal({ targetLevel: "qualified", status: "in_progress" }), + ).toEqual([]); + }); + + it("rejects an unknown target level", () => { + const problems = validateGrowthGoal({ targetLevel: "grandmaster" }); + expect(problems[0]).toContain("targetLevel"); + }); +}); diff --git a/src/domain/growthGoals.ts b/src/domain/growthGoals.ts new file mode 100644 index 0000000..5ff3dd0 --- /dev/null +++ b/src/domain/growthGoals.ts @@ -0,0 +1,71 @@ +/** + * Growth-goal lifecycle — unit C6 (ARCHITECTURE §5.8.6). + * + * Pure: no DB, no imports from `src/db`. The state machine behind a + * `growth_goals` row. The data layer calls `nextGoalStatus` to move a goal and + * rejects any transition the diagram does not allow, so a goal can never skip a + * step (e.g. `achieved` straight from `requested`). + * + * Lifecycle (ARCHITECTURE §5.8.6): + * requested → mentor_assigned (admin picks a mentor_ready volunteer) + * requested → declined (no capacity this season) + * mentor_assigned → in_progress (first shadow scheduled) + * in_progress → in_progress (a shadow is completed + assessment logged) + * in_progress → achieved (mentor signs off the target level) + * in_progress / mentor_assigned → paused; paused → in_progress (resume) + * achieved / declined → terminal + */ + +import { GOAL_STATUSES, SKILL_LEVELS, type GoalStatus, type SkillLevel } from "@/db/schema"; + +export { GOAL_STATUSES, SKILL_LEVELS }; +export type { GoalStatus, SkillLevel }; + +/** A lifecycle action. `progressShadow` keeps the goal in `in_progress`. */ +export type GoalAction = + | "assignMentor" // requested → mentor_assigned + | "decline" // requested / mentor_assigned → declined + | "startShadow" // mentor_assigned → in_progress + | "progressShadow" // in_progress → in_progress (shadow_count++) + | "achieve" // in_progress → achieved + | "pause" // in_progress / mentor_assigned → paused + | "resume"; // paused → in_progress + +/** + * The status a goal moves to from `current` on `action`, or `null` when the + * transition is not allowed by the lifecycle. `progressShadow` is a self-loop + * (a completed shadow does not change status) and returns `in_progress`. + */ +export function nextGoalStatus(current: GoalStatus, action: GoalAction): GoalStatus | null { + const transitions: Record>> = { + requested: { assignMentor: "mentor_assigned", decline: "declined" }, + mentor_assigned: { startShadow: "in_progress", decline: "declined", pause: "paused" }, + in_progress: { progressShadow: "in_progress", achieve: "achieved", pause: "paused" }, + paused: { resume: "in_progress" }, + achieved: {}, + declined: {}, + }; + + const target = transitions[current]?.[action]; + return target ?? null; +} + +/** True when `action` is a legal move from `current`. */ +export function canGoalTransition(current: GoalStatus, action: GoalAction): boolean { + return nextGoalStatus(current, action) !== null; +} + +/** Validate a growth-goal payload before it is written. */ +export function validateGrowthGoal(input: { + targetLevel: string; + status?: string; +}): string[] { + const problems: string[] = []; + if (!SKILL_LEVELS.includes(input.targetLevel as SkillLevel)) { + problems.push(`targetLevel must be one of: ${SKILL_LEVELS.join(", ")}`); + } + if (input.status !== undefined && !GOAL_STATUSES.includes(input.status as GoalStatus)) { + problems.push(`status must be one of: ${GOAL_STATUSES.join(", ")}`); + } + return problems; +} diff --git a/src/domain/shadows.test.ts b/src/domain/shadows.test.ts new file mode 100644 index 0000000..d4f1c0f --- /dev/null +++ b/src/domain/shadows.test.ts @@ -0,0 +1,76 @@ +import { describe, expect, it } from "vitest"; +import { validateShadowPairing, type PairedMentorInput } from "./shadows"; + +/** A mentor who is mentor-ready for the skill (expert, opted in, approved). */ +const readyMentor: PairedMentorInput = { + userId: "mentor-1", + verifiedLevel: "expert", + mentorMinLevel: "expert", + mentorOptIn: true, + adminApproved: true, +}; + +describe("validateShadowPairing — shadow without a mentor", () => { + it("rejects a shadow slot with no paired mentor — the primary C6 rule", () => { + const result = validateShadowPairing({ + isShadow: true, + skillId: "skill-1", + pairedMentor: null, + }); + expect(result.ok).toBe(false); + expect(result.problems[0]).toContain("paired mentor"); + }); +}); + +describe("validateShadowPairing — shadow with a mentor", () => { + it("accepts a shadow paired with a mentor-ready mentor", () => { + const result = validateShadowPairing({ + isShadow: true, + skillId: "skill-1", + pairedMentor: readyMentor, + }); + expect(result.ok).toBe(true); + expect(result.problems).toEqual([]); + }); + + it("rejects a shadow whose mentor never opted in to teach", () => { + const result = validateShadowPairing({ + isShadow: true, + skillId: "skill-1", + pairedMentor: { ...readyMentor, mentorOptIn: false }, + }); + expect(result.ok).toBe(false); + expect(result.problems[0]).toContain("not mentor-ready"); + }); + + it("rejects a shadow whose mentor is not at the skill's mentor_min_level", () => { + const result = validateShadowPairing({ + isShadow: true, + skillId: "skill-1", + pairedMentor: { ...readyMentor, verifiedLevel: "qualified", mentorMinLevel: "expert" }, + }); + expect(result.ok).toBe(false); + expect(result.problems[0]).toContain("not mentor-ready"); + }); + + it("rejects a shadow whose mentor is not yet admin-approved", () => { + const result = validateShadowPairing({ + isShadow: true, + skillId: "skill-1", + pairedMentor: { ...readyMentor, adminApproved: false }, + }); + expect(result.ok).toBe(false); + }); +}); + +describe("validateShadowPairing — non-shadow slot", () => { + it("does not require a pairing for a normal slot", () => { + const result = validateShadowPairing({ + isShadow: false, + skillId: "skill-1", + pairedMentor: null, + }); + expect(result.ok).toBe(true); + expect(result.problems).toEqual([]); + }); +}); diff --git a/src/domain/shadows.ts b/src/domain/shadows.ts new file mode 100644 index 0000000..ed2161a --- /dev/null +++ b/src/domain/shadows.ts @@ -0,0 +1,82 @@ +/** + * Shadow pairing validation — unit C6 (ARCHITECTURE §5.8.5). + * + * Pure: no DB, no imports from `src/db`. Depends on C5's `isMentorReady` (the + * per-skill mentor predicate). A shadow slot is a trainee slot that does not + * count toward coverage; it is only valid alongside a mentor who is + * mentor-ready for that exact skill. + * + * The rule (ARCHITECTURE §5.8.5): + * - A shadow slot requires a paired mentor **in the same service instance**. + * - That mentor must be mentor-ready for the skill: verified level at or above + * the skill's mentor_min_level, opted in to teach, and admin-approved. + * + * The "same instance" context lives in the slot/assignment data layer (D3/D5), + * which resolves the paired mentor's competency and passes it in here. This + * function is the reusable gate the data layer calls — and the CHECK constraint + * `chk_shadow_paired` on `slots` is the data-layer backstop that a trainee slot + * always has a `paired_with_user_id`. + */ + +import { isMentorReady, type SkillLevel } from "./mentor"; + +export { isMentorReady }; +export type { SkillLevel }; + +/** A paired mentor's competency for the skill, resolved by the data layer. */ +export interface PairedMentorInput { + userId: string; + verifiedLevel: SkillLevel; + mentorMinLevel: SkillLevel; + mentorOptIn: boolean; + adminApproved: boolean; +} + +export interface ShadowPairInput { + /** True for a trainee / shadow slot (does not count toward coverage). */ + isShadow: boolean; + /** The skill being shadowed — the mentor must be ready on this exact skill. */ + skillId: string; + /** The mentor paired into this instance for this skill, or null. */ + pairedMentor: PairedMentorInput | null; +} + +export type ShadowPairResult = { ok: boolean; problems: string[] }; + +/** + * Validate a shadow slot's pairing. Returns `{ ok: true }` when the pairing is + * valid, or `{ ok: false, problems }` listing every reason it is not. Called by + * the slot data layer before a shadow slot is written. + */ +export function validateShadowPairing(params: ShadowPairInput): ShadowPairResult { + const problems: string[] = []; + + // A non-shadow slot has no pairing requirement. + if (!params.isShadow) return { ok: true, problems }; + + // A shadow without a paired mentor is invalid — the primary C6 rule. + if (!params.pairedMentor) { + return { + ok: false, + problems: [ + `shadow slot for skill ${params.skillId} requires a paired mentor in the same instance`, + ], + }; + } + + // The paired mentor must be mentor-ready for this exact skill. + if ( + !isMentorReady({ + verifiedLevel: params.pairedMentor.verifiedLevel, + mentorMinLevel: params.pairedMentor.mentorMinLevel, + mentorOptIn: params.pairedMentor.mentorOptIn, + adminApproved: params.pairedMentor.adminApproved, + }) + ) { + problems.push( + `paired mentor ${params.pairedMentor.userId} is not mentor-ready for skill ${params.skillId}`, + ); + } + + return { ok: problems.length === 0, problems }; +}