Files
crosscode-platform/apps/app/backend/prisma/migrations/20261204000000_content/migration.sql
T
joshuaandClaude Opus 5.5 a9079f1195 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>
2026-12-01 11:20:31 +02:00

129 lines
3.8 KiB
SQL

-- 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;