Skip to content
The record
Finding20 August 20264 min read

A merge moves lines, it never copies them — and the discipline of deleting features that work

The invariant that makes merging two part-built pallets safe is that a merge moves lines rather than copying them, because a copying merge would silently inflate every total in the system by exactly the merged quantity; alongside it, the two-commit house rule for removals — drop the code first, drop the table second.

systemsitad-lifecyclemethod

What was done

Two half-built pallets of the same product can now be merged onto a new one. The rule the tests exist to protect is that a merge moves lines and never copies them: a copying merge would leave the same stock in two containers and inflate the pallet count, the inventory roll-up and every report by exactly the merged quantity, with nothing erroring. Merge is held to exactly two pallets at a time because an N-way merge is much harder to reason about when it half-fails, and two-at-a-time repeated is equivalent and recoverable; one deployment bug is recorded here too, where PalletMerge compiled and the migration ran but the module was never registered, so the feature passed its tests and 500'd in the deployed app. The repair logging module, built on 12 July, was removed six weeks later as unused - the warehouse grades and sells or breaks devices rather than running a workshop - and that removal set the house rule for removals: drop the code first, drop the table second, because they deploy separately and dropping a table while code still references it is an outage.

MOVE (what it does)     COPY (the bug it avoids)
-------------------     ------------------------
A: 12 ]                 A: 12 ]
B:  8 ]--> C: 20        B:  8 ]--> C: 20
A: 0  (merged)          A: 12  (still counted)
B: 0  (merged)          B:  8  (still counted)
-------------------     ------------------------
system total 20         total 40, nothing errors
 
one UPDATE re-points the rows; no INSERT anywhere

Why the invariant is the whole feature


Status

Shipped, 20–21 August 2026.

Pallet merge, and the invariant it rests on

merge pallets onto a new pallet.

Two half-built pallets of the same product should become one. The rule that makes this safe, and which the tests exist to protect:

A merge MOVES lines. It never copies them.

If a merge copied, the stock would exist in two places at once and every total in the system — the pallet count, the inventory roll-up, the reports — would be wrong by exactly the merged quantity. Nothing would error; the numbers would just be too big, and it would be nearly impossible to trace back.

hold merge to exactly two pallets. An N-way merge is more flexible and much harder to reason about when it half-fails. Two at a time, repeated, is equivalent and recoverable.

pallet detail 500: PalletMerge was never registered with the running app. The entity existed, the migration ran, and the module was not wired in — so the feature worked in tests and 500'd in the deployed app. A reminder that in NestJS, an entity that compiles is not an entity the app can load.

The workspace gave pallets filter, sort, select and export; fixed the

defects that reviewing it exposed; put the row actions behind a menu.

** — the export opens on the Items sheet, not the summary.** A workbook that opens on a summary makes the reader hunt for the data. Also fixed date-formatted metadata that Excel was reinterpreting.

Removing the repairs module

** then — remove the repair logging module, then drop the repair_logs table.**

Built on 12 July, removed six weeks later. It was not being used: the warehouse does not run a repair workshop with per-device work logs, it grades devices and either sells or breaks them.

The two-commit pattern is deliberate and is now the house rule for removals: drop the code first, drop the table second. They deploy separately. Dropping the table while code still references it is an outage; dropping the code first means the table sits unused for one deploy and then goes.

What was kept: the audit verdicts. The repairs module had accumulated grading information that was genuinely in use, and that was preserved rather than going with the table.

costing and invoicing unhooked from the pallet on the same principle. Both were attached to pallets because that was where they were first needed, not because they belong there.

Why it matters

Three features deleted in one month — warranty tracking, sales, repairs — each working, each modelling something the business does not do. The discipline of removing them is why the app stayed navigable enough to redesign into five nav groups a few days later.

What was deliberately not built

No undo for a merge. It moves lines between containers and both remain; the recovery is a merge back.

Open questions

None outstanding.


The code

The invariant as it is actually written: one UPDATE re-points the existing rows (apps/api/src/pallets/pallets.service.ts, mergePallets)

// Lines MOVE: one UPDATE per source, re-pointing rows that already exist.
// Nothing is inserted, so no quantity can be counted twice.
for (const source of ordered) {
  // OVERWRITE source_pallet_id - never COALESCE it with the existing
  // value. It means ONE HOP: the immediate pre-merge parent. If A was
  // itself merged from X and Y, then A+B into C, C's rows must name A,
  // not X. The full chain lives in pallet_merges.
  await lines.update(
    { palletId: source.id },
    {
      palletId: created.id,
      sourcePalletId: source.id,
      sourcePalletNumber: source.palletNumber,
    },
  );
}
// shippedAt deliberately untouched - merging is not shipping.
await pallets.update({ id: In(ids) }, { status: PalletStatus.MERGED });
From apps/api/src/pallets/pallets.service.ts — an excerpt, trimmed to the technique it illustrates.

Not shown. The surrounding transaction is summarised in prose rather than shown: the pessimistic row lock, its deterministic ordering (unordered ids made opposite-order merges deadlock instead of queueing), the re-validation inside the lock because the operator's preview may be seconds stale, and the merge-blocker list. Also left out: the audit row written per source, the activity log, and the inheritance rules for supplier and location. Those are the implementation; the excerpt is the one idea.

A published copy. Commit references and internal identifiers have been removed and the operator is not named; the engineering, the counts and the stated limits are unchanged.