Data

Why soft delete must be NOT NULL DEFAULT 0

One very small, very specific convention, and what it has caught.

If `is_deleted` allows NULL, then "not deleted" has two representations: 0 and NULL. Any condition written as `is_deleted = 0` silently drops the NULL rows.

This kind of data loss does not throw. You just notice one afternoon during reconciliation that the numbers are short, and you cannot find where.

So the convention is: the column is NOT NULL, defaults to 0, the base class adds the condition uniformly, and hand-written SQL must add it itself. It costs two extra words and buys "what you query is all of it".

Running the hand-written-SQL assertion inside the test suite makes a missing condition fail right there and print the real SQL — no waiting for production.

Last updated 2026-10-09← Articles