diff --git a/README.md b/README.md index 22373e5..2d0615d 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ curl -fsS http://localhost:3000/api/health # dashboard curl -fsS http://localhost:8787/api/health # advanced editor ``` -With the default local configuration (`MAGIC_LINK_DEV_TRANSPORT=true`), requesting a sign-in link shows it in the browser and prints it in the app log: +With the default local configuration (`MAGIC_LINK_DEV_TRANSPORT=true`), requesting a sign-in link prints it in the app log: ```bash docker compose logs -f app @@ -265,7 +265,7 @@ Copy `.env.example` to `.env`; never commit real secrets (`.env*` is ignored, `. | `APP_ORIGIN` | Fallback application origin. | | `CHURCH_TIMEZONE` | Display timezone; scheduling itself stores UTC instants and local dates. Defaults to `America/New_York`. | | `AUTO_ACTIVATE_NEW_USERS` | `false` (default) sends unknown emails to `pending_approval`; `true` is for dev/test only. | -| `MAGIC_LINK_DEV_TRANSPORT` | Shows/prints the sign-in link instead of emailing it. Defaults on outside production; compose sets `true` for first login. | +| `MAGIC_LINK_DEV_TRANSPORT` | Returns/prints the sign-in link instead of emailing it; the login page never displays it. Defaults on outside production; compose sets `true` for first login. | | `ALLOW_DEV_RESET` | Enables the destructive `POST /api/dev/reset` endpoint. Must stay `false` in real deployments. | | `CRON_SECRET` | Bearer/query secret for the cron HTTP routes. Empty means session-only. | | `POSTMARK_SERVER_TOKEN`, `POSTMARK_FROM` | Optional Postmark fallback and default sender. Admin email settings take precedence. | @@ -470,7 +470,7 @@ Keep the app on loopback and use an SSH tunnel for this step: ssh -L 3000:127.0.0.1:3000 you@media.example.org ``` -Open `http://localhost:3000/login`, request a link for `admin@glenloch.local`, and read it from the page or from `docker compose logs app`. Then: +Open `http://localhost:3000/login`, request a link for `admin@glenloch.local`, and read it from `docker compose logs app`. Then: 1. Admin → People: change the admin name and email to the real person, and create real accounts. 2. Admin → Services: set real service times, roles, and headcounts. @@ -483,7 +483,7 @@ Only after that, set `MAGIC_LINK_DEV_TRANSPORT=false` in `.env` and restart: docker compose up -d app ``` -**Do not expose the app publicly while the dev transport is on:** it displays sign-in links in the browser. Keep `APP_BIND=127.0.0.1` until bootstrap is finished. +**Do not expose the app publicly while the dev transport is on:** it can return and log sign-in links during bootstrap. Keep `APP_BIND=127.0.0.1` until bootstrap is finished. ### 6. Reverse proxy and TLS with Caddy diff --git a/docker-compose.yml b/docker-compose.yml index 4c3d389..ab1b335 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -91,6 +91,25 @@ services: max-file: "3" restart: unless-stopped + # Notification dispatcher. The app only queues mail in the outbox; this loop + # drains it through the CRON_SECRET endpoint, so assignment, publish and + # reminder emails go out without anyone pressing a button. + cron: + image: curlimages/curl:8.10.1 + environment: + CRON_SECRET: ${CRON_SECRET:-} + depends_on: + app: + condition: service_healthy + entrypoint: ["sh", "-c"] + command: + - 'while true; do echo "cron tick"; curl -fsS --max-time 30 -H "Authorization: Bearer $$CRON_SECRET" http://app:3000/api/dev/cron/notifications || echo "notification tick failed"; echo; sleep 60; done' + restart: unless-stopped + logging: + options: + max-size: "10m" + max-file: "3" + # Advanced photo editor (Lumenroom), vendored under ./lumenroom so one clone # and one `docker compose up -d --build` deploys both apps. Its catalog is # temporary bridge data; originals stay on the app's media storage. diff --git a/drizzle/0023_assignment_proposals.sql b/drizzle/0023_assignment_proposals.sql new file mode 100644 index 0000000..cf45552 --- /dev/null +++ b/drizzle/0023_assignment_proposals.sql @@ -0,0 +1,15 @@ +CREATE TABLE "assignment_proposals" ( + "id" text PRIMARY KEY NOT NULL, + "assignment_id" text NOT NULL, + "user_id" text NOT NULL, + "proposed_instance_id" text NOT NULL, + "note" text, + "status" text DEFAULT 'pending' NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "assignment_proposals" ADD CONSTRAINT "assignment_proposals_assignment_id_assignments_id_fk" FOREIGN KEY ("assignment_id") REFERENCES "public"."assignments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "assignment_proposals" ADD CONSTRAINT "assignment_proposals_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "assignment_proposals" ADD CONSTRAINT "assignment_proposals_proposed_instance_id_service_instances_id_fk" FOREIGN KEY ("proposed_instance_id") REFERENCES "public"."service_instances"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "assignment_proposals_pending_assignment_idx" ON "assignment_proposals" USING btree ("assignment_id") WHERE "assignment_proposals"."status" = 'pending';--> statement-breakpoint +CREATE INDEX "assignment_proposals_status_idx" ON "assignment_proposals" USING btree ("status","created_at"); \ No newline at end of file diff --git a/drizzle/meta/0023_snapshot.json b/drizzle/meta/0023_snapshot.json new file mode 100644 index 0000000..20b38a6 --- /dev/null +++ b/drizzle/meta/0023_snapshot.json @@ -0,0 +1,5026 @@ +{ + "id": "90d5a442-3d2c-4e4b-ae86-aa34d892d339", + "prevId": "c7302dfd-ebb7-4d72-8cc7-fa900b7a4c58", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.announcements": { + "name": "announcements", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "published": { + "name": "published", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "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()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "announcements_published_created_idx": { + "name": "announcements_published_created_idx", + "columns": [ + { + "expression": "published", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "announcements_created_by_users_id_fk": { + "name": "announcements_created_by_users_id_fk", + "tableFrom": "announcements", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.app_settings": { + "name": "app_settings", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.assignment_proposals": { + "name": "assignment_proposals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "assignment_id": { + "name": "assignment_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "proposed_instance_id": { + "name": "proposed_instance_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "assignment_proposals_pending_assignment_idx": { + "name": "assignment_proposals_pending_assignment_idx", + "columns": [ + { + "expression": "assignment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"assignment_proposals\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "assignment_proposals_status_idx": { + "name": "assignment_proposals_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "assignment_proposals_assignment_id_assignments_id_fk": { + "name": "assignment_proposals_assignment_id_assignments_id_fk", + "tableFrom": "assignment_proposals", + "tableTo": "assignments", + "columnsFrom": [ + "assignment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "assignment_proposals_user_id_users_id_fk": { + "name": "assignment_proposals_user_id_users_id_fk", + "tableFrom": "assignment_proposals", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "assignment_proposals_proposed_instance_id_service_instances_id_fk": { + "name": "assignment_proposals_proposed_instance_id_service_instances_id_fk", + "tableFrom": "assignment_proposals", + "tableTo": "service_instances", + "columnsFrom": [ + "proposed_instance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "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.audit_log": { + "name": "audit_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_ip_hash": { + "name": "actor_ip_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "before_json": { + "name": "before_json", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "after_json": { + "name": "after_json", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "audit_log_created_idx": { + "name": "audit_log_created_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.bridge_sessions": { + "name": "bridge_sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "bridge_sessions_event_idx": { + "name": "bridge_sessions_event_idx", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "bridge_sessions_user_id_users_id_fk": { + "name": "bridge_sessions_user_id_users_id_fk", + "tableFrom": "bridge_sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "bridge_sessions_event_id_events_id_fk": { + "name": "bridge_sessions_event_id_events_id_fk", + "tableFrom": "bridge_sessions", + "tableTo": "events", + "columnsFrom": [ + "event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.coverage_intakes": { + "name": "coverage_intakes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "requester_name": { + "name": "requester_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requester_email": { + "name": "requester_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requester_phone": { + "name": "requester_phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ministry": { + "name": "ministry", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'coverage'" + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'new'" + }, + "created_event_id": { + "name": "created_event_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reviewed_by": { + "name": "reviewed_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reviewed_at": { + "name": "reviewed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "coverage_intakes_status_idx": { + "name": "coverage_intakes_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "coverage_intakes_starts_idx": { + "name": "coverage_intakes_starts_idx", + "columns": [ + { + "expression": "starts_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "coverage_intakes_created_event_id_events_id_fk": { + "name": "coverage_intakes_created_event_id_events_id_fk", + "tableFrom": "coverage_intakes", + "tableTo": "events", + "columnsFrom": [ + "created_event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "coverage_intakes_reviewed_by_users_id_fk": { + "name": "coverage_intakes_reviewed_by_users_id_fk", + "tableFrom": "coverage_intakes", + "tableTo": "users", + "columnsFrom": [ + "reviewed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.coverage_requests": { + "name": "coverage_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "assignment_id": { + "name": "assignment_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "replacement_user_id": { + "name": "replacement_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resolved_by": { + "name": "resolved_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "coverage_requests_pending_assignment_idx": { + "name": "coverage_requests_pending_assignment_idx", + "columns": [ + { + "expression": "assignment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"coverage_requests\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "coverage_requests_status_idx": { + "name": "coverage_requests_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "coverage_requests_requester_idx": { + "name": "coverage_requests_requester_idx", + "columns": [ + { + "expression": "requested_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "coverage_requests_assignment_id_assignments_id_fk": { + "name": "coverage_requests_assignment_id_assignments_id_fk", + "tableFrom": "coverage_requests", + "tableTo": "assignments", + "columnsFrom": [ + "assignment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "coverage_requests_requested_by_users_id_fk": { + "name": "coverage_requests_requested_by_users_id_fk", + "tableFrom": "coverage_requests", + "tableTo": "users", + "columnsFrom": [ + "requested_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "coverage_requests_replacement_user_id_users_id_fk": { + "name": "coverage_requests_replacement_user_id_users_id_fk", + "tableFrom": "coverage_requests", + "tableTo": "users", + "columnsFrom": [ + "replacement_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "coverage_requests_resolved_by_users_id_fk": { + "name": "coverage_requests_resolved_by_users_id_fk", + "tableFrom": "coverage_requests", + "tableTo": "users", + "columnsFrom": [ + "resolved_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.event_folders": { + "name": "event_folders", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'originals'" + }, + "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": { + "event_folders_event_name_idx": { + "name": "event_folders_event_name_idx", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "event_folders_event_idx": { + "name": "event_folders_event_idx", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "event_folders_event_id_events_id_fk": { + "name": "event_folders_event_id_events_id_fk", + "tableFrom": "event_folders", + "tableTo": "events", + "columnsFrom": [ + "event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "event_folders_created_by_users_id_fk": { + "name": "event_folders_created_by_users_id_fk", + "tableFrom": "event_folders", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.event_photographers": { + "name": "event_photographers", + "schema": "", + "columns": { + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'photographer'" + }, + "assigned_by": { + "name": "assigned_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assigned_at": { + "name": "assigned_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "event_photographers_user_idx": { + "name": "event_photographers_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "event_photographers_event_id_events_id_fk": { + "name": "event_photographers_event_id_events_id_fk", + "tableFrom": "event_photographers", + "tableTo": "events", + "columnsFrom": [ + "event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "event_photographers_user_id_users_id_fk": { + "name": "event_photographers_user_id_users_id_fk", + "tableFrom": "event_photographers", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "event_photographers_assigned_by_users_id_fk": { + "name": "event_photographers_assigned_by_users_id_fk", + "tableFrom": "event_photographers", + "tableTo": "users", + "columnsFrom": [ + "assigned_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "event_photographers_pk": { + "name": "event_photographers_pk", + "columns": [ + "event_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.event_photos": { + "name": "event_photos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uploader_id": { + "name": "uploader_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stored_name": { + "name": "stored_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "checksum_sha256": { + "name": "checksum_sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "edit_json": { + "name": "edit_json", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "advanced_edit_json": { + "name": "advanced_edit_json", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "edited_stored_name": { + "name": "edited_stored_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "edited_size_bytes": { + "name": "edited_size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "edited_at": { + "name": "edited_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "edited_by": { + "name": "edited_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "event_photos_folder_checksum_idx": { + "name": "event_photos_folder_checksum_idx", + "columns": [ + { + "expression": "folder_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checksum_sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "event_photos_folder_idx": { + "name": "event_photos_folder_idx", + "columns": [ + { + "expression": "folder_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "event_photos_folder_id_event_folders_id_fk": { + "name": "event_photos_folder_id_event_folders_id_fk", + "tableFrom": "event_photos", + "tableTo": "event_folders", + "columnsFrom": [ + "folder_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "event_photos_uploader_id_users_id_fk": { + "name": "event_photos_uploader_id_users_id_fk", + "tableFrom": "event_photos", + "tableTo": "users", + "columnsFrom": [ + "uploader_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "event_photos_edited_by_users_id_fk": { + "name": "event_photos_edited_by_users_id_fk", + "tableFrom": "event_photos", + "tableTo": "users", + "columnsFrom": [ + "edited_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "event_photos_stored_name_unique": { + "name": "event_photos_stored_name_unique", + "nullsNotDistinct": false, + "columns": [ + "stored_name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.event_videos": { + "name": "event_videos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uploader_id": { + "name": "uploader_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "checksum_sha256": { + "name": "checksum_sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "original_stored_name": { + "name": "original_stored_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "archive_folder": { + "name": "archive_folder", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "trim_start_ms": { + "name": "trim_start_ms", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "trim_end_ms": { + "name": "trim_end_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "web_stored_name": { + "name": "web_stored_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "poster_stored_name": { + "name": "poster_stored_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'processing'" + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'team'" + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp with time zone", + "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": true, + "default": "now()" + } + }, + "indexes": { + "event_videos_event_checksum_idx": { + "name": "event_videos_event_checksum_idx", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checksum_sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "event_videos_event_created_idx": { + "name": "event_videos_event_created_idx", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "event_videos_status_idx": { + "name": "event_videos_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "event_videos_event_id_events_id_fk": { + "name": "event_videos_event_id_events_id_fk", + "tableFrom": "event_videos", + "tableTo": "events", + "columnsFrom": [ + "event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "event_videos_uploader_id_users_id_fk": { + "name": "event_videos_uploader_id_users_id_fk", + "tableFrom": "event_videos", + "tableTo": "users", + "columnsFrom": [ + "uploader_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "event_videos_original_stored_name_unique": { + "name": "event_videos_original_stored_name_unique", + "nullsNotDistinct": false, + "columns": [ + "original_stored_name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.events": { + "name": "events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'photoshoot'" + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "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()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "events_starts_at_idx": { + "name": "events_starts_at_idx", + "columns": [ + { + "expression": "starts_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "events_created_by_idx": { + "name": "events_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "events_created_by_users_id_fk": { + "name": "events_created_by_users_id_fk", + "tableFrom": "events", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "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.notification_rules": { + "name": "notification_rules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event": { + "name": "event", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'assignment.created'" + }, + "offset_days": { + "name": "offset_days", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "send_at_local_time": { + "name": "send_at_local_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'09:00'" + }, + "channel_set": { + "name": "channel_set", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'email'" + }, + "applies_to_service_id": { + "name": "applies_to_service_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "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": { + "notification_rules_active_idx": { + "name": "notification_rules_active_idx", + "columns": [ + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "notification_rules_applies_to_service_id_services_id_fk": { + "name": "notification_rules_applies_to_service_id_services_id_fk", + "tableFrom": "notification_rules", + "tableTo": "services", + "columnsFrom": [ + "applies_to_service_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "notification_rules_key_unique": { + "name": "notification_rules_key_unique", + "nullsNotDistinct": false, + "columns": [ + "key" + ] + } + }, + "policies": {}, + "checkConstraints": { + "chk_notification_rules_channel": { + "name": "chk_notification_rules_channel", + "value": "\"notification_rules\".\"channel_set\" IN ('email','sms','email+sms')" + } + }, + "isRLSEnabled": false + }, + "public.notifications": { + "name": "notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'email'" + }, + "template_key": { + "name": "template_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rule_key": { + "name": "rule_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assignment_id": { + "name": "assignment_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slot_id": { + "name": "slot_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "to_address": { + "name": "to_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload_json": { + "name": "payload_json", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "dedupe_key": { + "name": "dedupe_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scheduled_for": { + "name": "scheduled_for", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_status": { + "name": "provider_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "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 + } + }, + "indexes": { + "notifications_status_scheduled_idx": { + "name": "notifications_status_scheduled_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_for", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "notifications_user_idx": { + "name": "notifications_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "notifications_assignment_idx": { + "name": "notifications_assignment_idx", + "columns": [ + { + "expression": "assignment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "notifications_user_id_users_id_fk": { + "name": "notifications_user_id_users_id_fk", + "tableFrom": "notifications", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_assignment_id_assignments_id_fk": { + "name": "notifications_assignment_id_assignments_id_fk", + "tableFrom": "notifications", + "tableTo": "assignments", + "columnsFrom": [ + "assignment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "notifications_slot_id_slots_id_fk": { + "name": "notifications_slot_id_slots_id_fk", + "tableFrom": "notifications", + "tableTo": "slots", + "columnsFrom": [ + "slot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "notifications_dedupe_key_unique": { + "name": "notifications_dedupe_key_unique", + "nullsNotDistinct": false, + "columns": [ + "dedupe_key" + ] + } + }, + "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.run_sheet_items": { + "name": "run_sheet_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "service_instance_id": { + "name": "service_instance_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "time_label": { + "name": "time_label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner": { + "name": "owner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "run_sheet_items_instance_idx": { + "name": "run_sheet_items_instance_idx", + "columns": [ + { + "expression": "service_instance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "run_sheet_items_service_instance_id_service_instances_id_fk": { + "name": "run_sheet_items_service_instance_id_service_instances_id_fk", + "tableFrom": "run_sheet_items", + "tableTo": "service_instances", + "columnsFrom": [ + "service_instance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.service_checklist_items": { + "name": "service_checklist_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "service_instance_id": { + "name": "service_instance_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phase": { + "name": "phase", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pre'" + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "done_at": { + "name": "done_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "done_by": { + "name": "done_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "service_checklist_instance_label_idx": { + "name": "service_checklist_instance_label_idx", + "columns": [ + { + "expression": "service_instance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "phase", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "label", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "service_checklist_instance_idx": { + "name": "service_checklist_instance_idx", + "columns": [ + { + "expression": "service_instance_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "phase", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "service_checklist_items_service_instance_id_service_instances_id_fk": { + "name": "service_checklist_items_service_instance_id_service_instances_id_fk", + "tableFrom": "service_checklist_items", + "tableTo": "service_instances", + "columnsFrom": [ + "service_instance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "service_checklist_items_done_by_users_id_fk": { + "name": "service_checklist_items_done_by_users_id_fk", + "tableFrom": "service_checklist_items", + "tableTo": "users", + "columnsFrom": [ + "done_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "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.service_run_sheets": { + "name": "service_run_sheets", + "schema": "", + "columns": { + "service_instance_id": { + "name": "service_instance_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "speaker": { + "name": "speaker", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sermon_title": { + "name": "sermon_title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stream_url": { + "name": "stream_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slides_url": { + "name": "slides_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "service_run_sheets_service_instance_id_service_instances_id_fk": { + "name": "service_run_sheets_service_instance_id_service_instances_id_fk", + "tableFrom": "service_run_sheets", + "tableTo": "service_instances", + "columnsFrom": [ + "service_instance_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "service_run_sheets_updated_by_users_id_fk": { + "name": "service_run_sheets_updated_by_users_id_fk", + "tableFrom": "service_run_sheets", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "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.training_lessons": { + "name": "training_lessons", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "published": { + "name": "published", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "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": { + "training_lessons_published_idx": { + "name": "training_lessons_published_idx", + "columns": [ + { + "expression": "published", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.training_resources": { + "name": "training_resources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "lesson_id": { + "name": "lesson_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stored_name": { + "name": "stored_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "training_resources_lesson_idx": { + "name": "training_resources_lesson_idx", + "columns": [ + { + "expression": "lesson_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "training_resources_lesson_id_training_lessons_id_fk": { + "name": "training_resources_lesson_id_training_lessons_id_fk", + "tableFrom": "training_resources", + "tableTo": "training_lessons", + "columnsFrom": [ + "lesson_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "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.used_magic_tokens": { + "name": "used_magic_tokens", + "schema": "", + "columns": { + "jti": { + "name": "jti", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.used_tokens": { + "name": "used_tokens", + "schema": "", + "columns": { + "jti": { + "name": "jti", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "assignment_id": { + "name": "assignment_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "used_tokens_assignment_id_assignments_id_fk": { + "name": "used_tokens_assignment_id_assignments_id_fk", + "tableFrom": "used_tokens", + "tableTo": "assignments", + "columnsFrom": [ + "assignment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "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 + }, + "mentor_approved_at": { + "name": "mentor_approved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "mentor_approved_by": { + "name": "mentor_approved_by", + "type": "text", + "primaryKey": false, + "notNull": 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 + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "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'" + }, + "calendar_feed_token": { + "name": "calendar_feed_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "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_key": { + "name": "users_email_lower_key", + "columns": [ + { + "expression": "lower(\"email\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_username_lower_key": { + "name": "users_username_lower_key", + "columns": [ + { + "expression": "lower(\"username\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_calendar_feed_token_key": { + "name": "users_calendar_feed_token_key", + "columns": [ + { + "expression": "calendar_feed_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "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 ff9f43c..351724e 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -162,6 +162,13 @@ "when": 1795223283100, "tag": "0022_fixed_squadron_supreme", "breakpoints": true + }, + { + "idx": 23, + "version": "7", + "when": 1795274972891, + "tag": "0023_assignment_proposals", + "breakpoints": true } ] } \ No newline at end of file diff --git a/e2e/events.spec.ts b/e2e/events.spec.ts index e9185a1..33cf3df 100644 --- a/e2e/events.spec.ts +++ b/e2e/events.spec.ts @@ -129,21 +129,18 @@ test.describe("event photo sharing", () => { await page.getByLabel("Exposure").focus(); await page.getByLabel("Exposure").press("ArrowRight"); await page.getByRole("button", { name: "Save edited JPEG" }).click(); - await expect(page.getByText("Full-resolution JPEG saved.")).toBeVisible({ - timeout: 30_000, - }); + // A successful save closes the editor and returns to the refreshed gallery. + await expect(page.getByRole("dialog")).toBeHidden({ timeout: 30_000 }); + await expect(page.getByText("Edited", { exact: true })).toBeVisible(); const [download] = await Promise.all([ page.waitForEvent("download"), - page.getByRole("link", { name: "Download edited JPEG" }).click(), + page.getByRole("link", { name: "Download edited" }).click(), ]); expect(download.suggestedFilename()).toBe("photo-edited.jpg"); const edited = await readFile((await download.path())!); expect(edited.subarray(0, 3).toString("hex")).toBe("ffd8ff"); expect(edited.equals(PHOTO)).toBe(false); - - await page.getByRole("button", { name: "Close photo editor" }).click(); - await expect(page.getByText("Edited", { exact: true })).toBeVisible(); await expect(page.locator(`img[alt="${PHOTO_NAME}"]`)).toHaveAttribute( "src", /variant=edited/, diff --git a/public/training/media-team-admin-guide.pdf b/public/training/media-team-admin-guide.pdf index 1f7d83a..830e0b3 100644 Binary files a/public/training/media-team-admin-guide.pdf and b/public/training/media-team-admin-guide.pdf differ diff --git a/public/training/media-team-coordinator-guide.pdf b/public/training/media-team-coordinator-guide.pdf new file mode 100644 index 0000000..c788132 Binary files /dev/null and b/public/training/media-team-coordinator-guide.pdf differ diff --git a/public/training/media-team-user-guide.pdf b/public/training/media-team-user-guide.pdf index 8ecaec4..dbfc0e5 100644 Binary files a/public/training/media-team-user-guide.pdf and b/public/training/media-team-user-guide.pdf differ diff --git a/src/app/(app)/coverage/page.tsx b/src/app/(app)/coverage/page.tsx index f66fa75..7e588a3 100644 --- a/src/app/(app)/coverage/page.tsx +++ b/src/app/(app)/coverage/page.tsx @@ -4,7 +4,11 @@ import { Download, Printer } from "lucide-react"; import { auth } from "@/auth/config"; import { hasPermission } from "@/auth/permissions"; import type { SystemRole } from "@/auth/roles"; -import { listPendingCoverageRequests } from "@/db/coverage"; +import { + listPendingAlternativeProposals, + listPendingCoverageRequests, +} from "@/db/coverage"; +import { CHURCH_TIMEZONE, formatInTimezone } from "@/lib/tz"; import { listCoverageIntakes } from "@/db/intake"; import { rankedCandidatesForSlot } from "@/db/rankedCandidates"; import { Button } from "@/components/ui/button"; @@ -24,9 +28,10 @@ export default async function CoveragePage() { if (!user?.id) return null; if (!hasPermission(user.systemRole, "schedule.publish")) redirect("/home"); - const [requests, intakes] = await Promise.all([ + const [requests, intakes, alternatives] = await Promise.all([ listPendingCoverageRequests(), listCoverageIntakes("new"), + listPendingAlternativeProposals(), ]); const views: CoverageRequestView[] = await Promise.all( @@ -96,6 +101,60 @@ export default async function CoveragePage() { + {alternatives.length > 0 && ( +
+
+

