- Translate to English every doc the code branches did not touch: AGENT.md, developer guide, vibe, CHANGELOG, docs index, module pages, all skills except ipal-seo-check (14 pages follow after the security/SEO merge). Placeholder marker is now [TO FILL: …]; skill resources renamed to section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer block say the docs are in English. - docs/seeding.md: create-only, natural keys, never delete, no users or secrets, empty-field globals, fallbackLocale: false, dry run, backup and restore, production update guard, seeds vs migrations, Coolify Terminal. Seed templates gain --dry-run, the SEED_UPDATE production guard (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary. "Seeding on production" rule block in AGENT.md. - Coolify is the single deployment path (deployment, env, developer guide, ipal-setup): build vs runtime env, migrations on container start (prodMigrations), health check and rolling updates, rollback, backups and restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone; default is media served by the app (R2_PUBLIC_URL empty). - docsConsistency: no Polish prose outside code/quoted data (pending pages listed); IPAL_* names may also be read by shipped skill templates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9.3 KiB
seeding — content seeds that never overwrite production
A seed is a script that puts content into the database: pages, forms, globals. ipal-kit ships two templates. Copy them into the project and fill them from the brief:
| Template | Copy to | Seeds |
|---|---|---|
docs/agent/skills/ipal-site/resources/seed-content.template.ts |
scripts/seed-content.ts |
pages (or another collection with a slug) and globals, every language |
docs/agent/skills/ipal-form/resources/seed-form.template.ts |
scripts/seed-form-<name>.ts |
one form: fields, confirmation, both e-mails, every language |
Both follow the rules below. A seed you write yourself must follow them too.
Rules
-
Create-only and idempotent. A seed creates what is missing and skips what exists. Running it twice changes nothing the second time.
-
Match by a natural key, never by ID. IDs differ between databases.
Record Key page, content entry the slug in the default locale form the form title global the global itself (there is only one) -
Never delete. No
payload.delete, no "clean up first". A record that should go away is removed by a person in the panel. -
Never seed users, passwords or secrets. SMTP, Turnstile, API keys and tokens stay in the panel or in env vars. The first admin is created on the first-user screen.
-
Globals: fill only empty fields. A field that already has content is kept.
-
Media: leave upload fields empty or reference existing uploads by ID. Never upload files in a production seed. The editor adds images.
-
Write each locale separately, with
fallbackLocale: false. See Locales. -
Pass the context flags the plugin reads. See Context flags.
Running a seed
| Command | What it does |
|---|---|
SEED_DRY_RUN=1 pnpm payload run scripts/seed-content.ts |
no writes; prints the plan |
pnpm payload run scripts/seed-content.ts |
creates what is 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 does the same as SEED_DRY_RUN=1, for example with a package script:
"seed:content": "payload run scripts/seed-content.ts" → pnpm seed:content --dry-run.
Every run prints one line per record and a summary:
| Status | Meaning |
|---|---|
create |
the record is missing; the seed creates it (for a global: fills its empty fields) |
skip (exists) |
the record exists; nothing changes |
update |
SEED_UPDATE=1 and nobody edited the record since seeding; the seed overwrites the seeded fields |
skip (edited) |
SEED_UPDATE=1, but an editor changed the record; it is kept (the line says why) |
error |
the write failed; the script exits with code 1 |
The summary table counts created, skipped, updated, skipped-edited and errors.
Before you run a seed on production
- Dry run. Run the seed with
SEED_DRY_RUN=1and read every line. Expectcreateandskip (exists). - Test on a copy. Run it on staging or on a local copy of the production database first.
- Back up the database.
- Coolify: the database resource → Backups → Backup now (deployment.md §4.6).
- Postgres by hand:
pg_dump -Fc "$DATABASE_URI" > before-seed.dump - MongoDB by hand:
mongodump --uri="$DATABASE_URI" --archive=before-seed.archive
- Run it for real. Check the panel and the site.
Restore, if something went wrong:
- Coolify: the database resource → Import Backup → pick the backup → check the restore command → start. Stop writes from the app first.
- Postgres by hand:
pg_restore --clean --if-exists --no-owner -d "$DATABASE_URI" before-seed.dump - MongoDB by hand:
mongorestore --uri="$DATABASE_URI" --archive=before-seed.archive --drop
Updates on production
A seed may update a record on production only when both are true:
- the seed created it, and
- nobody edited it since.
Anything an editor changed is always skipped and reported as skip (edited).
SEED_UPDATE=1 is refused when NODE_ENV=production or when the database is not local. It runs only
when IPAL_SEED_ALLOW_PROD_UPDATE=1 is also set. The refusal message tells you to back up first.
A database counts as local when DATABASE_URI is a SQLite file (file:…), a Unix socket, or a URL whose
host is localhost, 127.0.0.1 or ::1. Everything else is not local, including Docker service names
(Coolify) and mongodb+srv://.
How a seed tells "edited since seeding"
| Method | How it works | Status |
|---|---|---|
| Timestamps | updatedAt is at most SEED_UNTOUCHED_SECONDS (default 120) after createdAt. The seed's own writes happen in that window; any later save, by an editor or by a seed update, moves updatedAt. |
primary — works in every project, no schema change |
| Seed hash | A hidden text field (default name seedHash) stores a hash of the values the seed wrote. On the next run the seed hashes the current values at the same keys. A different hash = an editor changed something. |
optional — needs a field in the collection or global |
Timestamps are simple and safe, but they allow one update per record: after a seeded update
updatedAt moves on, so the next run reports skip (edited). When you need repeated updates, add the
hash field. The templates use it automatically when the collection or global has a top-level field with
that name; the stored hash then decides instead of the timestamps.
// a collection (pages) or a global — for forms use ipalKit({ forms: { formOverrides: { fields } } })
{ name: 'seedHash', type: 'text', admin: { hidden: true } }
Postgres: adding the field needs a migration (pnpm payload migrate:create).
Payload sets updatedAt on every save, so a seed cannot "reset" it. A hash that differs only because of
storage formatting counts as edited — the safe side.
Locales
Write the default locale first. It creates the structure: blocks and array rows. Then write every other locale onto the same row ids. New row ids would wipe the other languages' texts.
Read and write every non-default locale with fallbackLocale: false. With localization.fallback: true,
Payload fills missing values from the fallback locale. An update in locale X without
fallbackLocale: false saves those fallback values as the X translation: the Polish text ends up in the
English version. See also i18n.md.
Context flags
Pass them in context on every create, update and updateGlobal:
| Flag | Read by | Effect |
|---|---|---|
disableRevalidate: true |
buildRevalidateHook (hooks.md) |
no revalidatePath for seeded records (outside Next the hook already does nothing) |
ipalSkipIndexNow: true |
the IndexNow hook (indexNow option, seo.md) |
no IndexNow ping for seeded, often placeholder, content |
ipalSeed: true |
nothing in the plugin | lets the project's own hooks recognise a seed |
Running a seed on Coolify
- Coolify → the application → Terminal → the app container (deployment.md §4.7).
- Dry run:
SEED_DRY_RUN=1 pnpm payload run scripts/seed-content.ts. - Back up the database (Backup now).
- The real run, without
SEED_DRY_RUN.
The seed script and its dependencies must be in the image. Env vars (DATABASE_URI, PAYLOAD_SECRET, …)
must be available at runtime, not only at build time. The container already has NODE_ENV=production, so
SEED_UPDATE=1 is refused there unless you add IPAL_SEED_ALLOW_PROD_UPDATE=1.
Seeds or migrations?
| Change | Tool |
|---|---|
| Schema: new field, new collection, changed type | Payload migration: pnpm payload migrate:create, runs on deploy (deployment.md §4.3) |
| Data fix that must run exactly once on every database | Payload migration |
| Field rename or move that must keep content | the ipal-migrate-fields skill |
| Content: pages, forms, globals from a brief | seed |
A seed never changes the schema. A migration never fills editorial content from a brief.
Turn off, override, extend
The guards are defaults in the templates. The project can change them — at the top of each template
(SAFETY block) or through env:
| Env var / constant | Default | What it does |
|---|---|---|
SEED_DRY_RUN=1 / --dry-run |
off | no writes, print the plan |
SEED_UPDATE=1 |
off | update records nobody edited since seeding |
IPAL_SEED_ALLOW_PROD_UPDATE=1 |
off | allow SEED_UPDATE=1 on production or a non-local database |
SEED_FORCE=1 |
off | with SEED_UPDATE=1: overwrite edited records too. Local database only (FORCE_ONLY_LOCAL) |
SEED_LOCAL_HOSTS |
— | extra hosts that count as local, comma-separated (e.g. a Docker Compose db service) |
SEED_DB_URL_ENV |
DATABASE_URI |
the env var that holds the database URL |
SEED_UNTOUCHED_SECONDS |
120 |
the timestamp window for "untouched since creation" |
SEED_HASH_FIELD |
seedHash |
the hash field name; empty = timestamps only |
SEED_NOTIFY_EMAIL |
— | form seed: notification address for a first run when the company global is still empty |
The plugin itself has no seed option and no seed code. The templates are plain project scripts: edit them freely, but keep the rules above.