|
| 1 | +/** |
| 2 | + * One-off, idempotent content tweak: swap the homepage hero (noir_hero) CTA |
| 3 | + * button styles so "Programm ansehen" is secondary (transparent) and |
| 4 | + * "Tickets & Spenden" is primary (gold). |
| 5 | + * |
| 6 | + * Runs in the migrator container ON the server (live DATABASE_URL from the |
| 7 | + * compose env_file). Self-contained — NO imports from src/ (the migrator image |
| 8 | + * only copies prisma/ + node_modules). Idempotent: keyed by button label, so |
| 9 | + * re-running is a no-op. Set DRY_RUN=1 to log the planned change without writing. |
| 10 | + * |
| 11 | + * docker compose --profile migrate run --rm --build eventschau-migrate \ |
| 12 | + * npx tsx prisma/seed-hero-buttons.ts |
| 13 | + */ |
| 14 | +import { PrismaClient } from '@prisma/client' |
| 15 | + |
| 16 | +const prisma = new PrismaClient() |
| 17 | +const DRY = process.env.DRY_RUN === '1' |
| 18 | +const TENANT_SLUG = process.env.TENANT_SLUG || 'e-ventschau' |
| 19 | + |
| 20 | +async function main() { |
| 21 | + const tenant = await prisma.tenant.findFirst({ where: { slug: TENANT_SLUG }, select: { id: true } }) |
| 22 | + if (!tenant) throw new Error(`tenant not found: ${TENANT_SLUG}`) |
| 23 | + |
| 24 | + const sec = await prisma.homepageSection.findFirst({ |
| 25 | + where: { tenantId: tenant.id, type: 'noir_hero' }, |
| 26 | + select: { id: true, content: true }, |
| 27 | + }) |
| 28 | + if (!sec) { console.log('no noir_hero section — nothing to do'); return } |
| 29 | + |
| 30 | + const content = (sec.content ?? {}) as Record<string, unknown> |
| 31 | + const buttons = Array.isArray(content.buttons) ? (content.buttons as Record<string, unknown>[]) : [] |
| 32 | + const next = buttons.map((b) => { |
| 33 | + const label = typeof b.label === 'string' ? b.label : '' |
| 34 | + if (label.includes('Programm')) return { ...b, variant: 'secondary' } |
| 35 | + if (label.includes('Tickets')) return { ...b, variant: 'primary' } |
| 36 | + return b |
| 37 | + }) |
| 38 | + |
| 39 | + console.log('before:', JSON.stringify(buttons)) |
| 40 | + console.log('after :', JSON.stringify(next)) |
| 41 | + if (DRY) { console.log('DRY_RUN — no write'); return } |
| 42 | + |
| 43 | + await prisma.homepageSection.update({ |
| 44 | + where: { id: sec.id }, |
| 45 | + data: { content: { ...content, buttons: next } as object }, |
| 46 | + }) |
| 47 | + console.log('updated noir_hero', sec.id) |
| 48 | +} |
| 49 | + |
| 50 | +main().then(() => prisma.$disconnect()).catch((e) => { console.error(e); process.exit(1) }) |
0 commit comments