The big clean-up

Exercise 4 of 6 in chapter 11 · 280 XP · 5 objectives checked by tests

Topics covered: Long-running taskprogressIterate()--dry-runBatch processingtoIterable()Verbosity

The reservation book keeps growing. Reservations honored or canceled months ago pile up in it, and the reservation book page is slowing down. Gorm wants a big clean-up command, to run once a month (and one day, through a scheduled task).

A command that deletes data in bulk deserves some care: you want to be able to look before deleting, follow its progress, and be sure it copes with thousands of reservations.

Long-running tasks

Your mission

Write app:registre:purger (purge the reservation book):

  1. it deletes the finished reservations (honored or canceled) whose day is before the cutoff: by default, 30 days ago. The others stay put. Summary: 2 reservations purged.;
  2. --dry-run deletes nothing and announces 2 reservations would be purged.;
  3. --avant (before) chooses the cutoff: --avant 2026-08-01, or a relative one like --avant "last month". An unreadable date gives Command::INVALID and “Invalid date”;
  4. it processes the reservations in batches, with a progress bar, down to the very last one;
  5. with -v, it lists each purged reservation: “Boromir, July 2, 2026 (honored)”.

In the Console tab: app:registre:purger --dry-run --avant today -v, then without --dry-run.