app: announcements, devotionals and events' backend (APP-1.0-PLAN §5-§7)

Announcements: public or members-only, pinned, a campus, a publish time and an
end, an optional button, markdown text; Content admins write them; the
heartbeat counts the last 30 days; "also send it" flags kept for §8.

Devotionals: Cross Code's from the Hub each night and on Sync now (the next
2 weeks from today in the church's timezone, with the licence; exactly those
days replaced, the rest kept, a Hub outage changes nothing), or the church's
own by its Devotional writers, by hand or the same CSV import as the Hub's
(preview, then replace or skip days already filled). Only KJV and BSB; the
passage with its copyright line and Read in YouVersion; today's or the most
recent; the archive by month; members-only ones; the acknowledgements.

Events: simple events in the church's timezone, and the feed both ways as the
Website's (publish its own as crosscode.event/1 with removals; read-only copies
of Cross Events' and the Website's, Register on the Events site, canonical to
the origin). Jobs event-feed (15 min) and crosscode-devotionals (01:15).
Migration 20261204000000_content (checked on PostgreSQL 18: applies, no diff).
93 backend tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 11:20:31 +02:00
co-authored by Claude Opus 5.5
parent 710b762ddf
commit a9079f1195
14 changed files with 1514 additions and 21 deletions
@@ -0,0 +1,128 @@
-- Church App 1.0.0: announcements, devotionals and events (docs/APP-1.0-PLAN.md §5-§7): announcements,
-- Cross Code's and the church's own devotionals, simple events, the feed's copies and removals.
-- CreateEnum
CREATE TYPE "AnnouncementAudience" AS ENUM ('everyone', 'members');
-- CreateEnum
CREATE TYPE "DevotionalSource" AS ENUM ('crosscode', 'church');
-- CreateTable
CREATE TABLE "Announcement" (
"id" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"body" TEXT NOT NULL,
"imageUrl" TEXT,
"buttonLabel" TEXT,
"buttonUrl" TEXT,
"campus" TEXT,
"audience" "AnnouncementAudience" NOT NULL DEFAULT 'everyone',
"pinned" BOOLEAN NOT NULL DEFAULT false,
"publishAt" TIMESTAMP(3),
"endsAt" TIMESTAMP(3),
"sendEmail" BOOLEAN NOT NULL DEFAULT false,
"sendWhatsApp" BOOLEAN NOT NULL DEFAULT false,
"sentAt" TIMESTAMP(3),
"createdById" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Announcement_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Devotional" (
"id" TEXT NOT NULL,
"source" "DevotionalSource" NOT NULL,
"originId" TEXT,
"date" TEXT NOT NULL,
"title" TEXT NOT NULL,
"reference" TEXT NOT NULL,
"location" JSONB NOT NULL,
"translation" TEXT NOT NULL,
"passageText" TEXT NOT NULL,
"body" TEXT NOT NULL,
"prayer" TEXT,
"author" TEXT,
"membersOnly" BOOLEAN NOT NULL DEFAULT false,
"createdById" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Devotional_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "SimpleEvent" (
"id" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"startsAt" TIMESTAMP(3) NOT NULL,
"endsAt" TIMESTAMP(3),
"allDay" BOOLEAN NOT NULL DEFAULT false,
"timezone" TEXT NOT NULL DEFAULT 'Africa/Johannesburg',
"location" TEXT,
"description" TEXT,
"imageUrl" TEXT,
"link" TEXT,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"publishedAt" TIMESTAMP(3),
"updatedBy" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "SimpleEvent_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "ImportedEvent" (
"id" TEXT NOT NULL,
"linkId" TEXT NOT NULL,
"originProduct" TEXT NOT NULL,
"originId" TEXT NOT NULL,
"startsAt" TIMESTAMP(3) NOT NULL,
"endsAt" TIMESTAMP(3) NOT NULL,
"data" JSONB NOT NULL,
"syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "ImportedEvent_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "FeedRemoval" (
"eventId" TEXT NOT NULL,
"removedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "FeedRemoval_pkey" PRIMARY KEY ("eventId")
);
-- CreateIndex
CREATE UNIQUE INDEX "Announcement_slug_key" ON "Announcement"("slug");
-- CreateIndex
CREATE INDEX "Announcement_publishAt_idx" ON "Announcement"("publishAt");
-- CreateIndex
CREATE INDEX "Devotional_date_idx" ON "Devotional"("date");
-- CreateIndex
CREATE UNIQUE INDEX "Devotional_source_date_key" ON "Devotional"("source", "date");
-- CreateIndex
CREATE UNIQUE INDEX "SimpleEvent_slug_key" ON "SimpleEvent"("slug");
-- CreateIndex
CREATE INDEX "SimpleEvent_startsAt_idx" ON "SimpleEvent"("startsAt");
-- CreateIndex
CREATE INDEX "ImportedEvent_startsAt_idx" ON "ImportedEvent"("startsAt");
-- CreateIndex
CREATE INDEX "ImportedEvent_linkId_idx" ON "ImportedEvent"("linkId");
-- CreateIndex
CREATE UNIQUE INDEX "ImportedEvent_originProduct_originId_key" ON "ImportedEvent"("originProduct", "originId");
-- AddForeignKey
ALTER TABLE "ImportedEvent" ADD CONSTRAINT "ImportedEvent_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "ProductLink"("installId") ON DELETE CASCADE ON UPDATE CASCADE;
+133 -12
View File
@@ -80,19 +80,20 @@ model Session {
/// the shared email and WhatsApp settings, and Events / the Website for the event feed (§7, §8).
/// The secret is encrypted.
model ProductLink {
installId String @id
product String
url String
publicKey String
secret String
connectedAt DateTime @default(now())
connectedById String?
installId String @id
product String
url String
publicKey String
secret String
connectedAt DateTime @default(now())
connectedById String?
/// Show this sibling's events in the App (the event feed, §7). Accounts has none.
showEvents Boolean @default(true)
lastSyncAt DateTime?
lastGoodAt DateTime?
lastSyncError String?
updatedAt DateTime @updatedAt
showEvents Boolean @default(true)
lastSyncAt DateTime?
lastGoodAt DateTime?
lastSyncError String?
updatedAt DateTime @updatedAt
importedEvents ImportedEvent[]
}
/// Nonces of link messages seen in the last hour (replays are refused).
@@ -366,3 +367,123 @@ model RequestPrayer {
@@unique([requestId, memberId])
}
// ── Announcements (§5) ───────────────────────────────────────────────────────────────────────
enum AnnouncementAudience {
everyone
members
}
/// News from the church: public ones are pages of their own (SEO, §11); members-only ones are noindex.
model Announcement {
id String @id @default(uuid())
slug String @unique
title String
/// Markdown, shown sanitised (no HTML).
body String
imageUrl String?
buttonLabel String?
buttonUrl String?
/// A campus's slug from the church profile, or null for every campus.
campus String?
audience AnnouncementAudience @default(everyone)
pinned Boolean @default(false)
/// Shown from then (now or later); a draft has none.
publishAt DateTime?
/// Hidden after this, if set.
endsAt DateTime?
/// Also send it at the publish time (to members who chose announcements, §8).
sendEmail Boolean @default(false)
sendWhatsApp Boolean @default(false)
/// When the sends were queued (once).
sentAt DateTime?
createdById String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([publishAt])
}
// ── Devotionals (§6) ─────────────────────────────────────────────────────────────────────────
// `crosscode.devotional/1`: Cross Code's (from the Hub, the next 2 weeks each night) and the
// church's own, side by side; Settings → Devotionals (AppSetting `devotionals_source`) picks which
// one shows. One per day per source.
enum DevotionalSource {
crosscode
church
}
model Devotional {
id String @id @default(uuid())
source DevotionalSource
/// The Hub's id for Cross Code's (`crosscode.devotional/1` `id`).
originId String?
/// The local day it's for (YYYY-MM-DD, the church's timezone).
date String
title String
reference String
/// `passageLocationSchema`: book, chapter and verses (for the YouVersion link).
location Json
translation String
passageText String
/// Markdown, shown sanitised.
body String
prayer String?
author String?
/// Only for signed-in members (noindex); public by default (§6).
membersOnly Boolean @default(false)
createdById String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([source, date])
@@index([date])
}
// ── Events (§7) ──────────────────────────────────────────────────────────────────────────────
// As the Website's: simple events made in the App, read-only copies of the siblings' events (the
// feed), and removals listed for 90 days.
model SimpleEvent {
id String @id @default(uuid())
slug String @unique
title String
startsAt DateTime
endsAt DateTime?
allDay Boolean @default(false)
timezone String @default("Africa/Johannesburg")
location String?
description String?
imageUrl String?
link String?
cancelled Boolean @default(false)
publishedAt DateTime?
updatedBy String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([startsAt])
}
model ImportedEvent {
id String @id @default(uuid())
linkId String
link ProductLink @relation(fields: [linkId], references: [installId], onDelete: Cascade)
originProduct String
originId String
startsAt DateTime
endsAt DateTime
data Json
syncedAt DateTime @default(now())
@@unique([originProduct, originId])
@@index([startsAt])
@@index([linkId])
}
model FeedRemoval {
eventId String @id
removedAt DateTime @default(now())
}