Files
CRM_Montzar/apps/api/prisma/migrations/20261117190000_account_balances/migration.sql
T

23 lines
917 B
SQL

-- AlterTable
ALTER TABLE "Organization" ADD COLUMN "accountBalanceSettings" JSONB NOT NULL DEFAULT '{}';
ALTER TABLE "Organization" ADD COLUMN "accountBalanceClaimsLastSlot" TEXT;
-- AlterTable
ALTER TABLE "CustomerGroup" ADD COLUMN "assigneeIds" TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[];
-- Backfill ordered assignee ids from existing M2M (alphabetical until re-saved)
UPDATE "CustomerGroup" AS g
SET "assigneeIds" = COALESCE((
SELECT ARRAY_AGG(link."B" ORDER BY u."fullName")
FROM "_CustomerGroupAssignees" AS link
INNER JOIN "User" AS u ON u."id" = link."B"
WHERE link."A" = g."id"
), ARRAY[]::TEXT[])
WHERE COALESCE(cardinality(g."assigneeIds"), 0) = 0;
-- AlterTable
ALTER TABLE "ActivityBoard" ADD COLUMN "systemKey" TEXT;
-- CreateIndex (NULLs allowed multiple times in PostgreSQL)
CREATE UNIQUE INDEX "ActivityBoard_organizationId_systemKey_key" ON "ActivityBoard"("organizationId", "systemKey");