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:
@@ -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');
|
||||
|
||||
@@ -41,6 +41,30 @@ services:
|
||||
retries: 20
|
||||
start_period: 30s
|
||||
|
||||
# ════════════════════════════════════════════════════════════════════════
|
||||
# Migrate — spielt das (idempotente) Schema bei jedem `up` nach, damit neue
|
||||
# Tabellen/Spalten auch in eine BESTEHENDE DB kommen (Init-Scripts laufen nur
|
||||
# beim allerersten Start). Läuft einmal und beendet sich. supabase_admin =
|
||||
# Superuser → keine Owner-Konflikte. schema.sql ist idempotent.
|
||||
# ════════════════════════════════════════════════════════════════════════
|
||||
migrate:
|
||||
image: supabase/postgres:15.8.1.020
|
||||
container_name: openbureau-migrate
|
||||
restart: "no"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
PGPASSWORD: ${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- ./db/schema.sql:/openbureau-schema.sql:ro
|
||||
entrypoint: ["bash", "-c"]
|
||||
command:
|
||||
- >
|
||||
psql -h db -U supabase_admin -d postgres -v ON_ERROR_STOP=1 -f /openbureau-schema.sql &&
|
||||
psql -h db -U supabase_admin -d postgres -c "notify pgrst, 'reload schema';" &&
|
||||
echo '✓ Schema migriert.'
|
||||
|
||||
# ════════════════════════════════════════════════════════════════════════
|
||||
# GoTrue — Auth (Login für das CMS)
|
||||
# ════════════════════════════════════════════════════════════════════════
|
||||
@@ -124,6 +148,8 @@ services:
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
kong:
|
||||
condition: service_started
|
||||
environment:
|
||||
|
||||
Reference in New Issue
Block a user