CREATE TABLE "activity_log" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "organization_id" text NOT NULL, "actor_id" text, "actor_name" text NOT NULL, "action" text NOT NULL, "entity_type" text NOT NULL, "entity_id" text, "patient_name" text, "patient_file_number" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "activity_log" ADD CONSTRAINT "activity_log_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "activity_log" ADD CONSTRAINT "activity_log_actor_id_user_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint CREATE INDEX "activity_org_created_idx" ON "activity_log" USING btree ("organization_id","created_at");