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
+25
View File
@@ -2,12 +2,21 @@ import type { EnvRule } from './assertEnv.js'
type TurnstileNames = { secretVar?: string; siteKeyVar?: string }
import { checkDatabaseName } from './databaseName.js'
export type IpalEnvFeatures = {
/**
* Cookie crawl (cookieScanner.crawl): the scanner service URL and the shared
* token (at least 16 characters). Required in production only.
*/
cookieCrawl?: boolean
/**
* Warn (never fail) when the database name in DATABASE_URI breaks the naming rule
* `<domain without dots>_prod` / `_dev` (docs/deployment.md). `true` takes the domain from
* NEXT_PUBLIC_SERVER_URL (skipped for localhost); `{ domain }` sets it; `{ warn }` replaces
* the console.warn. Default off.
*/
databaseName?: { domain?: string; warn?: (message: string) => void } | boolean
/** Override the database var. Default 'DATABASE_URI'. */
databaseVar?: string
/** Microsoft Graph e-mail (graphAdapter). Adds the GRAPH_* vars. */
@@ -62,6 +71,7 @@ export type IpalEnvFeatures = {
export function ipalEnvRules(features: IpalEnvFeatures = {}): EnvRule[] {
const {
cookieCrawl = false,
databaseName = false,
databaseVar = 'DATABASE_URI',
emailGraph = false,
ipHeader = false,
@@ -158,5 +168,20 @@ export function ipalEnvRules(features: IpalEnvFeatures = {}): EnvRule[] {
)
}
if (databaseName) {
const { domain, warn = (message: string) => console.warn(`[ipal] ${message}`) } = databaseName === true ? {} : databaseName
rules.push({
name: databaseVar,
description: 'Database name: <domain without dots>_prod / _dev (warning only)',
required: false,
// A warning, never an error: the project may have a reason (an old database, a shared server).
validate: (value) => {
const message = checkDatabaseName({ databaseUri: value, domain: domain ?? process.env[serverUrlVar] })
if (message) {warn(`${databaseVar}: ${message}`)}
return true
},
})
}
return rules
}