ADR-0134 — The free plan is a row that says so
Status: Accepted · Date: 2026-08-30 · Track: 011 phase 01 · Supersedes: nothing · Builds on: ADR-0077, ADR-0113
Context
The only path in the tree that moves an account off a paid plan is the hourly
expire_subscriptions task. It assigns and compares the string 'free' against
users.plan_id INT:
UPDATE users SET plan_id = 'free', … WHERE … AND plan_id != 'free'
PostgreSQL coerces that literal when the statement is planned, so the error arrives with no matching rows at all. The task has errored on every hourly run it has ever made, and no subscription has ever expired — a paid account whose payment window closes stays paid indefinitely. It compiles in Go, which is why it survived; it was found by running it (011's chartering evidence, and phase 01's own run against a migrated PostgreSQL 16).
The failure is in both halves of the statement, which makes it a shape rather
than a typo. "The free plan" was a name, and the product has no plan called
free: the seed's row is Free, an operator may rename it, and a deployment's
bottom rung may be a different row entirely.
The same question arrives from the other side. users.plan_id is INT NOT NULL DEFAULT 0, all three create paths stamp 0, and no plans row carries id 0 —
so every account begins on a plan that does not exist, and so does any account
whose plan was deleted out from under it (plans has no FK from users). Such
an account read as no plan at all: every quota unset, which fails open to
unlimited (004's rule), and every capability absent, which defaults to deny. That
is not the free plan. It is more than the free plan sells on one axis and less on
the other.
Decision
A plan row says whether it is the default, and that flag is the only place the product's answer to "which plan is free" is stored.
migrations/000043addsplans.is_default BOOLEAN NOT NULL DEFAULT FALSEwith a partial unique index on the TRUE side, so at most one row can say it. The migration marks the first active plan in the admin list's own order ("order", thenplan_id) — on a stock database the seededFree— and guards on nothing being marked, so re-running never moves an operator's choice. Moving the bottom rung is oneUPDATE, no deploy: 004's rule that the numbers are the owner's, applied to an identity.PlanRepository.DefaultPlanIDis the single read of it.0means no row is marked, which is a state rather than an error.SubscriptionService.ExpireLapsedresolves that id, then hands it and the moment toUserRepository.ExpireSubscriptions. Neither spells a plan's name; the statement takes both as parameters. The clock is handed in for ADR-0113's reason — a transition that reads the wall clock cannot be tested at any moment but now — and the task moves out ofRegisterDefaultTasksintoRegisterSubscriptionTasksfor the reason 009's sweeps did: the composition root decides which clock a deployment runs on.- With no default marked, the expiry refuses (
ErrNoDefaultPlan) rather than guessing. The alternative is a guess that moves paying accounts onto a rung nobody chose. - An account is on the plan its row names, and where it names none, on the row
that says it is the default. The three create paths insert the default plan's
id, and
GetEffectivePlanSettingsresolves an id matching no row to the default plan, the account's own overrides still layered on top key by key. A deployment that marks no default is unchanged: the subselect finds nothing and the read is what it always was.
The transition is idempotent and re-runnable (009's rule): the update clears the
expiration date its own predicate selects on, so a second run moves nothing. It
keeps the original intent with plan_id IS DISTINCT FROM $2, so an account
already on the free plan is not counted as a downgrade.
Consequences
- The bottom rung runs. Proved by a row that moved against PostgreSQL 16, and
watched failing from the side a regression travels: with the literal restored,
the same test reports
invalid input syntax for type integer: "free". - Legacy
plan_id = 0rows are not rewritten. Backfilling them would silently retarget every feature flag whose audience is0(FeatureFlagService), which is a different subject. They resolve to the default plan at read time instead, and 0 stays a real audience for the rows that carry it. A new account no longer joins that audience — it is on a plan. - On a deployment whose free plan carries quota keys, accounts that read as "no plan" stop being unlimited on those axes and gain the capabilities the plan grants. That is the correction, not a side effect: it is what the plan sells.
- Nothing here decides what the free plan contains. Its numbers are the charter's Blocker 1 and stay the owner's, set through 004's admin form.
- The word
freeno longer appears in any statement. What is free is whatever row the operator marked.
Source: docs/decisions/0134-the-free-plan-is-a-row-that-says-so.md