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:
co-authored by
Claude Opus 5.5
parent
9ecab39783
commit
af7d96f0e3
+18
-2
@@ -36,6 +36,19 @@ patch `node_modules` or fork the package.
|
||||
**Docs language:** all ipal-kit docs, this guide and the skills are written in English.
|
||||
Write new rules, AGENTS.md entries and plugin-gap reports in English.
|
||||
|
||||
> **VERY IMPORTANT — seeding after launch.** 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).
|
||||
|
||||
**Database names** (MongoDB and Postgres): the site's domain **with the dots removed**, plus `_prod` or `_dev` —
|
||||
`intecion.com` → `intecioncom_prod` / `intecioncom_dev`, `architektimprez.pl` → `architektimprezpl_prod` /
|
||||
`architektimprezpl_dev`. The name is the path of `DATABASE_URI`: `mongodb://…@mongo:27017/intecioncom_prod?authSource=admin`,
|
||||
`postgres://…@db:5432/intecioncom_prod`. You derive the names from the domain and confirm them with the owner (ipal-setup
|
||||
stage 0). `ipalEnvRules({ databaseName: true })` warns when they do not match (deployment.md §4.2a).
|
||||
|
||||
**Seeding on production** (details: `node_modules/@intecion/ipal-kit/docs/seeding.md`). Write seeds with
|
||||
`createSeeder` from `@intecion/ipal-kit/seed` (the templates do) — it enforces every rule below:
|
||||
- Seeds are create-only and idempotent: match by the default-locale slug / form title / the global, skip what exists.
|
||||
@@ -44,6 +57,7 @@ Write new rules, AGENTS.md entries and plugin-gap reports in English.
|
||||
- On production: dry run first (`SEED_DRY_RUN=1`), back up the database (Coolify **Backup now**), then the real run.
|
||||
- `SEED_UPDATE=1` on production / a non-local database only with `IPAL_SEED_ALLOW_PROD_UPDATE=1`, after a backup;
|
||||
records an editor changed are always skipped and reported (`skip (edited)`) — never use `SEED_FORCE=1` there.
|
||||
- After launch: named records only (`only` / `SEED_ONLY`); a full run of a live database is refused without `IPAL_SEED_ALLOW_FULL=1`.
|
||||
- Schema and one-off data fixes → Payload migrations; field renames with content → **ipal-migrate-fields**; content → seeds.
|
||||
|
||||
## Ask before you build — architecture questions
|
||||
@@ -60,7 +74,7 @@ the ready-to-send list is in **ipal-setup** stage 0 (ipal-site phase 0 uses the
|
||||
| Forms | which forms, who receives them, e-mail provider (SMTP from the panel or Microsoft Graph) |
|
||||
| Analytics and consent | GA4 / GTM / pixels, Consent Mode basic or advanced, cookie banner mode, cookie scan |
|
||||
| SEO / GEO | market and local business data, AI crawler policy (llms.txt, Markdown, MCP, AI bots) |
|
||||
| Data and media | database (Postgres or MongoDB), media storage (R2 or local disk) |
|
||||
| Data and media | database (Postgres or MongoDB) and its names (`<domain without dots>_prod` / `_dev` — derive, then confirm), media storage (R2 or local disk) |
|
||||
| Admin | 2FA, white-label (client brand in the panel), agency credit |
|
||||
| Hosting | Coolify, the production domain(s), who adds the DNS records (deployment.md §6) |
|
||||
|
||||
@@ -1290,10 +1304,12 @@ Write everything in this file in English.
|
||||
|
||||
## Project decisions
|
||||
- Architecture answers (AGENT.md "Ask before you build"), one line each: languages + default + URLs ·
|
||||
styling · pages/collections · forms + e-mail · analytics/consent/cookie scan · SEO/GEO · database + media ·
|
||||
styling · pages/collections · forms + e-mail · analytics/consent/cookie scan · SEO/GEO · database (+ names
|
||||
`<domain>_prod` / `<domain>_dev`, e.g. `intecioncom_prod`) + media ·
|
||||
2FA/white-label/credit · hosting + domains + DNS
|
||||
- <client-specific decisions, e.g. "blog without authors", "404 = homepage">
|
||||
- <approved workarounds: what, why, plugin-request file, owner's approval>
|
||||
- Launch date: <date> — from then on seeds touch named records only (AGENT.md "seeding after launch")
|
||||
- <exceptions to the rules — with the reason>
|
||||
- <only on a client decision> ipal-audit-skip: <keys from AGENT.md §0b> — <reason, source of the decision>
|
||||
```
|
||||
|
||||
@@ -114,6 +114,8 @@ Commit the script — in production run it after the migration: `SEED_DRY_RUN=1`
|
||||
the real run (rules: `node_modules/@intecion/ipal-kit/docs/seeding.md`). Changing the form: fix FORM,
|
||||
`SEED_UPDATE=1 pnpm payload run …` — it updates the form only if nobody edited it since seeding (otherwise
|
||||
`skip (edited)`); on production / a non-local database it also needs `IPAL_SEED_ALLOW_PROD_UPDATE=1`.
|
||||
**After launch** a form seed touches only its own form (`only: ['forms:<title>']` in the template) — never re-run
|
||||
every form seed or the content seed to change one form (AGENT.md "seeding after launch").
|
||||
|
||||
Details the seed already covers, which you check after every manual change in the panel:
|
||||
1. **Forms → the form**: fields from the brief, `name` in English, lowercase
|
||||
|
||||
@@ -106,7 +106,9 @@ function richText(text: string) {
|
||||
|
||||
const payload = await getPayload({ config })
|
||||
// Options (docs/seeding.md § Turn off, override, extend) — env vars work without editing this file.
|
||||
const seed = createSeeder(payload, { label: '[seed-form]' })
|
||||
// A form seed touches exactly one record — this form (matched by its title). After launch that stays true:
|
||||
// it never re-seeds other forms, and an edited form is skipped (docs/seeding.md, "after launch").
|
||||
const seed = createSeeder(payload, { label: '[seed-form]', only: [`forms:${FORM.title}`] })
|
||||
|
||||
// Notification address — from the panel, never from this file.
|
||||
let notifyTo = process.env.SEED_NOTIFY_EMAIL?.trim() ?? ''
|
||||
|
||||
@@ -149,7 +149,7 @@ Mandatory set: AGENT.md §0b, skill **ipal-setup**; checks: **ipal-audit**, **ip
|
||||
| languages | `src/i18n.config.ts` | `export const i18nConfig = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] } as const satisfies I18nConfig` | `curl -sI $U/` → 3xx to `/pl` | i18n.md |
|
||||
| proxy | `src/proxy.ts` | `export const proxy = createProxy(i18nConfig, { NextResponse, markdown: true })` + `export const config = { matcher: ['/((?!api\|admin\|_next\|.*\\..*).*)'] }` (a literal!) | `curl -sI $U/` → `/pl`; `curl -s -H 'Accept: text/markdown' $U/pl` → Markdown | i18n.md, PROGRAMISTA §2.6 |
|
||||
| proxy (Next 15 / custom) | `middleware`/`proxy.ts` | `createLocaleMiddleware({ config, … })` (`/next/middleware` or the main entry) | as above | i18n.md |
|
||||
| env validation | `src/instrumentation.ts` | `if (process.env.NEXT_RUNTIME === 'nodejs') assertEnv(ipalEnvRules({ storage: true, ipHeader: true }))` from `@intecion/ipal-kit/env` | remove a variable → startup fails with the list of missing ones | env.md |
|
||||
| env validation | `src/instrumentation.ts` | `if (process.env.NEXT_RUNTIME === 'nodejs') assertEnv(ipalEnvRules({ storage: true, ipHeader: true, databaseName: true }))` from `@intecion/ipal-kit/env` | remove a variable → startup fails with the list of missing ones; a database not named `<domain>_prod`/`_dev` → a warning | env.md, deployment.md §4.2a |
|
||||
| Next config | `next.config.ts` | `withPayload(withSecurityConfig({ images: buildImagesConfig(), htmlLimitedBots: /Googlebot\|Bingbot…/i, headers: async () => [{ source: '/:path*', headers: buildSecurityHeaders({ hsts, csp }) }, { source: '/admin/:path*', headers: buildAdminCspHeaders(csp) }, ...buildUploadSecurityHeaders()] }))` | `curl -sI $U/pl \| grep -iE 'x-content-type\|strict-transport\|x-powered-by'` (no `x-powered-by`) | security.md, storage.md, PROGRAMISTA §2.9 |
|
||||
| CSP | `next.config.ts`, `src/app/api/csp-report/route.ts` | `csp = { mode: 'report-only', reportUri: '/api/csp-report', r2Url, <flags> }` in `buildSecurityHeaders` + `buildAdminCspHeaders`; route `export const POST = createCspReportRoute()`; after clean reports `mode: 'enforce'` | `curl -sI $U/pl \| grep -i content-security-policy-report-only`; browser console and `[csp]` log lines without violations | security.md |
|
||||
| data / routes | `src/lib/content.ts` | `export const { … } = createContentHelpers({ config, content, i18n: i18nConfig, baseUrl, markdownAlternate: true, summaryField: 'aiSummary', mcp: { serverName } })` | `pnpm tsc --noEmit` | frontend.md, PROGRAMISTA §2.7 |
|
||||
@@ -218,7 +218,7 @@ and what throws without `i18n`: frontend.md. `SiteProviders` props: `shell`, `ba
|
||||
|
||||
| variable | required when | effect when missing | where to set |
|
||||
|---|---|---|---|
|
||||
| `DATABASE_URI` | always (Payload; `ipalEnvRules` always) | no database, startup fails | env (name: `databaseVar`) |
|
||||
| `DATABASE_URI` | always (Payload; `ipalEnvRules` always) | no database, startup fails | env (name: `databaseVar`); the database is named `<domain without dots>_prod` / `_dev` (`intecioncom_prod`), checked by `databaseName: true` |
|
||||
| `PAYLOAD_SECRET` | always | Payload does not start; `assertEnv` throws | env, ≥32 characters, different in prod (`secretVar`) |
|
||||
| `NEXT_PUBLIC_SERVER_URL` | always (`kind: 'url'`) | sitemap/robots/canonical/JSON-LD/llms with origin `''` (relative), IndexNow does not send, R2 relative URL without a prefix | env (`serverUrlVar`) |
|
||||
| `NODE_ENV` | no (`development`/`production`/`test`) | `production` is stricter: R2 and `IPAL_IP_HEADER` required, IndexNow works, IP warning, `buildImagesConfig` prod | set by Next / hosting |
|
||||
@@ -237,13 +237,15 @@ Details: env.md, deployment.md, PROGRAMISTA §3.
|
||||
|
||||
**DNS** (A/AAAA, www, CAA, Search Console TXT, Bing, SPF/DKIM/DMARC for the From domain, R2 domain): the plugin sets nothing — list of records to check with `dig`: `deployment.md` §6, summary in **ipal-setup** stage 11.
|
||||
|
||||
**Seeding** (content in pages, forms, globals): create-only, matched by a natural key, never delete, never seed users or secrets, dry run → backup → real run; updates on production only for untouched records and only with `IPAL_SEED_ALLOW_PROD_UPDATE=1`. Helper: `createSeeder` from `@intecion/ipal-kit/seed` (resources/api.md → Seeding). Templates: `ipal-site/resources/seed-content.template.ts`, `ipal-form/resources/seed-form.template.ts`. Rules and Coolify steps: `node_modules/@intecion/ipal-kit/docs/seeding.md`.
|
||||
**Seeding** (content in pages, forms, globals) — **VERY IMPORTANT: after launch never re-seed everything; named records only** (`only` / `SEED_ONLY`; a full run of a live database needs the owner's OK and `IPAL_SEED_ALLOW_FULL=1`). Create-only, matched by a natural key, never delete, never seed users or secrets, dry run → backup → real run; updates on production only for untouched records and only with `IPAL_SEED_ALLOW_PROD_UPDATE=1`. Helper: `createSeeder` from `@intecion/ipal-kit/seed` (resources/api.md → Seeding). Templates: `ipal-site/resources/seed-content.template.ts`, `ipal-form/resources/seed-form.template.ts`. Rules and Coolify steps: `node_modules/@intecion/ipal-kit/docs/seeding.md`.
|
||||
|
||||
| Seed env var (run time) | Effect |
|
||||
|---|---|
|
||||
| `SEED_DRY_RUN=1` (or `--dry-run`) | no writes, print the plan |
|
||||
| `SEED_UPDATE=1` | also update records nobody edited since seeding |
|
||||
| `IPAL_SEED_ALLOW_PROD_UPDATE=1` | allow `SEED_UPDATE=1` on production / a non-local database (back up first) |
|
||||
| `SEED_ONLY` | the records a run may touch (`pages:kontakt,global:header`) — required after launch |
|
||||
| `IPAL_SEED_ALLOW_FULL=1` | allow a run without `SEED_ONLY` on production / a non-local database — owner's explicit OK only |
|
||||
| `SEED_FORCE=1` | with `SEED_UPDATE=1`: overwrite edited records too — local database only |
|
||||
| `SEED_LOCAL_HOSTS` | extra hosts that count as a local database (comma-separated) |
|
||||
| `SEED_DB_URL_ENV` | name of the env var holding the database URL (default `DATABASE_URI`) |
|
||||
|
||||
@@ -254,7 +254,10 @@ Opt-in with `ipalKit({ cookieScanner: true })`; the plugin wires the collection,
|
||||
| Export | Import from | What it does / when |
|
||||
|---|---|---|
|
||||
| `assertEnv(rules, { env?, label? })` | `@intecion/ipal-kit/env`, `@intecion/ipal-kit` | validates `process.env` against the rules at startup; collects every missing item and throws one error |
|
||||
| `ipalEnvRules({ storage?, emailGraph?, ipHeader?, turnstile?, serverUrlVar?, secretVar?, databaseVar? })` | `@intecion/ipal-kit/env`, `@intecion/ipal-kit` | ready rule set (`DATABASE_URI`, `PAYLOAD_SECRET`, `NEXT_PUBLIC_SERVER_URL` + `R2_*`/`GRAPH_*`/Turnstile/`IPAL_IP_HEADER` depending on the features used) for `assertEnv`; `R2_PUBLIC_URL` optional unless `storage: { requirePublicUrl: true }` |
|
||||
| `ipalEnvRules({ storage?, emailGraph?, ipHeader?, turnstile?, serverUrlVar?, secretVar?, databaseVar?, databaseName? })` | `@intecion/ipal-kit/env`, `@intecion/ipal-kit` | ready rule set (`DATABASE_URI`, `PAYLOAD_SECRET`, `NEXT_PUBLIC_SERVER_URL` + `R2_*`/`GRAPH_*`/Turnstile/`IPAL_IP_HEADER` depending on the features used) for `assertEnv`; `R2_PUBLIC_URL` optional unless `storage: { requirePublicUrl: true }`; `databaseName: true \| { domain?, warn? }` only warns when the `DATABASE_URI` database is not `<domain without dots>_prod` / `_dev` |
|
||||
| `databaseNamesFor(domainOrUrl)` | `@intecion/ipal-kit/env`, `@intecion/ipal-kit` | the two database names for a site: `intecion.com` → `{ prod: 'intecioncom_prod', dev: 'intecioncom_dev' }` (`www.` dropped, dots removed) |
|
||||
| `databaseNameFromUri(uri)` | `@intecion/ipal-kit/env`, `@intecion/ipal-kit` | the database name (URI path) of a Mongo / Postgres `DATABASE_URI`; null for SQLite files or no name |
|
||||
| `checkDatabaseName({ databaseUri, domain })` | `@intecion/ipal-kit/env`, `@intecion/ipal-kit` | warning text when the name breaks the rule, else null (skips localhost / no domain) — what `databaseName` uses |
|
||||
|
||||
**Types:** `EnvRule`, `EnvKind` — variable rule (`name`, `required`, `kind`, `oneOf`, `validate`); `AssertEnvOptions` — `assertEnv` options; `IpalEnvFeatures` — `ipalEnvRules` argument (all from `/env` and root).
|
||||
|
||||
@@ -520,7 +523,7 @@ Server only (`pnpm payload run`); never import it from client code, the Payload
|
||||
|
||||
| Export | Import from | What it does / when |
|
||||
|---|---|---|
|
||||
| `createSeeder(payload, { dryRun?, update?, force?, guard?, editCheck?, context?, pagesCollection?, label?, log? })` | `@intecion/ipal-kit/seed` | The seed rules in one place → `{ upsertBySlug, upsertBy, fillGlobal, summary, dryRun, update, force, local }`. Create-only by default, natural keys, never deletes, globals: empty fields only, every locale with `fallbackLocale: false` onto the same row ids, skips records edited since seeding, writes with `context` `{ ipalSeed, disableRevalidate, ipalSkipIndexNow }`. Throws when `update` runs on production / a non-local database without `IPAL_SEED_ALLOW_PROD_UPDATE=1`. Both seed templates use it. |
|
||||
| `createSeeder(payload, { dryRun?, update?, force?, only?, guard?, editCheck?, context?, pagesCollection?, label?, log? })` | `@intecion/ipal-kit/seed` | The seed rules in one place → `{ upsertBySlug, upsertBy, fillGlobal, summary, dryRun, update, force, local, only }`. `only` (or `SEED_ONLY`) = the records the run may touch (`pages:kontakt`, `forms:<title>`, `global:<slug>`, `pages:*`), the rest → `skip (not listed)`; a run without it against production / a non-local database throws unless `IPAL_SEED_ALLOW_FULL=1` (after launch: named records only). Create-only by default, natural keys, never deletes, globals: empty fields only, every locale with `fallbackLocale: false` onto the same row ids, skips records edited since seeding, writes with `context` `{ ipalSeed, disableRevalidate, ipalSkipIndexNow }`. Throws when `update` runs on production / a non-local database without `IPAL_SEED_ALLOW_PROD_UPDATE=1`. Both seed templates use it. |
|
||||
| `upsertBySlug(collection, data \| data[], { slugField? })` | (method of `createSeeder`) | Matches by the default-locale slug; an array creates missing records first, so `{ $page: 'slug' }` links work in any order. |
|
||||
| `upsertBy(collection, key, data)` | (method) | Matches by other keys, e.g. a form by `{ title }`. |
|
||||
| `fillGlobal(slug, data)` | (method) | Fills only empty fields of a global (all seeded fields with `update` when untouched). |
|
||||
|
||||
@@ -43,13 +43,19 @@ Before I set up the site I need your decisions on:
|
||||
5. Analytics and consent: GA4 / GTM / Meta / other pixels? Consent Mode basic or advanced? Cookie dialog
|
||||
inline / modal / detailed? Cookie scan of the finished site?
|
||||
6. SEO/GEO: market, local business (address, opening hours)? AI access (llms.txt, Markdown, MCP, AI bots) — on?
|
||||
7. Database: Postgres or MongoDB? Media: Cloudflare R2 or local disk (Coolify volume)?
|
||||
7. Database: Postgres or MongoDB? Names (rule: domain without dots + _prod / _dev) — for <domain> I will use
|
||||
<domainnodots>_prod and <domainnodots>_dev, OK? Media: Cloudflare R2 or local disk (Coolify volume)?
|
||||
8. Admin: 2FA (on by default), white-label with the client's logo, agency credit in the panel?
|
||||
9. Hosting: Coolify — which server/project? Production domain(s), www or apex? Who adds the DNS records?
|
||||
```
|
||||
**Code.** None — write every answer into `AGENTS.md` → "Project decisions" (one line per topic; template: AGENT.md §13).
|
||||
|
||||
**Check.** All nine topics have an answer in "Project decisions"; nothing in it says "assumed" or "default".
|
||||
**Database names** (VERY IMPORTANT, deployment.md §4.2a): derive them from the production domain — dots removed,
|
||||
plus `_prod` / `_dev` (`intecion.com` → `intecioncom_prod`, `intecioncom_dev`; `architektimprez.pl` →
|
||||
`architektimprezpl_prod`, `architektimprezpl_dev`) — and confirm them in question 7. Never `payload`, `test` or a guess.
|
||||
|
||||
**Check.** All nine topics have an answer in "Project decisions" (including both database names); nothing in it
|
||||
says "assumed" or "default".
|
||||
|
||||
**Turn off / override.** Never skipped. If the owner says "you decide" for a topic, write that down as their answer,
|
||||
propose a concrete choice and get a yes before you build it.
|
||||
@@ -403,7 +409,7 @@ export function register() {
|
||||
if (process.env.NEXT_RUNTIME !== 'nodejs') return
|
||||
// R2_PUBLIC_URL optional: media served through the app by default (storage.md, env.md)
|
||||
assertEnv(
|
||||
ipalEnvRules({ storage: true, ipHeader: true /* , emailGraph: true with Graph */ }).map((r) =>
|
||||
ipalEnvRules({ storage: true, ipHeader: true, databaseName: true /* , emailGraph: true with Graph */ }).map((r) =>
|
||||
r.name === 'R2_PUBLIC_URL' ? { ...r, required: false } : r,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -80,6 +80,9 @@ form with fields in JSX, an `api/contact` route, `nodemailer`, reCAPTCHA (AGENT.
|
||||
enter content from the brief: pages, blocks, links (`{ $page: 'slug' }`), globals —
|
||||
all languages side by side (`{ pl, en }`). Missing data → `[TO FILL: …]`.
|
||||
Never invent company data, prices, reviews, numbers, certificates, names.
|
||||
**VERY IMPORTANT — after launch never run the whole seed again** (the owner's edits must survive): a later
|
||||
change lists exactly the records it touches in `ONLY` / `SEED_ONLY` (e.g. `pages:kontakt,global:header`),
|
||||
checked with a dry run; a full re-seed only with the owner's explicit OK (`IPAL_SEED_ALLOW_FULL=1`).
|
||||
The template is a thin script over `createSeeder` (`@intecion/ipal-kit/seed`): keep the calls
|
||||
(`upsertBySlug`, `fillGlobal`, `summary`), change only CONTENT; options in docs/seeding.md.
|
||||
2. `pnpm payload run scripts/seed-content.ts` → the placeholder list goes into the report.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* 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
|
||||
@@ -16,6 +17,10 @@
|
||||
* - 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
|
||||
@@ -47,11 +52,14 @@ 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 }), { pagesCollection: COLLECTION })
|
||||
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)
|
||||
|
||||
+24
-2
@@ -19,8 +19,9 @@ Related: [PROGRAMISTA.md](./dev/PROGRAMISTA.md) (from zero to a working site, §
|
||||
### Core (REQUIRED — the project will not start without them)
|
||||
|
||||
```bash
|
||||
# Database (Mongo or Postgres — depending on the project)
|
||||
DATABASE_URI=mongodb://... # or postgres://... / file:./dev.db (dev)
|
||||
# Database (Mongo or Postgres — depending on the project); name = <domain without dots>_prod / _dev (§4.2a)
|
||||
DATABASE_URI=mongodb://user:pass@mongo:27017/intecioncom_prod?authSource=admin # or postgres://user:pass@db:5432/intecioncom_prod
|
||||
# dev: …/intecioncom_dev, or file:./dev.db
|
||||
|
||||
# Payload secret (signs sessions/tokens) — random, long
|
||||
PAYLOAD_SECRET=<random-string-min-32-chars>
|
||||
@@ -244,6 +245,27 @@ One Coolify **application** per project (built from the Git repo) plus a Coolify
|
||||
- **Redirect** www ↔ apex in the app's domain/redirect setting (Direction) so the canonical host is the one in
|
||||
`NEXT_PUBLIC_SERVER_URL` — canonical, hreflang and sitemap URLs use that variable, the redirect must agree with it.
|
||||
|
||||
### 4.2a Database names (VERY IMPORTANT)
|
||||
|
||||
Every project uses the same names, on MongoDB and Postgres: the site's domain **with the dots removed**, plus
|
||||
`_prod` (production) or `_dev` (development / staging). No other suffixes, no `payload`, `test` or `db1`.
|
||||
|
||||
| Site | Production | Development |
|
||||
|---|---|---|
|
||||
| `intecion.com` | `intecioncom_prod` | `intecioncom_dev` |
|
||||
| `architektimprez.pl` | `architektimprezpl_prod` | `architektimprezpl_dev` |
|
||||
|
||||
- The name is the path of `DATABASE_URI`: `mongodb://user:pass@mongo:27017/intecioncom_prod?authSource=admin`,
|
||||
`postgres://user:pass@db:5432/intecioncom_prod` (the Postgres database name, not the user or the schema).
|
||||
- In Coolify: create the database resource with that database name (Postgres "Initial database", or the name in the
|
||||
Mongo connection string), and set `DATABASE_URI` on the app to it.
|
||||
- A leading `www.` is not part of the name; a hyphen in the domain stays (quote the name in SQL:
|
||||
`CREATE DATABASE "my-sitepl_prod"`).
|
||||
- **Check:** `ipalEnvRules({ databaseName: true })` warns at startup (never fails) when the name in `DATABASE_URI`
|
||||
does not match the domain in `NEXT_PUBLIC_SERVER_URL` (skipped for localhost). `{ domain: 'intecion.com' }` sets the
|
||||
domain, `{ warn }` replaces the console warning; leave the option out to turn the check off. Helpers:
|
||||
`databaseNamesFor`, `databaseNameFromUri`, `checkDatabaseName` from `@intecion/ipal-kit/env` (env.md).
|
||||
|
||||
### 4.2 Environment variables — where and when
|
||||
|
||||
Coolify → the application → **Environment Variables**. Each variable can be available at **build time**,
|
||||
|
||||
+18
-1
@@ -67,6 +67,8 @@ ipalEnvRules({
|
||||
serverUrlVar?: string, // default 'NEXT_PUBLIC_SERVER_URL'
|
||||
secretVar?: string, // default 'PAYLOAD_SECRET'
|
||||
databaseVar?: string, // default 'DATABASE_URI'
|
||||
databaseName?: boolean | { domain?: string; warn?: (message: string) => void },
|
||||
// WARN (never fail) when the DATABASE_URI database is not <domain without dots>_prod / _dev
|
||||
})
|
||||
```
|
||||
|
||||
@@ -101,6 +103,21 @@ assertEnv([
|
||||
])
|
||||
```
|
||||
|
||||
### Database names — `databaseName`
|
||||
|
||||
The naming rule (deployment.md §4.2a): the site's domain with the dots removed, plus `_prod` / `_dev` —
|
||||
`intecion.com` → `intecioncom_prod` / `intecioncom_dev`. `ipalEnvRules({ databaseName: true })` adds a check that
|
||||
only **warns** (console, or your `warn`) when the database in `DATABASE_URI` breaks it. The domain comes from
|
||||
`NEXT_PUBLIC_SERVER_URL` in `process.env` (localhost and dotless hosts are skipped) or from `{ domain }`.
|
||||
|
||||
```ts
|
||||
import { checkDatabaseName, databaseNameFromUri, databaseNamesFor } from '@intecion/ipal-kit/env'
|
||||
|
||||
databaseNamesFor('https://www.intecion.com') // { prod: 'intecioncom_prod', dev: 'intecioncom_dev' }
|
||||
databaseNameFromUri('postgres://u:p@db:5432/intecioncom_prod') // 'intecioncom_prod' (null for file:/no name)
|
||||
checkDatabaseName({ databaseUri: process.env.DATABASE_URI, domain: 'intecion.com' }) // warning text or null
|
||||
```
|
||||
|
||||
## assertEnv — the validator
|
||||
|
||||
```ts
|
||||
@@ -151,7 +168,7 @@ redeploys.
|
||||
## Exports
|
||||
|
||||
```ts
|
||||
import { assertEnv, ipalEnvRules } from '@intecion/ipal-kit/env'
|
||||
import { assertEnv, checkDatabaseName, databaseNameFromUri, databaseNamesFor, ipalEnvRules } from '@intecion/ipal-kit/env'
|
||||
import type { EnvRule, EnvKind, AssertEnvOptions, IpalEnvFeatures } from '@intecion/ipal-kit/env'
|
||||
```
|
||||
|
||||
|
||||
+29
-12
@@ -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) |
|
||||
|
||||
Reference in New Issue
Block a user