-- AlterTable: whether players see a monster's exact hit points or only its health bar ALTER TABLE "campaigns" ADD COLUMN "showMonsterHp" BOOLEAN NOT NULL DEFAULT true; -- AlterTable: where an encounter takes place ALTER TABLE "encounters" ADD COLUMN "locationId" TEXT; ALTER TABLE "encounters" ADD CONSTRAINT "encounters_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "locations"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- CreateTable: every location a character has been to CREATE TABLE "character_location_visits" ( "id" TEXT NOT NULL, "characterId" TEXT NOT NULL, "locationId" TEXT NOT NULL, "firstVisitedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "character_location_visits_pkey" PRIMARY KEY ("id") ); CREATE UNIQUE INDEX "character_location_visits_characterId_locationId_key" ON "character_location_visits"("characterId", "locationId"); ALTER TABLE "character_location_visits" ADD CONSTRAINT "character_location_visits_characterId_fkey" FOREIGN KEY ("characterId") REFERENCES "characters"("id") ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE "character_location_visits" ADD CONSTRAINT "character_location_visits_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "locations"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- Characters have been to wherever they are now. INSERT INTO "character_location_visits" ("id", "characterId", "locationId") SELECT 'visit_' || "id", "id", "currentLocationId" FROM "characters" WHERE "currentLocationId" IS NOT NULL;