On a fashion image site, pressing Download on one image produced a polite message: “Download request recorded. File permission is pending.” The wording suggests a queue and a reviewer, as if someone had decided this image needed approval. Nobody had decided anything. The message was the server’s way of saying that a row it expected did not exist.

A rule that lived in one afternoon’s SQL

The server allows a download only when the image version has a download grant (or a separate combination of approval, license and download flags). Three days earlier, when downloads were opened up, grants were inserted with a one-time SQL script for every image that was public at that moment: 1,219 of them. That script was correct. It just was not a rule. It described a snapshot.

After that, new images were published by one-off scripts written for each batch. None of them had a grant step, because the grant had never been part of publishing in the first place. A read-only count made the gap plain: 1,659 public images, 1,219 grants, 443 public images with no grant. The image that was reported had zero.

Put the rule where every publish has to pass

The obvious fix would be to add a grant step to the publish script. There was no such script to fix. Each batch had its own, and the next one would be written fresh. So the rule went into the database instead: a migration adds a trigger that, whenever a public release record is inserted, inserts the matching grant for that content and version. It uses insert-or-ignore, and it does not touch license or download-flag values. Whatever script publishes next, it has to write a release record, and the grant follows.

A test walks the path end to end: before release the download returns 404, a release record is written, a version-1 grant appears, and the download returns 200. The local suite passed 42 of 42. The production change was packaged as a backfill of the missing grants, then the trigger, then the migration record, with expected checks of zero missing grants and one trigger. Writing to the production database was handed to the operator to run; the result of that run is not recorded in the log I wrote this from.

A one-time fix that is right on the day it runs still has to be repeated by whoever comes next. If they do not know it exists, they will not.