-- AlterTable: how a character is doing beyond HP, and the class counters -- (Rage, Ki...) spent since the rest that gives them back, as { key: used }. ALTER TABLE "characters" ADD COLUMN "resourcesUsed" JSONB NOT NULL DEFAULT '{}', ADD COLUMN "inspiration" BOOLEAN NOT NULL DEFAULT false, ADD COLUMN "exhaustion" INTEGER NOT NULL DEFAULT 0, ADD COLUMN "conditions" TEXT[] DEFAULT ARRAY[]::TEXT[]; -- A character's conditions used to be kept per encounter. They are the -- character's own now, so those given in an encounter still in progress move -- onto the character. UPDATE "characters" c SET "conditions" = held.conditions FROM ( SELECT p."characterId", array_agg(DISTINCT condition) AS conditions FROM "encounter_participants" p JOIN "encounters" e ON e."id" = p."encounterId" CROSS JOIN LATERAL unnest(p."conditions") AS condition WHERE p."characterId" IS NOT NULL AND e."status" = 'ACTIVE' GROUP BY p."characterId" ) held WHERE c."id" = held."characterId";