Files
teatea-pension/drizzle/0004_silly_carnage.sql

27 lines
2.2 KiB
SQL

CREATE TYPE "public"."care_task_priority" AS ENUM('low', 'normal', 'high', 'urgent');--> statement-breakpoint
CREATE TYPE "public"."care_task_status" AS ENUM('pending', 'in_progress', 'completed', 'cancelled');--> statement-breakpoint
CREATE TYPE "public"."care_task_type" AS ENUM('daily_care', 'meal', 'medication', 'rehab', 'inspection', 'cleaning', 'other');--> statement-breakpoint
CREATE TABLE "care_tasks" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"organization_id" uuid NOT NULL,
"elder_id" uuid,
"title" text NOT NULL,
"care_type" "care_task_type" NOT NULL,
"priority" "care_task_priority" DEFAULT 'normal' NOT NULL,
"status" "care_task_status" DEFAULT 'pending' NOT NULL,
"scheduled_at" timestamp with time zone NOT NULL,
"assignee_label" text DEFAULT '' NOT NULL,
"execution_notes" text DEFAULT '' NOT NULL,
"completed_at" timestamp with time zone,
"created_by_account_id" uuid,
"completed_by_account_id" uuid,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "care_tasks" ADD CONSTRAINT "care_tasks_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "care_tasks" ADD CONSTRAINT "care_tasks_elder_id_elders_id_fk" FOREIGN KEY ("elder_id") REFERENCES "public"."elders"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "care_tasks" ADD CONSTRAINT "care_tasks_created_by_account_id_accounts_id_fk" FOREIGN KEY ("created_by_account_id") REFERENCES "public"."accounts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "care_tasks" ADD CONSTRAINT "care_tasks_completed_by_account_id_accounts_id_fk" FOREIGN KEY ("completed_by_account_id") REFERENCES "public"."accounts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "care_tasks_queue_lookup" ON "care_tasks" USING btree ("organization_id","status","priority");--> statement-breakpoint
CREATE INDEX "care_tasks_schedule_lookup" ON "care_tasks" USING btree ("organization_id","scheduled_at");