Files
ipal-kit/docs/agent/skills/ipal-site/resources/seed-content.template.ts
T
Radosław SmolińskiandClaude Opus 5.5 af7d96f0e3 Database naming rule; seeding after launch touches named records only
- Rule (VERY IMPORTANT): databases are named <domain without dots>_prod /
  _dev (intecion.com → intecioncom_prod / intecioncom_dev) on MongoDB and
  Postgres — AGENT.md top rules, deployment.md §4.2a (Coolify), env.md,
  ipal-setup architecture questions (derive, then confirm), AGENTS.md
  template. ipalEnvRules({ databaseName }) warns (never fails) on a
  mismatch, domain from NEXT_PUBLIC_SERVER_URL or { domain }, { warn }
  overridable; helpers databaseNamesFor, databaseNameFromUri,
  checkDatabaseName from the root and /env.
- Rule (VERY IMPORTANT): after launch never re-seed everything — AGENT.md,
  seeding.md, ipal-site, ipal-form, ipal-reference. createSeeder gains
  `only` / SEED_ONLY (pages:slug, forms:title, global:slug, collection:*;
  the rest → "skip (not listed)") and refuses a run with no record list
  against a production / non-local database unless IPAL_SEED_ALLOW_FULL=1
  (guard.allowFull; dry runs allowed). Seed templates carry an ONLY list;
  the form seed touches only its own form.
- Tests: seed only/full-run guard, database-name helpers and warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 13:27:46 +01:00

72 lines
4.4 KiB
TypeScript

/**
* Content seed from the brief — skill ipal-site, phase 6. Rules: docs/seeding.md.
*
* SEED_DRY_RUN=1 pnpm payload run scripts/seed-content.ts # no writes: prints create / skip / update per record
* pnpm payload run scripts/seed-content.ts # creates what's missing, never overwrites
* SEED_UPDATE=1 pnpm payload run scripts/seed-content.ts # also updates records nobody edited since seeding
* SEED_ONLY="pages:kontakt" pnpm payload run … # only the listed records (or set ONLY below)
* (`--dry-run` after the script path works too, e.g. `pnpm seed:content --dry-run`.)
*
* The rules live in createSeeder (@intecion/ipal-kit/seed), so fixes arrive with a
* plugin upgrade:
* - Create-only and idempotent. Pages match by their DEFAULT-locale slug; globals
* get only the fields that are still empty. Nothing is ever deleted.
* - SEED_UPDATE=1 is refused when NODE_ENV=production or the database is not local,
* unless IPAL_SEED_ALLOW_PROD_UPDATE=1 is also set. Back up the database first.
* - An update skips every record an editor changed since seeding ("skip (edited)").
* - Every locale is written with `fallbackLocale: false` onto the same row ids.
* - Writes carry ipalSkipIndexNow, disableRevalidate and ipalSeed in `context`.
* - Never seed users, passwords or secrets (SMTP, Turnstile, API keys) — panel / env.
* - VERY IMPORTANT — after launch: never run the whole seed again. The owner's edits on the live
* site must survive. List exactly the records this run may touch in ONLY (or SEED_ONLY); the rest
* is reported as "skip (not listed)". A run without a list against a production / non-local
* database is refused unless IPAL_SEED_ALLOW_FULL=1 — only with the owner's explicit OK.
*
* Write content ONCE, all languages side by side:
* heading: { pl: 'Nasze usługi', en: 'Our services' } → localized value
* heading: 'Nasze usługi' → same in every locale / non-localized field
* page: { $page: 'kontakt' } → ID of the page whose DEFAULT-locale slug is 'kontakt'
* Missing data: '[TO FILL: tax ID (NIP)]' — never invent company data, prices, reviews, numbers.
* Media: leave empty or reference existing uploads by ID — the editor adds images. Never upload here.
*/
import config from '@payload-config'
import { createSeeder } from '@intecion/ipal-kit/seed'
import { getPayload } from 'payload'
// ------------------------------------------------------------------ CONTENT --
const PAGES: Record<string, unknown>[] = [
{
title: { pl: 'Strona główna', en: 'Home' },
slug: { pl: 'home', en: 'home' },
layout: [
{
blockType: 'hero',
header: { heading: { pl: 'Nagłówek z briefu', en: 'Heading from the brief' } }, // buildSectionHeaderField
links: [{ link: { type: 'internal', page: { $page: 'kontakt' }, label: { pl: 'Kontakt', en: 'Contact' }, appearance: 'primary' } }],
},
],
},
{ title: { pl: 'Kontakt', en: 'Contact' }, slug: { pl: 'kontakt', en: 'contact' }, layout: [] },
]
const GLOBALS: { slug: string; data: Record<string, unknown> }[] = [
// { slug: 'header', data: { links: [{ link: { type: 'internal', page: { $page: 'kontakt' }, label: { pl: 'Kontakt', en: 'Contact' } } }] } },
]
const COLLECTION = 'pages'
// Before launch: undefined (the whole site). After launch: ONLY the records the owner asked for, e.g.
// ['pages:kontakt', 'global:header'] — `collection:<default-locale slug>`, `global:<slug>`, `collection:*`.
const ONLY: string[] | undefined = undefined
// ----------------------------------------------------------------- /CONTENT --
// Options (docs/seeding.md § Turn off, override, extend) — env vars work without editing this file:
// createSeeder(payload, { editCheck: { hashField: false }, guard: { localHosts: ['db'] }, context: { … } })
const seed = createSeeder(await getPayload({ config }), { only: ONLY, pagesCollection: COLLECTION })
// One call for all pages: missing ones are created first, so $page links work in any order.
await seed.upsertBySlug(COLLECTION, PAGES)
for (const g of GLOBALS) await seed.fillGlobal(g.slug, g.data)
const { errors } = seed.summary()
const todo = JSON.stringify({ PAGES, GLOBALS }).match(/\[TO FILL:[^\]]*\]/g) ?? []
if (todo.length) console.log(`\n${todo.length} placeholder(s) for the final report:\n ${[...new Set(todo)].join('\n ')}`)
process.exit(errors ? 1 : 0)