cms: Schema-Migration bei jedem up nachziehen (forums/threads in Bestands-DB)

Problem: Init-Scripts (docker-entrypoint-initdb.d) laufen nur beim allerersten
DB-Start. Neue Tabellen aus schema.sql (forums/threads) landeten daher nicht in
einer bereits initialisierten Produktiv-DB → "relation public.forums does not
exist" auf der Dialog-Seite.

- docker-compose.yml: neuer einmaliger `migrate`-Service spielt das idempotente
  schema.sql als supabase_admin (Superuser, keine Owner-Konflikte) bei jedem
  `up` ein und lädt den PostgREST-Cache neu; cms wartet via
  service_completed_successfully darauf.
- routes/dialog.js: fehlende Tabelle führt nicht mehr zu rohem SQL-Fehler —
  leere Liste + server-seitiges Log statt 500 auf der Seite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 18:50:07 +02:00
parent bd85570259
commit 70a6798404
2 changed files with 41 additions and 5 deletions
+15 -5
View File
@@ -5,18 +5,28 @@ import {
forumsWithCounts, forumWithThreads, recentComments, createThread, recentForModeration, threadMeta,
} from '../dialog-store.js';
// Fehlt die Tabelle (Migration noch nicht eingespielt), nicht mit einem rohen
// SQL-Fehler antworten — leer zurückgeben und server-seitig laut loggen.
function softFail(c, e, fallback) {
console.error('[dialog]', e?.message || e);
return c.json(fallback);
}
// ── Öffentliche Lese-Handler ─────────────────────────────────────────────
export async function listForums(c) {
try { return c.json(await forumsWithCounts()); }
catch (e) { return c.json({ error: String(e) }, 500); }
catch (e) { return softFail(c, e, []); }
}
export async function showForum(c) {
const data = await forumWithThreads(c.req.param('slug'));
if (!data) return c.json({ error: 'Forum nicht gefunden' }, 404);
return c.json(data);
try {
const data = await forumWithThreads(c.req.param('slug'));
if (!data) return c.json({ error: 'Forum nicht gefunden' }, 404);
return c.json(data);
} catch (e) { return softFail(c, e, { forum: null, threads: [] }); }
}
export async function recent(c) {
return c.json(await recentComments(Number(c.req.query('limit')) || 20));
try { return c.json(await recentComments(Number(c.req.query('limit')) || 20)); }
catch (e) { return softFail(c, e, []); }
}
export async function threadInfo(c) {
const key = c.req.query('key');