Demo data from the Hub: crosscode demo, the seed-demo job, set-demo fixes

- scripts: `crosscode demo <church> --profile … [--admin-email …]`: backup,
  set-demo.js as the site's user, reload, wait for /health.
- Contracts 1.7.0: the seed-demo job, DEMO_PROFILES, SEED_DEMO_MIN_AGENT.
- Agent 1.2.0: seed-demo → crosscode demo.
- Events 2.4.1: set-demo.js stops with a clear message when it can't read
  .env (was "client password must be a string", then a hang); keeps the
  oldest admin when the default one isn't on the site; --admin-email=.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 10:37:16 +02:00
co-authored by Claude Opus 5.5
parent 126beaad70
commit f2a5df029a
21 changed files with 360 additions and 21 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/events-backend",
"version": "2.4.0",
"version": "2.4.1",
"description": "Event Management System Backend",
"main": "src/index.js",
"scripts": {
+26 -6
View File
@@ -16,8 +16,9 @@
* campus-limited staff, a series across campuses, kids check-in and rosters at two
* campuses.
*
* Everything is removed first EXCEPT the site settings (AppSetting) and the admin
* account (DEMO_ADMIN_EMAIL, default joshua@crosscode.co.za). Dates are relative to
* Everything is removed first EXCEPT the site settings (AppSetting) and one admin
* account (--admin-email= or DEMO_ADMIN_EMAIL; else joshua@crosscode.co.za, else the oldest admin).
* Dates are relative to
* today, so the upcoming events are always in the future whenever this is run.
*
* No emails or WhatsApp messages are sent. Demo people use @example.com addresses and
@@ -40,7 +41,18 @@ const fs = require('fs');
const crypto = require('crypto');
const readline = require('readline');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const ENV_FILE = path.resolve(__dirname, '../.env');
const loaded = require('dotenv').config({ path: ENV_FILE, quiet: true });
// Without DATABASE_URL the pg driver fails with "client password must be a string" and hangs. The
// usual reason on a server: .env is readable only by the site's own user (mode 600).
if (!process.env.DATABASE_URL && !process.argv.includes('--list')) {
const denied = loaded.error && loaded.error.code === 'EACCES';
console.error(denied
? `Can't read ${ENV_FILE}: it belongs to the site's user. Run this as that user, e.g.\n sudo -u <site user> npm run demo:ministry\nor, as root: crosscode demo <church> --profile ministry`
: `DATABASE_URL isn't set (${loaded.error ? `${ENV_FILE}: ${loaded.error.code || loaded.error.message}` : `not in ${ENV_FILE}`}). Nothing was changed.`);
process.exit(1);
}
const { hashPassword } = require('../src/config/auth');
const { v4: uuidv4 } = require('uuid');
@@ -49,7 +61,11 @@ const { applyBundles } = require('../src/utils/bundles');
const prisma = createPrismaClient();
const ADMIN_EMAIL = (process.env.DEMO_ADMIN_EMAIL || 'joshua@crosscode.co.za').trim().toLowerCase();
// The account kept: --admin-email= or DEMO_ADMIN_EMAIL (must exist), else joshua@crosscode.co.za
// if it's there, else the oldest admin (a site installed from the Hub has its own admin).
const ADMIN_ARG = (process.argv.find(a => a.startsWith('--admin-email=')) || '').slice('--admin-email='.length);
const ADMIN_NAMED = (ADMIN_ARG || process.env.DEMO_ADMIN_EMAIL || '').trim().toLowerCase();
const ADMIN_EMAIL = ADMIN_NAMED || 'joshua@crosscode.co.za';
const DEMO_PASSWORD = 'Demo@1234';
const SKIP_PROMPT = process.argv.includes('--yes') || process.argv.includes('-y');
const PROFILE_NAME = (process.argv.find(a => a.startsWith('--profile=')) || '--profile=events').split('=')[1].trim().toLowerCase();
@@ -1846,9 +1862,13 @@ async function main() {
return;
}
admin = await prisma.user.findFirst({ where: { email: { equals: ADMIN_EMAIL, mode: 'insensitive' } } });
if (!admin && !ADMIN_NAMED) {
admin = await prisma.user.findFirst({ where: { role: 'admin' }, orderBy: { createdAt: 'asc' } });
if (admin) console.log(`Keeping the site's first admin, ${admin.email} (${ADMIN_EMAIL} isn't here).`);
}
if (!admin) {
console.error(`Admin account ${ADMIN_EMAIL} was not found — nothing was changed.`);
console.error('Set DEMO_ADMIN_EMAIL to the account you want to keep.');
console.error(`Admin account ${ADMIN_NAMED || 'to keep'} was not found — nothing was changed.`);
console.error('Name the account to keep with --admin-email= or DEMO_ADMIN_EMAIL (or finish /setup first).');
process.exitCode = 1;
return;
}