createSeeder(payload, { dryRun, update, force, guard, editCheck, context, ... })
returns upsertBySlug, upsertBy, fillGlobal and summary(); building blocks
isLocalDatabase, writeLocales, seedHash, projectOnto, editedSinceSeed.
Behaviour follows docs/seeding.md: create-only by default, natural keys,
never deletes, globals get empty fields only, every locale written with
fallbackLocale: false onto the same row ids, records edited since seeding
skipped, update refused on production / non-local DB unless
IPAL_SEED_ALLOW_PROD_UPDATE=1, context.ipalSkipIndexNow on every write.
Both seed templates now use the helper. Node-only entry (no 'server-only',
which throws under `payload run`). SQLite integration tests cover the
production guard, the edited-record skip, the hash field, row ids and
the IndexNow skip. Agent guide (AGENT.md, ipal-reference, ipal-site,
ipal-form) and seeding.md updated.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
64 lines
3.6 KiB
TypeScript
64 lines
3.6 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
|
|
* (`--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.
|
|
*
|
|
* 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'
|
|
// ----------------------------------------------------------------- /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 }), { 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)
|