Proposed another Sunday

+

+ These volunteers cannot serve their proposed date but offered an + alternative. Reassign them from the schedule, then clear the seat. +

+
+ +
+ )} +

Share the public request form at{" "} diff --git a/src/app/(app)/training/guides/admin/page.tsx b/src/app/(app)/training/guides/admin/page.tsx index a9a57a6..7672691 100644 --- a/src/app/(app)/training/guides/admin/page.tsx +++ b/src/app/(app)/training/guides/admin/page.tsx @@ -109,10 +109,13 @@ export default function AdminGuidePage() { />

- New service instances start as drafts. Volunteers only see the - week, and only receive assignment email, after you publish it. A - draft is safe to edit; a published week should be changed carefully - because people have already been told about it. + New service instances start as drafts, and volunteers do not see a + draft on their schedule. Assigning a seat still sends the proposed + email immediately so the volunteer can accept, decline, or propose + another Sunday. Publishing makes the week visible and queues the + published/reminder mail for every live assignment. A draft is safe + to edit; a published week should be changed carefully because people + have already been told about it.

@@ -374,7 +377,9 @@ export default function AdminGuidePage() { Press Publish when the week is ready. Publishing - queues assignment email and reminder rules for that instance. + makes the week visible and queues the published/reminder mail for + live assignments. Assignments made later still send their proposed + email immediately. Unpublish only when you intend to withdraw the week; volunteers may @@ -443,6 +448,20 @@ export default function AdminGuidePage() {

+

+ Volunteers who propose another Sunday +

+

+ The proposed email also offers Propose another Sunday. + That link records a pending proposal for a coordinator but leaves the + original assignment live, so the seat remains covered while you + decide. Pending proposals appear on Coverage under{" "} + Proposed another Sunday. This queue is read-only for + now: review the date and note, then change the schedule yourself + (assign a replacement or clear the seat) and confirm the change with + the volunteer. +

+

Requests from outside the team

Ministry leaders can submit the public form at{" "} @@ -704,12 +723,14 @@ export default function AdminGuidePage() { admins can remove them. - +

- The Platform administration guide and the Volunteer guide appear at - the top of Training as web pages with screenshots and as downloadable - PDFs. They are documentation for this deployment, not editable - lessons, so they stay consistent for every admin. + Training shows the guide for the signed-in role: the Platform + administration guide for admins, the Coordinator guide for + coordinators, and the Volunteer guide for volunteers and trainees. + The admin and volunteer guides also have downloadable PDFs. These + are documentation for this deployment, not editable lessons, so they + stay consistent for everyone.

diff --git a/src/app/(app)/training/guides/coordinator/page.tsx b/src/app/(app)/training/guides/coordinator/page.tsx new file mode 100644 index 0000000..55b089e --- /dev/null +++ b/src/app/(app)/training/guides/coordinator/page.tsx @@ -0,0 +1,393 @@ +import type { Metadata } from "next"; +import { + GuideCallout, + GuideFields, + GuideFigure, + GuideSection, + GuideShell, + GuideStep, + GuideSteps, +} from "@/components/app/training/guide"; + +export const metadata: Metadata = { + title: "Coordinator guide", +}; + +const SECTIONS = [ + { id: "role", title: "Your coordinator role" }, + { id: "week", title: "Build and publish a week" }, + { id: "replies", title: "Assignment emails and replies" }, + { id: "coverage", title: "Coverage and swaps" }, + { id: "run-sheets", title: "Run sheets" }, + { id: "events", title: "Events and media" }, + { id: "announcements", title: "Announcements and training" }, + { id: "exports", title: "Print and CSV exports" }, + { id: "troubleshooting", title: "Troubleshooting" }, +]; + +export default function CoordinatorGuidePage() { + return ( + + +

+ Coordinators run the week. You can edit and publish the schedule, + handle coverage and swaps, edit run sheets, manage events, author + announcements, and use the print and CSV exports. You do not need the + Admin tab for any of that. +

+ + +
+ + +

+ The week view is the only editable schedule lens. Month and year are + read-only overviews. A week starts as a draft; publishing makes it + visible to volunteers and starts the published/reminder mail. +

+ + + + Open Schedule and use the arrows to reach the week + you are building. + + + Press an empty seat and choose a volunteer. The candidate list is + ranked by skills, availability, and conflicts. + + + Use Auto-fill for a first pass over open seats, then + review every suggestion. The ranking does not know the relational + context or the last-minute holiday. + + + Read any conflict before saving. A hard conflict blocks the + assignment; a soft warning, such as exceeding a monthly cap, can be + overridden. + + + Press Publish when the week is ready. Publishing + makes the schedule visible and queues the published/reminder mail for + the people already on it. + + + +

+ A proposed assignment sends its “Can you serve on …?” email as soon + as you create it, even while the week is still a draft. Publishing + does not send that email again; it adds the published/reminder mail + for seats that are already filled. Draft weeks stay hidden from the + volunteer schedule until you publish. +

+
+
+ + +

+ Every proposed seat gets an email with three single-use links. The + volunteer does not need an account or a login to use them. +

+ +

+ Links are good for 14 days and work once. If a volunteer says the link + expired or was already used, do not forward someone else’s link; ask an + admin to help with the account or create the assignment again. +

+ +

+ The subject reads “Can you serve on [position] — [date]?” and the + body shows the service, call time, and location, followed by the + three buttons. The same reply buttons also appear on the{" "} + /respond page the link opens. +

+
+
+ + +

+ Coverage is the working queue for changes. A pending request never + removes the volunteer: they stay responsible until you approve a + replacement or release the seat. +

+ +

Handle a swap request

+ + + Open Coverage and read the volunteer, seat, date, + and reason. + + + Review the ranked replacements and their warnings. Pick someone who + fits the skills and availability, not just the top score. + + + Choose Approve with replacement to cancel the + original assignment and place the replacement as proposed. The new + person receives the same accept/decline/propose email. + + + Choose Approve and release when nobody can take it. + The seat becomes open and the original assignment is kept in history. + + + Choose Decline when the request should not be + granted; the original volunteer stays on the seat. + + + +

+ Volunteers who propose another Sunday +

+

+ Proposals from the assignment email appear on Coverage under{" "} + Proposed another Sunday. The queue is read-only: it + records the volunteer, the current date, the proposed date, and any + note. Review it, then make the change yourself — assign a replacement, + move the seat, or clear it — and confirm the arrangement with the + volunteer. The original assignment stays live until you do. +

+ +

+ Requests from outside the team +

+

+ Ministry leaders can submit the public form at{" "} + /request-coverage without an account. Accepted requests + become events: choose Create event to open one with + the requester and ministry attached, or Decline if it + is not a fit. +

+
+ + +

+ Every service instance has one run sheet: speaker, message title, + stream and slides links, team notes, an ordered cue list, and a + pre/post checklist. Coordinators edit the details and cues; every + signed-in volunteer can tick checklist items. +

+ + + + Open the run sheet from the schedule, Dashboard, or your own + next-serve card. + + + Fill in speaker, message title, stream link, slides link, and team + notes, then press Save details. + + + Edit cues inline and save each row. Add a cue at the bottom when the + service needs one. + + + Add pre-service or post-service checklist items for this service. + Defaults are seeded only once, so your edits stick. + + + Press Print for a clean booth copy. + + +
+ + +

+ Events cover photoshoots, weddings, outreach nights, and other + coverage outside the weekly services. As a coordinator you see every + event and can assign photographers and editors; assigned volunteers see + only their events. +

+ + + + Create the event with its date, time, location, and brief, or create + one from an accepted outside coverage request. + + + Assign the photographers and editors. Only assigned people and + managers can open the event and its files. + + + Create folders for originals and edited exports so the handoff is + obvious. + + + After the event, confirm the selects are uploaded and the folder is + ready. Archive the event when the work is finished; archived events + stay readable but stop accepting uploads. + + + +

+ Event originals are stored on the configured church media share, not + in the database. The Media page is a convenience view and still + follows event assignment, so do not treat a copied link as public. +

+
+
+ + +

+ Coordinators can write announcements. Training lessons are authored by + admins, but everyone can read the published lessons and the guide for + their role. +

+ + + Open Announcements and write a title and plain-text + message. + + + Keep Published ticked, or untick it to save a draft. + + + Use the row actions to publish, unpublish, or delete a post. + + + Open Training to read the coordinator guide and the + published lessons. If a lesson needs a correction, ask an admin. + + + +

+ Training shows the guide for your role. Admins see the Platform + administration guide, coordinators see this guide, and volunteers and + trainees see the Volunteer guide. +

+
+
+ + + + + + + + +
+ ); +} diff --git a/src/app/(app)/training/guides/page.tsx b/src/app/(app)/training/guides/page.tsx new file mode 100644 index 0000000..a1ee175 --- /dev/null +++ b/src/app/(app)/training/guides/page.tsx @@ -0,0 +1,12 @@ +import { redirect } from "next/navigation"; +import { auth } from "@/auth/config"; +import type { SystemRole } from "@/auth/roles"; +import { trainingGuideForRole } from "@/lib/training-guides"; + +/** `/training/guides` opens the guide for the signed-in person's role. */ +export default async function TrainingGuidesPage() { + const session = await auth(); + const role = (session?.user as { systemRole?: SystemRole } | undefined) + ?.systemRole; + redirect(trainingGuideForRole(role).href); +} diff --git a/src/app/(app)/training/guides/user/page.tsx b/src/app/(app)/training/guides/user/page.tsx index dda6951..93b439b 100644 --- a/src/app/(app)/training/guides/user/page.tsx +++ b/src/app/(app)/training/guides/user/page.tsx @@ -128,6 +128,15 @@ export default function VolunteerGuidePage() { the top for the two things volunteers change most often.
+ +

+ A proposed seat arrives by email with three links:{" "} + Confirm, Can’t make it, and{" "} + Propose another Sunday. No login is needed and each + link works once. If you propose another Sunday, the coordinator sees + the request but the seat stays yours until they change it. +

+

- A week that has not been published does not appear on your schedule - and does not generate assignment email. If you expected a date and - cannot see it, the week is probably still a draft. + A week that has not been published does not appear on your schedule. + Assigning a seat can still send you a proposed email while the week + is a draft, so reply to that email even if the date is not on the + schedule yet. Publishing is what makes the week visible and triggers + the published and reminder mail.

@@ -258,6 +269,14 @@ export default function VolunteerGuidePage() { You will see the change on Home once it is resolved.

+

Propose another Sunday

+

+ If you cannot serve the date but could serve a different Sunday, use{" "} + Propose another Sunday in the assignment email (or the + alternative link on the respond page). Tell the coordinator which date + works and why. This does not release the original seat: it stays yours + until a coordinator acts on the proposal and confirms the change. +

Ministry leaders outside the team can request coverage through the public form at /request-coverage. If you are asked to @@ -395,24 +414,24 @@ export default function VolunteerGuidePage() {

Open Training from the navigation. - Read the Volunteer guide once end to end; it covers - every screen in this app. + Read the guide at the top of the page once end to end; it is chosen + for your role and covers every screen you can use. Open an attachment to read or download it. Links open in a new tab so you do not lose your place. - Use the PDF download on either guide for an offline copy you can keep - on your phone. + Use the PDF download when the guide offers one, or print the page for + an offline copy you can keep on your phone. diff --git a/src/app/(app)/training/page.tsx b/src/app/(app)/training/page.tsx index 123957d..9128a98 100644 --- a/src/app/(app)/training/page.tsx +++ b/src/app/(app)/training/page.tsx @@ -4,20 +4,36 @@ import { hasPermission } from "@/auth/permissions"; import type { SystemRole } from "@/auth/roles"; import { listLessons } from "@/db/training"; import { trainingBodyToHtml } from "@/lib/rich-text"; +import { trainingGuideForRole } from "@/lib/training-guides"; import { TrainingPanel } from "@/components/app/training-panel"; -import { BookOpenCheck, Download, ShieldCheck, UserRound } from "lucide-react"; +import { + BookOpenCheck, + ClipboardList, + Download, + ShieldCheck, + UserRound, +} from "lucide-react"; export const metadata = { title: "Training" }; /** * Training content. Volunteers see published lessons and attachments; admins - * can author, publish, upload, and delete. Content is stored in Postgres and + * can author, publish, upload, and delete. The full guide shown at the top is + * chosen from the signed-in person's role. Content is stored in Postgres and * attachments under the uploads volume, so it is editable with no deploy. */ export default async function TrainingPage() { const session = await auth(); - const role = (session?.user as { systemRole?: SystemRole } | undefined)?.systemRole; + const role = (session?.user as { systemRole?: SystemRole } | undefined) + ?.systemRole; const canEdit = hasPermission(role, "training.author"); + const guide = trainingGuideForRole(role); + const GuideIcon = + guide.key === "admin" + ? ShieldCheck + : guide.key === "coordinator" + ? ClipboardList + : UserRound; const lessons = (await listLessons({ includeUnpublished: canEdit })).map( (lesson) => ({ ...lesson, @@ -36,67 +52,37 @@ export default async function TrainingPage() {

- Full guides + Your guide

- Complete, illustrated walkthroughs with screenshots. Read them here - or download the PDF for printing and offline use. + The complete, illustrated walkthrough for your role. Read it here or + download the PDF where one is available.

-
-
-
-
-

- Platform administration guide -

-

- People and access, skill verification, positions, services and - publishing, coverage, run sheets, email, notifications, backups, - and exports. -

-
- -
+
+
+
- -
-
-
-

Volunteer guide

-

- Signing in, your next serve, the schedule, availability, swaps, - run sheets, events and media, training, profile, and reminders. -

-
- -
diff --git a/src/app/api/assignments/[id]/respond/route.ts b/src/app/api/assignments/[id]/respond/route.ts index e0d0b9f..eb17774 100644 --- a/src/app/api/assignments/[id]/respond/route.ts +++ b/src/app/api/assignments/[id]/respond/route.ts @@ -8,11 +8,13 @@ const bodySchema = z.object({ action: z.enum(["confirm", "decline"]) }); function errorStatus(code: RespondError["code"]): number { switch (code) { case "unknown_assignment": + case "unknown_instance": return 404; case "wrong_volunteer": return 403; case "not_actionable": case "already_used": + case "invalid_alternative": return 409; } } diff --git a/src/app/api/assignments/route.ts b/src/app/api/assignments/route.ts index 82ea2d3..31591b4 100644 --- a/src/app/api/assignments/route.ts +++ b/src/app/api/assignments/route.ts @@ -2,6 +2,7 @@ import { NextRequest } from "next/server"; import { z } from "zod"; import { and, eq, inArray } from "drizzle-orm"; import { auth } from "@/auth/config"; +import { requestOrigin } from "@/auth/magic-link"; import { AuthError, requirePermission } from "@/auth/permissions"; import type { SystemRole } from "@/auth/roles"; import { db } from "@/db"; @@ -16,8 +17,10 @@ import { AssignFactError, resolveAssignFacts, } from "@/db/assignments"; -import { cancelAssignmentNotifications } from "@/db/outbox"; -import { enqueuePublishNotifications } from "@/db/outbox"; +import { + cancelAssignmentNotifications, + enqueueAssignmentProposed, +} from "@/db/outbox"; import { enqueueRemindersForInstance } from "@/db/reminders"; import { classifyConflicts, hardConflicts } from "@/domain/conflicts"; import { uuidv7 } from "@/lib/uuid"; @@ -195,6 +198,8 @@ export const POST = async (req: NextRequest) => { .limit(1); const assignmentId = uuidv7(); + const now = new Date(); + const appOrigin = requestOrigin(req); await db.transaction(async (tx) => { await tx.insert(assignments).values({ id: assignmentId, @@ -203,7 +208,7 @@ export const POST = async (req: NextRequest) => { status: "proposed", source: "manual", assignedBy: actorId, - assignedAt: new Date(), + assignedAt: now, }); await tx .update(slots) @@ -224,12 +229,12 @@ export const POST = async (req: NextRequest) => { }), ); - // A published week's mail is written at publish time; a seat added later - // would otherwise never be announced. Both enqueues are idempotent on - // dedupe_key, so existing rows are untouched. + // The proposed email always goes out, whether the week is draft or + // published: the volunteer has to accept, decline, or propose another + // Sunday. On a published week only the reminders need topping up. + await enqueueAssignmentProposed(tx, assignmentId, { now, appOrigin }); if (instance?.status === "published") { - await enqueuePublishNotifications(tx, instance.id, { now: new Date() }); - await enqueueRemindersForInstance(tx, instance.id, { now: new Date() }); + await enqueueRemindersForInstance(tx, instance.id, { now, appOrigin }); } }); diff --git a/src/app/api/dev/magic-link/route.ts b/src/app/api/dev/magic-link/route.ts index d856765..392a91d 100644 --- a/src/app/api/dev/magic-link/route.ts +++ b/src/app/api/dev/magic-link/route.ts @@ -7,6 +7,7 @@ import { requestOrigin, } from "@/auth/magic-link"; import { rateLimit } from "@/lib/rate-limit"; +import { hasPasswordProtectedAdmin } from "@/db/users"; const JSON_HEADERS = { "content-type": "application/json" }; const bodySchema = z.object({ email: z.string().email() }); @@ -59,11 +60,29 @@ export const POST = async (req: NextRequest) => { ); } + // Bootstrap only. Once an admin has a real password, a public request for + // that admin's email must not mint a session link. New-account and recovery + // links are still issued by signed-in admins from the People panel. + if (await hasPasswordProtectedAdmin()) { + return new Response( + JSON.stringify({ + error: + "Use your username and password to sign in. Contact an admin if you need help.", + }), + { status: 403, headers: JSON_HEADERS }, + ); + } + try { const result = await requestMagicLink(parsed.data.email, { origin: requestOrigin(req), }); - return new Response(JSON.stringify(result), { + // Never expose account metadata to an unauthenticated caller. The dev + // transport may still return the URL for local bootstrap/tests; production + // turns that transport off and the login UI never renders a URL anyway. + const payload: { ok: true; url?: string } = { ok: true }; + if ("url" in result && result.url) payload.url = result.url; + return new Response(JSON.stringify(payload), { status: 200, headers: JSON_HEADERS, }); diff --git a/src/app/api/respond/alternative/route.ts b/src/app/api/respond/alternative/route.ts new file mode 100644 index 0000000..60fc3ba --- /dev/null +++ b/src/app/api/respond/alternative/route.ts @@ -0,0 +1,110 @@ +import { NextRequest } from "next/server"; +import { z } from "zod"; +import { clientIp } from "@/auth/api"; +import { RespondError, applyAlternativeProposal } from "@/db/respond"; +import { verifyRespondToken } from "@/lib/respond"; +import { rateLimit } from "@/lib/rate-limit"; + +const JSON_HEADERS = { "content-type": "application/json" }; + +const bodySchema = z.object({ + token: z.string().min(1), + instanceId: z.string().min(1), + note: z.string().max(500).optional(), +}); + +/** Map a refused proposal to its HTTP status. */ +function errorStatus(code: RespondError["code"]): number { + switch (code) { + case "unknown_assignment": + case "unknown_instance": + return 404; + case "wrong_volunteer": + return 403; + case "not_actionable": + case "already_used": + case "invalid_alternative": + return 409; + } +} + +/** + * POST /api/respond/alternative — { token, instanceId, note? } + * + * The no-login "propose another Sunday" endpoint. The token must be an + * `alternative` link; its `jti` is consumed exactly once, so the same email + * link cannot file two proposals. The assignment itself is left live for a + * coordinator to reassign. + */ +export const POST = async (req: NextRequest) => { + const parsed = bodySchema.safeParse(await req.json().catch(() => null)); + if (!parsed.success) { + return new Response( + JSON.stringify({ error: "a token and service date are required" }), + { status: 400, headers: JSON_HEADERS }, + ); + } + + const limit = rateLimit(`respond-alternative:${clientIp(req)}`, 30, 60_000); + if (!limit.ok) { + return new Response( + JSON.stringify({ + error: "too many attempts; try again shortly", + code: "RATE_LIMITED", + }), + { + status: 429, + headers: { + ...JSON_HEADERS, + "retry-after": String(limit.retryAfterSeconds), + }, + }, + ); + } + + const payload = await verifyRespondToken(parsed.data.token); + if (!payload) { + return new Response( + JSON.stringify({ + error: "this link is invalid or has expired", + code: "invalid_token", + }), + { status: 400, headers: JSON_HEADERS }, + ); + } + if (payload.action !== "alternative") { + return new Response( + JSON.stringify({ + error: "this link is for a different action", + code: "action_mismatch", + }), + { status: 400, headers: JSON_HEADERS }, + ); + } + + try { + const result = await applyAlternativeProposal({ + assignmentId: payload.assignmentId, + userId: payload.userId, + jti: payload.jti, + proposedInstanceId: parsed.data.instanceId, + note: parsed.data.note ?? null, + }); + return new Response(JSON.stringify({ ok: true, ...result }), { + status: 200, + headers: JSON_HEADERS, + }); + } catch (e) { + if (e instanceof RespondError) { + return new Response( + JSON.stringify({ error: e.message, code: e.code }), + { status: errorStatus(e.code), headers: JSON_HEADERS }, + ); + } + console.error("[respond-alternative] ERROR", e); + return new Response(JSON.stringify({ error: "failed to save the proposal" }), { + status: 500, + headers: JSON_HEADERS, + }); + } +}; diff --git a/src/app/api/respond/route.ts b/src/app/api/respond/route.ts index 8204e73..d515dac 100644 --- a/src/app/api/respond/route.ts +++ b/src/app/api/respond/route.ts @@ -17,8 +17,10 @@ function errorStatus(code: RespondError["code"]): number { switch (code) { case "already_used": case "not_actionable": + case "invalid_alternative": return 409; case "unknown_assignment": + case "unknown_instance": return 404; case "wrong_volunteer": return 403; diff --git a/src/app/login/login-form.tsx b/src/app/login/login-form.tsx new file mode 100644 index 0000000..f0a0e5d --- /dev/null +++ b/src/app/login/login-form.tsx @@ -0,0 +1,191 @@ +"use client"; + +import { useState } from "react"; +import { signIn } from "next-auth/react"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; +import { Label } from "@/components/ui/label"; + +/** + * Sign in with username/password. The email-link form is only available while + * the deployment has no password-protected admin (first-run bootstrap). It + * never renders a sign-in URL, even when the dev console transport returns one. + */ +export function LoginForm({ magicLinkEnabled }: { magicLinkEnabled: boolean }) { + const [login, setLogin] = useState(""); + const [password, setPassword] = useState(""); + const [passwordStatus, setPasswordStatus] = useState<{ + kind: "idle" | "signing" | "error"; + message?: string; + }>({ kind: "idle" }); + + const [email, setEmail] = useState(""); + const [linkStatus, setLinkStatus] = useState<{ + kind: "idle" | "sending" | "sent" | "error"; + message?: string; + }>({ kind: "idle" }); + + async function onPasswordSubmit(e: React.FormEvent) { + e.preventDefault(); + setPasswordStatus({ kind: "signing" }); + try { + const result = await signIn("password", { + login, + password, + redirect: false, + }); + if (!result || result.error) { + setPasswordStatus({ + kind: "error", + message: "That username or password did not match an active account.", + }); + return; + } + // Full navigation lets the server layout read the new session cookie. + window.location.assign("/schedule"); + } catch { + setPasswordStatus({ kind: "error", message: "Network error." }); + } + } + + async function onLinkSubmit(e: React.FormEvent) { + e.preventDefault(); + setLinkStatus({ kind: "sending" }); + try { + const res = await fetch("/api/dev/magic-link", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ email }), + }); + const body = (await res.json().catch(() => ({}))) as { error?: string }; + if (res.ok) { + setLinkStatus({ kind: "sent" }); + } else { + setLinkStatus({ + kind: "error", + message: body.error ?? "Something went wrong.", + }); + } + } catch { + setLinkStatus({ kind: "error", message: "Network error." }); + } + } + + return ( +
+
+
+

+ Glenloch Baptist Church +

+

+ Media Team Hub +

+
+ + + Sign in + + {magicLinkEnabled + ? "Use your username and password, or request a one-time email link." + : "Sign in with your username and password. Contact a media team admin if you need help."} + + + +
+
+ + setLogin(e.target.value)} + placeholder="you@church.local" + /> +
+
+ + setPassword(e.target.value)} + /> +
+ + {passwordStatus.kind === "error" && passwordStatus.message && ( +

+ {passwordStatus.message} +

+ )} +
+ + {magicLinkEnabled && ( + <> +
+ + or + +
+ +
+ + setEmail(e.target.value)} + placeholder="you@church.local" + /> + + {linkStatus.kind === "sent" && ( +

+ If that address belongs to an active account, a single-use + sign-in link has been sent. It expires in 10 minutes. +

+ )} + {linkStatus.kind === "error" && linkStatus.message && ( +

+ {linkStatus.message} +

+ )} +
+ +

+ First time here? The magic link will ask you to set a username + and password. If you are locked out, ask an admin for a reset + link. +

+ + )} +
+
+
+
+ ); +} diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index a345eda..32827a2 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -1,194 +1,13 @@ -"use client"; +import { hasPasswordProtectedAdmin } from "@/db/users"; +import { LoginForm } from "./login-form"; -import { useState } from "react"; -import { signIn } from "next-auth/react"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card"; -import { Input } from "@/components/ui/input"; -import { Button } from "@/components/ui/button"; -import { Label } from "@/components/ui/label"; +export const dynamic = "force-dynamic"; /** - * Sign in with the username/password set after the first magic link, or request - * a new one-time link by email. The magic-link path remains the recovery path - * when someone has not set credentials yet. + * Public sign-in. The email-link form is bootstrap-only: once an admin has a + * password, anyone who knew that admin's email could otherwise request a full + * admin session from this page. */ -export default function LoginPage() { - const [login, setLogin] = useState(""); - const [password, setPassword] = useState(""); - const [passwordStatus, setPasswordStatus] = useState<{ - kind: "idle" | "signing" | "error"; - message?: string; - }>({ kind: "idle" }); - - const [email, setEmail] = useState(""); - const [linkStatus, setLinkStatus] = useState<{ - kind: "idle" | "sending" | "sent" | "error"; - message?: string; - }>({ kind: "idle" }); - - async function onPasswordSubmit(e: React.FormEvent) { - e.preventDefault(); - setPasswordStatus({ kind: "signing" }); - try { - const result = await signIn("password", { - login, - password, - redirect: false, - }); - if (!result || result.error) { - setPasswordStatus({ - kind: "error", - message: "That username or password did not match an active account.", - }); - return; - } - // Full navigation lets the server layout read the new session cookie. - window.location.assign("/schedule"); - } catch { - setPasswordStatus({ kind: "error", message: "Network error." }); - } - } - - async function onLinkSubmit(e: React.FormEvent) { - e.preventDefault(); - setLinkStatus({ kind: "sending" }); - try { - const res = await fetch("/api/dev/magic-link", { - method: "POST", - headers: { "content-type": "application/json" }, - body: JSON.stringify({ email }), - }); - const body = (await res.json()) as { - ok?: boolean; - url?: string; - error?: string; - }; - if (res.ok) { - setLinkStatus({ kind: "sent", message: body.url }); - } else { - setLinkStatus({ - kind: "error", - message: body.error ?? "Something went wrong.", - }); - } - } catch { - setLinkStatus({ kind: "error", message: "Network error." }); - } - } - - return ( -
-
-
-

- Glenloch Baptist Church -

-

- Media Team Hub -

-
- - - Sign in - - Use your username and password, or request a one-time email link. - - - -
-
- - setLogin(e.target.value)} - placeholder="you@church.local" - /> -
-
- - setPassword(e.target.value)} - /> -
- - {passwordStatus.kind === "error" && passwordStatus.message && ( -

- {passwordStatus.message} -

- )} -
- -
- - or - -
- -
- - setEmail(e.target.value)} - placeholder="you@church.local" - /> - - {linkStatus.kind === "sent" && - (linkStatus.message ? ( -

- Sign-in link (dev console transport):
- - {linkStatus.message} - -

- ) : ( -

- Check your email for a single-use sign-in link. It expires in - 10 minutes. -

- ))} - {linkStatus.kind === "error" && linkStatus.message && ( -

- {linkStatus.message} -

- )} -
- -

- First time here? The magic link will ask you to set a username and - password. If you are locked out, ask an admin for a reset link. -

-
-
-
-
- ); +export default async function LoginPage() { + return ; } diff --git a/src/app/respond/page.tsx b/src/app/respond/page.tsx index cc9181a..218e858 100644 --- a/src/app/respond/page.tsx +++ b/src/app/respond/page.tsx @@ -1,12 +1,17 @@ -import { getRespondAssignment } from "@/db/respond"; +import { + alternativeOptionsForAssignment, + getRespondAssignment, +} from "@/db/respond"; import { verifyRespondToken } from "@/lib/respond"; import { RespondForm } from "@/components/app/respond-form"; +import { AlternativeForm } from "@/components/app/alternative-form"; /** * Public respond page — unit E4 (ARCHITECTURE §5.6). * - * `GET /respond?t=&a=confirm|decline` renders the assignment and the two - * buttons. It never mutates: the token is consumed only by the form's POST. + * `GET /respond?t=` renders the assignment and the action the token was + * minted for: confirm/decline, or the "propose another Sunday" form. It never + * mutates: the token is consumed only by the form's POST. */ export default async function RespondPage({ searchParams, @@ -41,6 +46,10 @@ export default async function RespondPage({ const alreadyAnswered = assignment.status === "confirmed" || assignment.status === "declined"; + const alternatives = + payload.action === "alternative" && !alreadyAnswered + ? await alternativeOptionsForAssignment(payload.assignmentId) + : null; return (
@@ -60,6 +69,21 @@ export default async function RespondPage({

You already responded — this assignment is {assignment.status}.

+ ) : payload.action === "alternative" ? ( + alternatives && alternatives.length > 0 ? ( + ({ + id: option.id, + label: option.label, + }))} + /> + ) : ( +

+ There are no other upcoming services for this position right now. + Please decline so a coordinator can help. +

+ ) ) : ( )} diff --git a/src/auth/magic-link.ts b/src/auth/magic-link.ts index b15868b..d8a7dd5 100644 --- a/src/auth/magic-link.ts +++ b/src/auth/magic-link.ts @@ -44,11 +44,18 @@ export const MAGIC_LINK_DEV_TRANSPORT = ? process.env.MAGIC_LINK_DEV_TRANSPORT === "true" : process.env.NODE_ENV !== "production"; -export const APP_ORIGIN = - process.env.AUTH_URL ?? - process.env.NEXTAUTH_URL ?? - process.env.APP_ORIGIN ?? - "http://localhost:3000"; +/** + * Canonical origin for links built outside a live request. PUBLIC_ORIGIN is the + * address volunteers actually receive, so it wins over the auth callback URL + * (which may be a LAN address used only for cookies). + */ +export const APP_ORIGIN = ( + process.env.PUBLIC_ORIGIN?.trim() || + process.env.AUTH_URL?.trim() || + process.env.NEXTAUTH_URL?.trim() || + process.env.APP_ORIGIN?.trim() || + "http://localhost:3000" +).replace(/\/+$/, ""); function firstHeaderValue(value: string | null): string | null { if (!value) return null; diff --git a/src/components/app/alternative-form.tsx b/src/components/app/alternative-form.tsx new file mode 100644 index 0000000..500cb3a --- /dev/null +++ b/src/components/app/alternative-form.tsx @@ -0,0 +1,111 @@ +"use client"; + +import { useState } from "react"; + +/** + * "Propose another Sunday" on the public `/respond` page. + * + * Only rendered for an `alternative` email link. Submitting records the + * volunteer's preferred Sunday for a coordinator; it does not change the + * assignment, so a proposal never silently opens a hole in the schedule. + */ +export function AlternativeForm({ + token, + options, +}: { + token: string; + options: { id: string; label: string }[]; +}) { + const [instanceId, setInstanceId] = useState(options[0]?.id ?? ""); + const [note, setNote] = useState(""); + const [state, setState] = useState<"idle" | "sending" | "done" | "error">( + "idle", + ); + const [message, setMessage] = useState(""); + + async function submit(event: React.FormEvent) { + event.preventDefault(); + setState("sending"); + setMessage(""); + try { + const res = await fetch("/api/respond/alternative", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ token, instanceId, note }), + }); + const body = (await res.json().catch(() => ({}))) as { + error?: string; + }; + if (!res.ok) { + setMessage(body.error ?? "Could not send your proposal."); + setState("error"); + return; + } + const picked = + options.find((option) => option.id === instanceId)?.label ?? + "that Sunday"; + setMessage( + `Thanks — your coordinator will see that you can serve on ${picked}.`, + ); + setState("done"); + } catch { + setMessage("Network error — please try again."); + setState("error"); + } + } + + if (state === "done") { + return ( +

+ {message} +

+ ); + } + + return ( +
+ + +