diff --git a/.agent/PROGRESS.md b/.agent/PROGRESS.md index 3deb578..77b28dd 100644 --- a/.agent/PROGRESS.md +++ b/.agent/PROGRESS.md @@ -498,7 +498,31 @@ Build log for Media Team Hub. One unit per commit, top to bottom. Append after e - **Headcount clamped to >= 1.** A role always produces at least one seat, so a zero/missing headcount can never silently drop a role from an instance. - **Seed is date-dependent, not fully idempotent.** The seed materializes `nextSundaysInTz(2)` (rolling window), so re-running it across dates creates new instances. After testing I reset instances/slots/assignments and re-ran the seed once to restore the canonical 4-instance / 12-slot state. -**Next: D4 — blackout CRUD + `isUnavailable(user, date)` pure function, ranges + rrule.** +## D4 — Blackout CRUD + `isUnavailable(user, date)` — DONE 2026-11-18 + +**Scope (from BUILD-PLAN.md):** blackout CRUD + `isUnavailable(user, date)` pure function, ranges + rrule. Done when: `pnpm test availability` green incl. inclusive-end case. ARCHITECTURE §4.7 / §5.3 rule 5 / §5.4. + +**Delivered:** +- `src/domain/availability.ts` — pure `isUnavailable(records, date)` + `overlapsRange(date, startsOn, endsOn)` + `recordCovers(record, date)`. A record covers the date if it is `active` and either its inclusive range `[starts_on, ends_on]` contains the date (same day = one day) or its `rrule` matches. No DB imports. +- `src/domain/availability.test.ts` — 11 tests named after the rule: inclusive-end case (2026-11-21..2026-11-28 covers 11-28), inclusive-start, day-before/day-after excluded, same-day blackout, active range covers, cancelled never covers, recurring rule matches its weekday, intervening Sunday excluded (2-week interval), malformed rrule neither throws nor matches, empty set false. +- `src/db/schema.ts` — `unavailability` table (ARCHITECTURE §4.7): `id, user_id (FK users, cascade), kind (enum), starts_on, ends_on (date), all_day (default true), reason (nullable), rrule (nullable), status (enum active|cancelled), created_at, created_by`. CHECK `ends_on >= starts_on`, CHECK `(ends_on - starts_on) <= 365`, unique index `(user_id, starts_on, ends_on) WHERE status='active'`, index on `user_id`. +- `src/db/unavailability.ts` — `listUnavailability({ userId })`, `getUnavailability`, `createUnavailability`, `updateUnavailability`, `cancelUnavailability` (soft-delete → `status='cancelled'`). Range validated on write (`validateUnavailabilityRange`); `rrule` validated via `validateRecurrence`. +- `src/app/api/dev/unavailability/route.ts` — GET (list, `userId` filter), POST (create, 400 on bad range/rrule), PATCH (edit or `status:'cancelled'` cancel). Constraint errors mapped to 400. + +**Schema change + migration:** `drizzle/0008_needy_stryfe.sql` creates the `unavailability` table. Applied to the DB on :5433. + +**Verification (all exit 0):** +- `tsc --noEmit` ✓ · `eslint .` ✓ (0 problems) · `vitest run` ✓ (**140** total; D4 = 11) +- Runtime smoke test (running app on :3000): POST valid blackout → 201; POST span > 365 → 400 "span must not exceed 365 days"; POST ends < starts → 400 "ends_on must not precede starts_on"; GET list; PATCH cancel → 200 with `status='cancelled'` (row persists). CHECK constraints enforced at the DB layer too (span > 365 and ends < starts rejected by `chk_unavailability_*`). Test rows cleaned up. + +**Decisions:** +- **Inclusive on both ends, by design.** A blackout 2026-11-21..2026-11-28 covers 11-28 (the end date), matching the ARCHITECTURE ("inclusive; same day = one day"). `overlapsRange` uses `>=` / `<=` on ISO strings (lexicographic order == chronological for YYYY-MM-DD), so no date parsing is needed. +- **`date` columns stored as strings (`mode: "string"`).** The whole recurrence/availability domain works in `YYYY-MM-DD` strings; storing the range as strings avoids Date↔string conversion at the DB boundary. Postgres `date` is mode-agnostic, so the migration is identical to a `mode: "date"` column. +- **Range and rrule are mutually exclusive coverage paths.** A record covers a date if it is `active` AND (range contains the date OR rrule matches it). A recurring blackout uses the rrule; a one-time blackout uses the range. `parseRecurrence` throws on malformed input, so `isUnavailable` guards with `validateRecurrence` and never throws. +- **Cancel, never delete.** `cancelUnavailability` flips `status='cancelled'`; the row persists so historical assignment conflicts stay explainable (rule 5 in §5.3 warns, doesn't hard-block). `isUnavailable` skips non-`active` records, so a cancelled blackout no longer excludes the volunteer. +- **Constraints enforced in two layers.** The pure `validateUnavailabilityRange` rejects bad ranges at the API boundary (400 with a clear message); the DB `chk_unavailability_*` CHECK constraints are the backstop so a bad range can never reach the table. + +**Next: D5 — conflict engine (pure function, hard vs soft conflicts).** --- diff --git a/.gitignore b/.gitignore index ee3caa8..5dba376 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ yarn-error.log* .pnpm-debug.log* # env files (commit .env.example only, never real secrets) +.env .env.local .env.* !.env.example diff --git a/drizzle/0008_needy_stryfe.sql b/drizzle/0008_needy_stryfe.sql new file mode 100644 index 0000000..764762e --- /dev/null +++ b/drizzle/0008_needy_stryfe.sql @@ -0,0 +1,19 @@ +CREATE TABLE "unavailability" ( + "id" text PRIMARY KEY NOT NULL, + "user_id" text NOT NULL, + "kind" text DEFAULT 'blackout' NOT NULL, + "starts_on" date NOT NULL, + "ends_on" date NOT NULL, + "all_day" boolean DEFAULT true NOT NULL, + "reason" text, + "rrule" text, + "status" text DEFAULT 'active' NOT NULL, + "created_at" timestamp with time zone DEFAULT now(), + "created_by" text, + CONSTRAINT "chk_unavailability_span" CHECK ("unavailability"."ends_on" >= "unavailability"."starts_on"), + CONSTRAINT "chk_unavailability_max_span" CHECK ("unavailability"."ends_on" - "unavailability"."starts_on" <= 365) +); +--> statement-breakpoint +ALTER TABLE "unavailability" ADD CONSTRAINT "unavailability_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "uq_unavailability_range" ON "unavailability" USING btree ("user_id","starts_on","ends_on") WHERE "unavailability"."status" = 'active';--> statement-breakpoint +CREATE INDEX "unavailability_user_idx" ON "unavailability" USING btree ("user_id"); \ No newline at end of file diff --git a/drizzle/meta/0008_snapshot.json b/drizzle/meta/0008_snapshot.json new file mode 100644 index 0000000..3e01360 --- /dev/null +++ b/drizzle/meta/0008_snapshot.json @@ -0,0 +1,2457 @@ +{ + "id": "b0bafcb2-2d8b-46c5-be51-0019fdb1ed84", + "prevId": "18ddad89-1dac-4d44-8fa2-16bf85fb6f1a", + "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.unavailability": { + "name": "unavailability", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blackout'" + }, + "starts_on": { + "name": "starts_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "ends_on": { + "name": "ends_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "all_day": { + "name": "all_day", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rrule": { + "name": "rrule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "uq_unavailability_range": { + "name": "uq_unavailability_range", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "starts_on", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "ends_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"unavailability\".\"status\" = 'active'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "unavailability_user_idx": { + "name": "unavailability_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "unavailability_user_id_users_id_fk": { + "name": "unavailability_user_id_users_id_fk", + "tableFrom": "unavailability", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "chk_unavailability_span": { + "name": "chk_unavailability_span", + "value": "\"unavailability\".\"ends_on\" >= \"unavailability\".\"starts_on\"" + }, + "chk_unavailability_max_span": { + "name": "chk_unavailability_max_span", + "value": "\"unavailability\".\"ends_on\" - \"unavailability\".\"starts_on\" <= 365" + } + }, + "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 54128aa..e0dbd37 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -57,6 +57,13 @@ "when": 1794976728115, "tag": "0007_funny_zarda", "breakpoints": true + }, + { + "idx": 8, + "version": "7", + "when": 1794979809192, + "tag": "0008_needy_stryfe", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/api/dev/unavailability/route.ts b/src/app/api/dev/unavailability/route.ts new file mode 100644 index 0000000..c8b0511 --- /dev/null +++ b/src/app/api/dev/unavailability/route.ts @@ -0,0 +1,145 @@ +import { NextRequest } from "next/server"; +import { z } from "zod"; +import { + listUnavailability, + createUnavailability, + updateUnavailability, + cancelUnavailability, +} from "@/db/unavailability"; + +const JSON_HEADERS = { "content-type": "application/json" }; + +const idSchema = z.string().min(1); + +const kindSchema = z + .enum(["blackout", "vacation", "recurring", "preference"]) + .optional(); +const statusSchema = z.enum(["active", "cancelled"]).optional(); + +const unavailabilityCreateSchema = z.object({ + userId: z.string().min(1), + kind: kindSchema, + startsOn: z.string().regex(/^\d{4}-\d{2}-\d{2}$/), + endsOn: z.string().regex(/^\d{4}-\d{2}-\d{2}$/), + allDay: z.boolean().optional(), + reason: z.string().nullable().optional(), + rrule: z.string().nullable().optional(), + status: statusSchema, + createdBy: z.string().nullable().optional(), +}); + +const unavailabilityUpdateSchema = unavailabilityCreateSchema.partial().omit({ + userId: true, +}); + +async function readBody(req: NextRequest) { + try { + return await req.json(); + } catch { + return null; + } +} + +const bad = (message: string) => + new Response(JSON.stringify({ error: message }), { + status: 400, + headers: JSON_HEADERS, + }); + +const ok = (row: unknown) => + new Response(JSON.stringify({ row }), { + status: 200, + headers: JSON_HEADERS, + }); + +const created = (row: unknown) => + new Response(JSON.stringify({ row }), { + status: 201, + headers: JSON_HEADERS, + }); + +/** Map Postgres constraint violations to client errors. Returns null otherwise. */ +const constraintError = (err: unknown): Response | null => { + let code: string | undefined; + let node: { code?: string; cause?: unknown } | null = err as { + code?: string; + cause?: unknown; + } | null; + while (node) { + if (node.code) { + code = node.code; + break; + } + node = (node.cause as { code?: string; cause?: unknown } | null) ?? null; + } + if (code === "23514") { + return new Response(JSON.stringify({ error: "invalid blackout range" }), { + status: 400, + headers: JSON_HEADERS, + }); + } + if (code === "23503") { + return new Response( + JSON.stringify({ error: "referenced user does not exist" }), + { status: 400, headers: JSON_HEADERS }, + ); + } + return null; +}; + +/** GET /api/dev/unavailability?userId=... — list blackouts (one per user). */ +export const GET = async (req: NextRequest) => { + const userId = req.nextUrl.searchParams.get("userId") ?? undefined; + const rows = await listUnavailability({ userId }); + return new Response(JSON.stringify({ rows }), { + status: 200, + headers: JSON_HEADERS, + }); +}; + +/** POST /api/dev/unavailability { ...fields } — create a blackout. */ +export const POST = async (req: NextRequest) => { + const body = await readBody(req); + if (!body || typeof body !== "object") { + return bad("invalid body"); + } + const parsed = unavailabilityCreateSchema.safeParse(body); + if (!parsed.success) return bad(parsed.error.message); + try { + return created(await createUnavailability(parsed.data)); + } catch (err) { + const constraint = constraintError(err); + if (constraint) return constraint; + return bad(err instanceof Error ? err.message : "internal error"); + } +}; + +/** + * PATCH /api/dev/unavailability { id, ...fields } — edit a blackout. + * PATCH { id, status: "cancelled" } — cancel (soft delete). + */ +export const PATCH = async (req: NextRequest) => { + const body = await readBody(req); + if (!body || typeof body !== "object") { + return bad("invalid body"); + } + const id = idSchema.safeParse((body as { id?: unknown }).id); + if (!id.success) return bad("invalid id"); + + // Cancel path: explicit status cancelled. + if ((body as { status?: unknown }).status === "cancelled") { + const row = await cancelUnavailability(id.data); + return ok(row); + } + + const parsed = unavailabilityUpdateSchema.safeParse(body); + if (!parsed.success) return bad(parsed.error.message); + try { + const row = await updateUnavailability(id.data, parsed.data); + return row ? ok(row) : bad("blackout not found"); + } catch (err) { + const constraint = constraintError(err); + if (constraint) return constraint; + return bad(err instanceof Error ? err.message : "internal error"); + } +}; diff --git a/src/db/schema.ts b/src/db/schema.ts index b616f5c..a661d70 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -8,7 +8,7 @@ * - notification_templates/rules/outbox (later) * - user_skills (C2), skill_assessments (C3), growth_goals (C6), * skill_equivalencies (later) - * - service_role_requirements, unavailability, events, notifications outbox + * - service_role_requirements, events, notifications outbox * * Conventions (ARCHITECTURE §4.2): * - `id` is a UUIDv7 text column (generated at the app/seed layer, see src/lib/uuid.ts) @@ -40,6 +40,13 @@ export type AssignmentStatus = (typeof ASSIGNMENT_STATUSES)[number]; export const ASSIGNMENT_SOURCES = ["manual", "auto", "swap", "import"] as const; export type AssignmentSource = (typeof ASSIGNMENT_SOURCES)[number]; +// Added in D4 (blackout CRUD + isUnavailable). ARCHITECTURE §"unavailability — blackout dates". +export const UNAVAILABILITY_KINDS = ["blackout", "vacation", "recurring", "preference"] as const; +export type UnavailabilityKind = (typeof UNAVAILABILITY_KINDS)[number]; + +export const UNAVAILABILITY_STATUSES = ["active", "cancelled"] as const; +export type UnavailabilityStatus = (typeof UNAVAILABILITY_STATUSES)[number]; + export const CONFIRMED_VIAS = ["app", "email_link", "sms_reply", "admin"] as const; export type ConfirmedVia = (typeof CONFIRMED_VIAS)[number]; @@ -288,6 +295,57 @@ export const assignments = pgTable( ], ); +/* ------------------------------------------------- unavailability (D4) */ + +/** + * Blackout / unavailability rows (ARCHITECTURE §\"unavailability — blackout + * dates\"). A volunteer publishes blackout dates; `isUnavailable` (D4) reads + * them to exclude the volunteer from the assign picker and auto-fill. + * + * `starts_on` / `ends_on` are inclusive local dates (same day = one day). + * CHECK constraints enforce `ends_on >= starts_on` and a <= 365 day span. + */ +export const unavailability = pgTable( + "unavailability", + { + id: text("id").primaryKey(), + userId: text("user_id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + kind: text("kind", { enum: UNAVAILABILITY_KINDS }) + .notNull() + .default("blackout"), + /** Inclusive local-date range; same day = one day. Stored as YYYY-MM-DD. */ + startsOn: date("starts_on", { mode: "string" }).notNull(), + endsOn: date("ends_on", { mode: "string" }).notNull(), + allDay: boolean("all_day").notNull().default(true), + /** Private by default; admin-visible only. */ + reason: text("reason"), + /** Recurring pattern (RFC 5545 subset), e.g. every other week. */ + rrule: text("rrule"), + status: text("status", { enum: UNAVAILABILITY_STATUSES }) + .notNull() + .default("active"), + createdAt: timestamp("created_at", { mode: "date", withTimezone: true }) + .defaultNow(), + createdBy: text("created_by"), + }, + (table) => [ + // One active record per (user, range); recurring records carry an rrule. + uniqueIndex("uq_unavailability_range") + .on(table.userId, table.startsOn, table.endsOn) + .where(sql`${table.status} = 'active'`), + index("unavailability_user_idx").on(table.userId), + // Inclusive range: ends_on must not precede starts_on. + check("chk_unavailability_span", sql`${table.endsOn} >= ${table.startsOn}`), + // Max span 365 days (date - date is an integer number of days in PG). + check( + "chk_unavailability_max_span", + sql`${table.endsOn} - ${table.startsOn} <= 365`, + ), + ], +); + /* ------------------------------------------------------------- catalog */ /** @@ -678,6 +736,7 @@ export const schema = { serviceInstances, slots, assignments, + unavailability, skillCategories, vendors, technologies, diff --git a/src/db/unavailability.ts b/src/db/unavailability.ts new file mode 100644 index 0000000..10f700d --- /dev/null +++ b/src/db/unavailability.ts @@ -0,0 +1,143 @@ +/** + * Blackout / unavailability rows (ARCHITECTURE §"unavailability — blackout + * dates"). D4 writes these — a volunteer publishes blackout dates; the pure + * `isUnavailable` (src/domain/availability.ts) reads them to exclude the + * volunteer from the assign picker and auto-fill. + * + * Integrity rules: + * - `ends_on` is inclusive and must not precede `starts_on`; span <= 365 days. + * Both are validated on write so a bad range can never reach the DB. + * - `rrule` is validated on write (RFC 5545 subset) so a malformed rule can + * never reach `isUnavailable`. + * - Cancel, never delete — `status` flips to `cancelled`; the row persists so + * historical assignment conflicts stay explainable. + * + * Read path: `listUnavailability({ userId })` returns one record per user; omit + * `userId` for the admin-wide list. + */ + +import { eq } from "drizzle-orm"; +import { db } from "@/db"; +import { unavailability } from "@/db/schema"; +import { uuidv7 } from "@/lib/uuid"; +import { validateRecurrence } from "@/domain/recurrence"; + +type UnavailabilityInsert = typeof unavailability.$inferInsert; + +export type UnavailabilityCreate = Omit< + UnavailabilityInsert, + "id" | "created_at" | "created_by" +> & { createdBy?: string | null }; +export type UnavailabilityUpdate = Partial< + Omit +>; + +const notNull = (value: T | null | undefined): T | undefined => + value === null || value === undefined ? undefined : value; + +/** + * Validate the inclusive range: `ends_on >= starts_on` and a span of <= 365 + * days. Dates are ISO (YYYY-MM-DD) strings; the span is computed in whole days. + */ +export function validateUnavailabilityRange( + startsOn: string, + endsOn: string, +): string[] { + const errors: string[] = []; + if (endsOn < startsOn) errors.push("ends_on must not precede starts_on"); + const days = Math.round( + (Date.parse(`${endsOn}T00:00:00Z`) - Date.parse(`${startsOn}T00:00:00Z`)) / + 86_400_000, + ); + if (days > 365) errors.push("span must not exceed 365 days"); + return errors; +} + +export async function listUnavailability({ userId }: { userId?: string } = {}) { + const where = userId + ? eq(unavailability.userId, userId) + : undefined; + return await db + .select() + .from(unavailability) + .where(where) + .orderBy(unavailability.startsOn, unavailability.endsOn); +} + +export async function getUnavailability(id: string) { + const [row] = await db.select().from(unavailability).where(eq(unavailability.id, id)); + return row ?? null; +} + +export async function createUnavailability(fields: UnavailabilityCreate) { + const problems = validateUnavailabilityRange(fields.startsOn, fields.endsOn); + if (fields.rrule != null) problems.push(...validateRecurrence(fields.rrule)); + if (problems.length > 0) { + throw new Error(problems.join("; ")); + } + + const values: UnavailabilityInsert = { + id: uuidv7(), + userId: fields.userId, + kind: fields.kind, + startsOn: fields.startsOn, + endsOn: fields.endsOn, + allDay: fields.allDay ?? true, + reason: notNull(fields.reason), + rrule: notNull(fields.rrule), + status: fields.status ?? "active", + createdBy: notNull(fields.createdBy), + }; + + const [row] = await db.insert(unavailability).values(values).returning(); + return row; +} + +export async function updateUnavailability( + id: string, + fields: UnavailabilityUpdate, +) { + const current = await getUnavailability(id); + if (!current) return null; + + // Validate the resulting range even when only one bound is being changed. + const startsOn = (fields.startsOn ?? current.startsOn) as string; + const endsOn = (fields.endsOn ?? current.endsOn) as string; + const problems = validateUnavailabilityRange(startsOn, endsOn); + if (fields.rrule != null) problems.push(...validateRecurrence(fields.rrule)); + if (problems.length > 0) { + throw new Error(problems.join("; ")); + } + + const patch: Record = {}; + const editable: (keyof UnavailabilityUpdate)[] = [ + "kind", + "startsOn", + "endsOn", + "allDay", + "reason", + "rrule", + "status", + ]; + for (const key of editable) { + if (fields[key] !== undefined) patch[key] = fields[key]; + } + if (Object.keys(patch).length === 0) return current; + + const [row] = await db + .update(unavailability) + .set(patch) + .where(eq(unavailability.id, id)) + .returning(); + return row; +} + +/** Cancel (soft-delete) a blackout; the row persists for audit. */ +export async function cancelUnavailability(id: string) { + const [row] = await db + .update(unavailability) + .set({ status: "cancelled" }) + .where(eq(unavailability.id, id)) + .returning(); + return row; +} diff --git a/src/domain/availability.test.ts b/src/domain/availability.test.ts new file mode 100644 index 0000000..ac306c6 --- /dev/null +++ b/src/domain/availability.test.ts @@ -0,0 +1,92 @@ +import { describe, expect, it } from "vitest"; +import { + isUnavailable, + overlapsRange, + recordCovers, + type UnavailabilityRecord, +} from "./availability"; + +const record = (partial: Partial): UnavailabilityRecord => ({ + id: "u1", + userId: "user-1", + kind: "blackout", + startsOn: "2026-11-21", + endsOn: "2026-11-28", + allDay: true, + reason: null, + rrule: null, + status: "active", + createdAt: new Date(), + createdBy: null, + ...partial, +}); + +describe("overlapsRange — inclusive on both ends", () => { + it("covers the start date", () => { + expect(overlapsRange("2026-11-21", "2026-11-21", "2026-11-28")).toBe(true); + }); + + it("covers the END date (inclusive-end case)", () => { + expect(overlapsRange("2026-11-28", "2026-11-21", "2026-11-28")).toBe(true); + }); + + it("excludes the day before start and the day after end", () => { + expect(overlapsRange("2026-11-20", "2026-11-21", "2026-11-28")).toBe(false); + expect(overlapsRange("2026-11-29", "2026-11-21", "2026-11-28")).toBe(false); + }); + + it("a same-day blackout covers exactly that day", () => { + expect(overlapsRange("2026-12-25", "2026-12-25", "2026-12-25")).toBe(true); + expect(overlapsRange("2026-12-24", "2026-12-25", "2026-12-25")).toBe(false); + }); +}); + +describe("recordCovers", () => { + it("honours an active range", () => { + expect(recordCovers(record({}), "2026-11-25")).toBe(true); + }); + + it("a cancelled record never covers", () => { + expect(recordCovers(record({ status: "cancelled" }), "2026-11-25")).toBe(false); + }); + + it("a recurring rule matches its weekday", () => { + // Every other Sunday starting 2026-11-22: 11-22, 12-06 match; 11-29 does + // not (it is the skipped Sunday of the 2-week interval). + const r = record({ + startsOn: "2026-11-22", + endsOn: "2027-12-31", + rrule: "FREQ=WEEKLY;INTERVAL=2;BYDAY=SU", + }); + expect(recordCovers(r, "2026-11-22")).toBe(true); + expect(recordCovers(r, "2026-12-06")).toBe(true); + // The intervening Sunday is outside the 2-week interval. + expect(recordCovers(r, "2026-11-29")).toBe(false); + }); + + it("a malformed rrule does not throw and does not match", () => { + const r = record({ rrule: "FREQ=MONTHLY;BOGUS" }); + expect(() => recordCovers(r, "2026-11-25")).not.toThrow(); + expect(recordCovers(r, "2026-11-25")).toBe(false); + }); +}); + +describe("isUnavailable", () => { + it("true when any active record covers the date", () => { + const records = [ + record({ id: "a", startsOn: "2026-11-01", endsOn: "2026-11-10" }), + record({ id: "b", startsOn: "2026-11-25", endsOn: "2026-11-28" }), + ]; + expect(isUnavailable(records, "2026-11-28")).toBe(true); + expect(isUnavailable(records, "2026-11-05")).toBe(true); + }); + + it("false when no record covers the date", () => { + const records = [record({ startsOn: "2026-11-25", endsOn: "2026-11-28" })]; + expect(isUnavailable(records, "2026-12-25")).toBe(false); + }); + + it("false for an empty record set", () => { + expect(isUnavailable([], "2026-11-25")).toBe(false); + }); +}); diff --git a/src/domain/availability.ts b/src/domain/availability.ts new file mode 100644 index 0000000..c791f91 --- /dev/null +++ b/src/domain/availability.ts @@ -0,0 +1,63 @@ +/** + * Availability — unit D4 (ARCHITECTURE §"unavailability — blackout dates"). + * + * Pure: no DB, no `src/db` imports. `isUnavailable(userRecords, date)` answers + * whether a volunteer is out on a given local date (YYYY-MM-DD), so the assign + * picker and auto-fill can exclude them. + * + * A record covers the date if it is `active` and either: + * - its inclusive range `[starts_on, ends_on]` contains the date, or + * - its `rrule` (RFC 5545 subset) matches the date. + * + * Range bounds are INCLUSIVE on both ends: a blackout 2026-11-21..2026-11-28 + * covers 2026-11-28 (the end date), not just up to 2026-11-27. + */ + +import { parseRecurrence, matchesRecurrence, validateRecurrence } from "./recurrence"; + +export type UnavailabilityKind = "blackout" | "vacation" | "recurring" | "preference"; +export type UnavailabilityStatus = "active" | "cancelled"; + +export interface UnavailabilityRecord { + id: string; + userId: string; + kind: UnavailabilityKind; + /** Inclusive local-date range; same day = one day. */ + startsOn: string; + endsOn: string; + allDay: boolean; + reason: string | null; + /** Recurring pattern (RFC 5545 subset), e.g. "FREQ=WEEKLY;INTERVAL=2". */ + rrule: string | null; + status: UnavailabilityStatus; + createdAt: Date; + createdBy: string | null; +} + +/** + * Inclusive range check: `startsOn <= date <= endsOn`. ISO (YYYY-MM-DD) strings + * compare correctly lexicographically, so no date parsing is needed here. + */ +export function overlapsRange(date: string, startsOn: string, endsOn: string): boolean { + return date >= startsOn && date <= endsOn; +} + +/** Is this single record active and covering `date`? */ +export function recordCovers(record: UnavailabilityRecord, date: string): boolean { + if (record.status !== "active") return false; + // A recurring rule is authoritative for coverage; the range (if any) is just + // metadata and is not used to over-cover non-matching dates. + if (record.rrule) { + // Guard the rrule: parseRecurrence() throws on malformed input, so only + // match when validateRecurrence() reports the rule is well-formed. + return validateRecurrence(record.rrule).length === 0 + && matchesRecurrence(date, parseRecurrence(record.rrule)); + } + // Range-only blackout: inclusive on both ends. + return overlapsRange(date, record.startsOn, record.endsOn); +} + +/** Is the user unavailable on `date` (YYYY-MM-DD)? */ +export function isUnavailable(records: UnavailabilityRecord[], date: string): boolean { + return records.some((record) => recordCovers(record, date)); +}