-- Hub 2.0: the AI cap and markup are the church's (counted over all its installs), moved from the -- licence. Each church takes the cap of its open licence with the highest cap, and that licence's -- markup override (Hub 1.7 had one Events licence per church, so this is that licence's). ALTER TABLE "Customer" ADD COLUMN "aiMarkupPercent" INTEGER, ADD COLUMN "aiMonthlyCapCents" INTEGER NOT NULL DEFAULT 0; UPDATE "Customer" c SET "aiMonthlyCapCents" = l."aiMonthlyCapCents", "aiMarkupPercent" = l."aiMarkupPercent" FROM ( SELECT DISTINCT ON ("customerId") "customerId", "aiMonthlyCapCents", "aiMarkupPercent" FROM "Licence" WHERE status <> 'revoked' ORDER BY "customerId", "aiMonthlyCapCents" DESC, "createdAt" ASC ) l WHERE c.id = l."customerId"; ALTER TABLE "Licence" DROP COLUMN "aiMarkupPercent", DROP COLUMN "aiMonthlyCapCents";