@dooer/dooer-test-env 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,15 +15,33 @@ const PROFILES = ['full', 'frontend', 'hq', 'booking']
15
15
  // `full` (everything staging runs) — compose profiles are additive, so we must name it explicitly.
16
16
  // See ENVIRONMENT-PLAN.md §6.
17
17
 
18
+ // Regenerate when the generator is newer than the file it produced. It used to generate only when the
19
+ // file was ABSENT, which meant a CLI upgrade never reached an existing environment: every generator fix
20
+ // (a container flag, a new service, an image bump) silently applied to new installs only, and the way you
21
+ // found out was a bug that was already fixed. An npm install rewrites lib/, so its mtime moves ahead of a
22
+ // compose file generated by the previous version, and a local edit to the generator does the same.
23
+ // The compose file is a build artifact — anything hand-edited there was already lost on the next `db pull`.
24
+ function composeIsStale() {
25
+ if (!fs.existsSync(rt.COMPOSE_FILE)) return true
26
+ try {
27
+ const generator = require.resolve('../compose/generate')
28
+ return fs.statSync(generator).mtimeMs > fs.statSync(rt.COMPOSE_FILE).mtimeMs
29
+ } catch (_) {
30
+ return false // never block `up` on a stat that failed
31
+ }
32
+ }
33
+
18
34
  function ensureCompose() {
19
35
  rt.ensureRunDir()
20
- if (!fs.existsSync(rt.COMPOSE_FILE)) {
36
+ if (composeIsStale()) {
37
+ const existed = fs.existsSync(rt.COMPOSE_FILE)
21
38
  const r = generateCompose({
22
39
  servicesDir: rt.SERVICES_DIR,
23
40
  out: rt.COMPOSE_FILE,
24
41
  outputValidation: !!rt.readState().outputValidation,
25
42
  })
26
- console.log(chalk.gray(`generated ${rt.COMPOSE_FILE} (${(r && r.serviceCount) || 'n'} services)`))
43
+ const what = existed ? 'regenerated (CLI is newer)' : 'generated'
44
+ console.log(chalk.gray(`${what} ${rt.COMPOSE_FILE} (${(r && r.serviceCount) || 'n'} services)`))
27
45
  }
28
46
  return rt.COMPOSE_FILE
29
47
  }
@@ -242,6 +242,12 @@ function infraServices() {
242
242
  'ssl_cert_file=/etc/postgresql/server.crt',
243
243
  '-c',
244
244
  'ssl_key_file=/etc/postgresql/server.key',
245
+ // A full Dooer DB is ~163 schemas / 25k tables+sequences, and `db snapshot` runs pg_dump, which
246
+ // takes an ACCESS SHARE lock on every one of them inside a single transaction. The default 64
247
+ // gives ~64×(max_connections+prepared) lock slots and pg_dump dies partway with "out of shared
248
+ // memory / You might need to increase max_locks_per_transaction" — reliably, on a real base DB.
249
+ '-c',
250
+ 'max_locks_per_transaction=1024',
245
251
  ],
246
252
  environment: {
247
253
  POSTGRES_DB: 'dooer',
package/lib/copy.js CHANGED
@@ -93,6 +93,20 @@ async function copyOrganization({ organizationId, sourceEnv, targetEnv, reason,
93
93
  ` ${detail.rows} rows across ${detail.tables} tables`
94
94
  )
95
95
  console.log(` new organization id: ${chalk.bold(detail.organizationId)}`)
96
+
97
+ // Rows whose foreign key points at a parent that did not come with them. The load runs with FK
98
+ // enforcement off (no ordering of 336 tables satisfies every constraint), and Postgres never re-checks,
99
+ // so these commit silently — they have to be told, or the copy looks clean when it is not.
100
+ if (detail.danglingRows) {
101
+ console.log(chalk.yellow(`\n ${detail.danglingRows} row(s) reference a parent that was not copied:`))
102
+ for (const d of detail.dangling || []) {
103
+ console.log(` ${String(d.rows).padStart(6)} ${d.from} → ${d.to} (${d.cause})`)
104
+ }
105
+ console.log(
106
+ ' The copy is complete and usable; these references dangle. `parent table not in schema map`\n' +
107
+ ' means the map does not carry that parent — it will recur on every copy until the map changes.'
108
+ )
109
+ }
96
110
  console.log(` audit: export ${exported.id} (${source.name}), import ${imported.id} (${target.name})\n`)
97
111
 
98
112
  return { organizationId: detail.organizationId, rows: detail.rows, tables: detail.tables, skipped }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooer/dooer-test-env",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
4
4
  "description": "Run the whole Dooer backend locally (staging DB minus customers), copy/purge customers between environments, and shred — one CLI.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": "Dooer/cli-dooer-test-env",
package/readme.md CHANGED
@@ -254,10 +254,28 @@ npx @dooer/dooer-test-env@latest customer copy \
254
254
  # optional: shred the rest of the PII afterwards (localhost only)
255
255
  npx @dooer/dooer-test-env@latest shred --execute
256
256
 
257
- # undo: delete that org again (rows + its S3 objects), dry-run first
257
+ # undo: delete that org's rows again dry-run first (omit --execute)
258
258
  npx @dooer/dooer-test-env@latest customer purge --org <orgId> --local --execute
259
259
  ```
260
260
 
261
+ **What the purge does not do:** it deletes rows, **not S3 objects**. A purged org leaves its uploaded
262
+ documents in the bucket; the command says so in its own output. Removing them needs bucket credentials the
263
+ service does not hold today.
264
+
265
+ **Dangling references.** The load runs with foreign-key enforcement off — no ordering of 336 tables
266
+ satisfies every constraint on the way in — and Postgres never re-checks afterwards, so a copied row whose
267
+ parent is missing would otherwise commit silently. The import checks the rows it wrote and reports any
268
+ that dangle:
269
+
270
+ ```
271
+ 44 row(s) reference a parent that was not copied:
272
+ 42 service_workflow.run.definitionId → service_workflow.definition (parent table not in schema map)
273
+ 2 service_accounts.systemMessageRecipient.systemMessageId → service_accounts.systemMessage
274
+ ```
275
+
276
+ `parent table not in schema map` means the map does not carry that parent at all, so it recurs on every
277
+ copy until the map changes. The copy is complete and usable; those references dangle.
278
+
261
279
  Naming: with **neither `--name` nor `--target`** the copy creates a new org that **keeps the source org's
262
280
  own name** (its `short_name` still gets a unique suffix). Pass `--name` to rename it, or `--target <uuid>`
263
281
  to copy into an org that already exists.