app: the House of Prayer's backend (APP-1.0-PLAN §3)

Commitments stored as rules (start, length, once/daily/weekly, end, skips) in the
church's timezone, daylight saving included; the day's coverage as counts only,
cached until a booking changes, live over server-sent events (X-Accel-Buffering
off, a comment every 25 s). Booking, skipping, changing, cancelling within the
8-hour rule, renewing (a signed single-use link), "I prayed" (self-reported).
Campaigns and moderated testimonies; the admin's bookings with names, always
access-logged; booking on a member's behalf. Reminders (every minute) and
renewal notices (14 and 3 days before) queued in an outbox for the messaging
slice. The heartbeat's prayer counts; export and delete for a member's prayer.
Migration 20261202000000_house_of_prayer (checked on PostgreSQL 18: applies, no
diff). 66 backend tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 10:29:39 +02:00
co-authored by Claude Opus 5.5
parent 6726518175
commit 5213bb36c0
23 changed files with 2376 additions and 30 deletions
@@ -0,0 +1,169 @@
-- Church App 1.0.0: the House of Prayer (docs/APP-1.0-PLAN.md §3): commitments as rules with their
-- skips, "I prayed" marks, campaigns, testimonies, the access log and the outbox for reminders.
-- CreateEnum
CREATE TYPE "PrayerRecurrence" AS ENUM ('once', 'daily', 'weekly');
-- CreateEnum
CREATE TYPE "PrayerReminder" AS ENUM ('none', 'min15', 'hour1', 'evening');
-- CreateEnum
CREATE TYPE "MessageChannel" AS ENUM ('email', 'whatsapp', 'both');
-- CreateEnum
CREATE TYPE "TestimonyStatus" AS ENUM ('pending', 'approved', 'removed');
-- CreateTable
CREATE TABLE "PrayerCommitment" (
"id" TEXT NOT NULL,
"memberId" TEXT,
"startDate" TEXT NOT NULL,
"startMinute" INTEGER NOT NULL,
"durationMinutes" INTEGER NOT NULL,
"recurrence" "PrayerRecurrence" NOT NULL,
"endDate" TEXT NOT NULL,
"reminder" "PrayerReminder" NOT NULL DEFAULT 'hour1',
"channel" "MessageChannel" NOT NULL DEFAULT 'email',
"note" TEXT,
"bookedById" TEXT,
"renewalNoticesSent" INTEGER NOT NULL DEFAULT 0,
"renewedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "PrayerCommitment_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "PrayerSkip" (
"id" TEXT NOT NULL,
"commitmentId" TEXT NOT NULL,
"date" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "PrayerSkip_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "PrayedMark" (
"id" TEXT NOT NULL,
"commitmentId" TEXT NOT NULL,
"memberId" TEXT,
"date" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "PrayedMark_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "PrayerCampaign" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"imageUrl" TEXT,
"startDate" TEXT NOT NULL,
"endDate" TEXT NOT NULL,
"goal" TEXT,
"targetPerSlot" INTEGER,
"createdById" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "PrayerCampaign_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Testimony" (
"id" TEXT NOT NULL,
"memberId" TEXT NOT NULL,
"campaignId" TEXT,
"text" TEXT NOT NULL,
"showName" BOOLEAN NOT NULL DEFAULT false,
"status" "TestimonyStatus" NOT NULL DEFAULT 'pending',
"removedReason" TEXT,
"moderatedById" TEXT,
"moderatedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Testimony_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "AccessLog" (
"id" TEXT NOT NULL,
"actorId" TEXT NOT NULL,
"action" TEXT NOT NULL,
"targetType" TEXT NOT NULL,
"targetId" TEXT,
"metadata" JSONB,
"ip" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "AccessLog_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "OutboxMessage" (
"id" TEXT NOT NULL,
"memberId" TEXT NOT NULL,
"kind" TEXT NOT NULL,
"channel" "MessageChannel" NOT NULL,
"payload" JSONB NOT NULL,
"dedupeKey" TEXT NOT NULL,
"sendAfter" TIMESTAMP(3) NOT NULL,
"sentAt" TIMESTAMP(3),
"failedAt" TIMESTAMP(3),
"error" TEXT,
"attempts" INTEGER NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "OutboxMessage_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "PrayerCommitment_endDate_idx" ON "PrayerCommitment"("endDate");
-- CreateIndex
CREATE INDEX "PrayerCommitment_memberId_idx" ON "PrayerCommitment"("memberId");
-- CreateIndex
CREATE UNIQUE INDEX "PrayerSkip_commitmentId_date_key" ON "PrayerSkip"("commitmentId", "date");
-- CreateIndex
CREATE INDEX "PrayedMark_date_idx" ON "PrayedMark"("date");
-- CreateIndex
CREATE UNIQUE INDEX "PrayedMark_commitmentId_date_key" ON "PrayedMark"("commitmentId", "date");
-- CreateIndex
CREATE INDEX "PrayerCampaign_endDate_idx" ON "PrayerCampaign"("endDate");
-- CreateIndex
CREATE INDEX "Testimony_status_createdAt_idx" ON "Testimony"("status", "createdAt");
-- CreateIndex
CREATE INDEX "AccessLog_createdAt_idx" ON "AccessLog"("createdAt");
-- CreateIndex
CREATE UNIQUE INDEX "OutboxMessage_dedupeKey_key" ON "OutboxMessage"("dedupeKey");
-- CreateIndex
CREATE INDEX "OutboxMessage_sentAt_sendAfter_idx" ON "OutboxMessage"("sentAt", "sendAfter");
-- AddForeignKey
ALTER TABLE "PrayerCommitment" ADD CONSTRAINT "PrayerCommitment_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PrayerSkip" ADD CONSTRAINT "PrayerSkip_commitmentId_fkey" FOREIGN KEY ("commitmentId") REFERENCES "PrayerCommitment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PrayedMark" ADD CONSTRAINT "PrayedMark_commitmentId_fkey" FOREIGN KEY ("commitmentId") REFERENCES "PrayerCommitment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Testimony" ADD CONSTRAINT "Testimony_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Testimony" ADD CONSTRAINT "Testimony_campaignId_fkey" FOREIGN KEY ("campaignId") REFERENCES "PrayerCampaign"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OutboxMessage" ADD CONSTRAINT "OutboxMessage_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;