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]>
This commit is contained in:
Radosław Smoliński
2026-10-29 13:27:46 +01:00
co-authored by Claude Opus 5.5
parent 9ecab39783
commit af7d96f0e3
19 changed files with 331 additions and 46 deletions
+29 -12
View File
@@ -1,5 +1,12 @@
# seeding — content seeds that never overwrite production
> **VERY IMPORTANT — the first rule of seeding.** Once a site is live, **never run a full seed again**: the owner's
> edits on the live site must survive. Every later change targets **named records only** — specific pages,
> globals, forms or fields — listed in the seed (`only: [...]` / `SEED_ONLY="pages:kontakt,global:header"`).
> Never re-seed everything, not even in create-only mode, without the owner's explicit OK. `createSeeder`
> refuses a run with no record list against a production or non-local database unless `IPAL_SEED_ALLOW_FULL=1`
> (set it only after that OK).
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:
@@ -26,13 +33,17 @@ should use it too; if it does not, it must follow the rules by hand.
3. **Never delete.** No `payload.delete`, no "clean up first". A record that should go away is removed by a
person in the panel.
4. **Never seed users, passwords or secrets.** SMTP, Turnstile, API keys and tokens stay in the panel or in
4. **After launch, named records only.** Before launch the seed may build the whole site. After launch a seed
lists exactly the records it may touch (`only`, `SEED_ONLY`) — everything else is reported as
`skip (not listed)` and never read for writing. A full run against a live database needs the owner's explicit
OK and `IPAL_SEED_ALLOW_FULL=1`. Record the launch date in `AGENTS.md` → "Project decisions".
5. **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.
5. **Globals: fill only empty fields.** A field that already has content is kept.
6. **Media: leave upload fields empty or reference existing uploads by ID.** Never upload files in a
6. **Globals: fill only empty fields.** A field that already has content is kept.
7. **Media: leave upload fields empty or reference existing uploads by ID.** Never upload files in a
production seed. The editor adds images.
7. **Write each locale separately, with `fallbackLocale: false`.** See [Locales](#locales).
8. **Pass the context flags** the plugin reads. See [Context flags](#context-flags).
8. **Write each locale separately, with `fallbackLocale: false`.** See [Locales](#locales).
9. **Pass the context flags** the plugin reads. See [Context flags](#context-flags).
## Running a seed
@@ -41,6 +52,7 @@ should use it too; if it does not, it must follow the rules by hand.
| `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 |
| `SEED_ONLY="pages:kontakt,global:header" pnpm payload run scripts/seed-content.ts` | after launch: only the listed records (`collection:slug`, `forms:<title>`, `global:<slug>`, `collection:*`) |
`--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`.
@@ -53,19 +65,20 @@ Every run prints one line per record and a summary:
| `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) |
| `skip (not listed)` | the record is not on the run's list (`only` / `SEED_ONLY`); it is not touched |
| `error` | the write failed; the script exits with code 1 |
The summary table counts `created`, `skipped`, `updated`, `skipped-edited` and `errors`.
The summary table counts `created`, `skipped`, `updated`, `skipped-edited`, `not listed` and `errors`.
## Before you run a seed on production
1. **Dry run.** Run the seed with `SEED_DRY_RUN=1` and read every line. Expect `create` and `skip (exists)`.
2. **Test on a copy.** Run it on staging or on a local copy of the production database first.
3. **Back up the database.**
2. **Dry run.** Run the seed with `SEED_DRY_RUN=1` and read every line. Expect `create` and `skip (exists)`.
3. **Test on a copy.** Run it on staging or on a local copy of the production database first.
4. **Back up the database.**
- Coolify: the database resource → **Backups** → **Backup now** ([deployment.md §4.6](./deployment.md)).
- Postgres by hand: `pg_dump -Fc "$DATABASE_URI" > before-seed.dump`
- MongoDB by hand: `mongodump --uri="$DATABASE_URI" --archive=before-seed.archive`
4. **Run it for real.** Check the panel and the site.
5. **Run it for real.** Check the panel and the site.
**Restore, if something went wrong:**
@@ -135,13 +148,15 @@ Pass them in `context` on every `create`, `update` and `updateGlobal` (`createSe
## Running a seed on Coolify
1. Coolify → the application → **Terminal** → the app container ([deployment.md §4.7](./deployment.md)).
2. Dry run: `SEED_DRY_RUN=1 pnpm payload run scripts/seed-content.ts`.
2. Dry run with the record list: `SEED_ONLY="pages:kontakt" SEED_DRY_RUN=1 pnpm payload run scripts/seed-content.ts`
— the plan must name only the records the owner asked for.
3. Back up the database (**Backup now**).
4. 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`.
`SEED_UPDATE=1` is refused there unless you add `IPAL_SEED_ALLOW_PROD_UPDATE=1`, and a run without `SEED_ONLY`
is refused unless you add `IPAL_SEED_ALLOW_FULL=1` (only with the owner's explicit OK).
## Seeds or migrations?
@@ -218,6 +233,8 @@ the script:
|---|---|---|---|
| `SEED_DRY_RUN=1` / `--dry-run` | `dryRun` | off | no writes, print the plan |
| `SEED_UPDATE=1` | `update` | off | update records nobody edited since seeding |
| `SEED_ONLY` | `only` | all records | the records the run may touch: `pages:kontakt`, `forms:Contact form`, `global:header`, `pages:*` (comma-separated in env) |
| `IPAL_SEED_ALLOW_FULL=1` | `guard.allowFull` | off | allow a run without `only` on production or a non-local database (a full re-seed — owner's OK only) |
| `IPAL_SEED_ALLOW_PROD_UPDATE=1` | `guard.allowProdUpdate` | off | allow `update` on production or a non-local database |
| `SEED_FORCE=1` | `force` | off | with `update`: overwrite edited records too. Local database only (`guard.forceOnlyLocal: false` lifts that) |
| `SEED_LOCAL_HOSTS` | `guard.localHosts` | — | extra hosts that count as local, comma-separated (e.g. a Docker Compose `db` service) |