Hub 2.0 step 6: AI cap and markup per church

The cap and markup move from the licence to the customer (migrated), use
is counted over all the church's installs under one lock per church, and
the licence token carries the church's cap. Settings → AI shows product.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 08:55:43 +02:00
co-authored by Claude Opus 5.5
parent 6e51780103
commit 59e6b9f03c
11 changed files with 138 additions and 72 deletions
@@ -0,0 +1,19 @@
-- 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";