Domdhi logoDOMDHI.OS
TECH

The Migration That Typechecked and Still Broke Production

Typecheck green. Tests green. Lint green. The live query broke on the first request, because every check I ran was verifying my code against my mocks, and the thing that changed was the database.

DDominic BacaLEAD ENGINEER · DOMDHI.OS2026.12.035 MIN READ
TECH// FIG.01

Drop a column. Run npm run typecheck — green. Run the test suite — green. Lint — green. Ship it.

Live query breaks on the first request.

Everything I ran verified my code against my own assumptions. The thing that changed was the database, and none of my checks were looking at the database.

Why The Green Checks Are Green

Three separate reasons, and understanding each one is what fixes this.

Typecheck doesn't know about your database. The generated types are a snapshot, produced by supabase gen types at some point in the past. Drop a column in a migration and those types keep describing the old schema until you regenerate them. The compiler is happily verifying your code against a description of a database that no longer exists.

Worse: if you do regenerate, typecheck only catches consumers that go through the typed client with a statically-known column reference. A .select("*") followed by reading row.some_column may still typecheck if the type is stale, and string-built filters are invisible to the compiler entirely.

Mocked tests assert your mock's shape. A test that mocks the Supabase client and returns { data: [{ id, name, old_column }] } will pass forever, regardless of what the real table contains. It's testing that your code can process a shape you invented. When the real shape diverges, the test has no opinion — it never touched the real schema.

This is the one that gives false confidence, because a passing test feels like verification of behavior. It's verification of behavior against a fixture.

Lint doesn't model data at all. Never did. Not its job.

So the full green board means: "the code is internally consistent with a snapshot of a schema and a set of fixtures I wrote." It does not mean "this will work."

The Grep That Isn't Enough

Obvious next move: grep for the column name before dropping it.

grep -rn "old_column" src/

Zero hits. Ship it. Still breaks.

Because the column is snake_case in the database and the code reads it off a typed object in camelCase:

const config = mapRow(row);
if (config.filingStatus) { ... }   // grep for filing_status: no hits

The mapper translated it at the boundary and every consumer downstream uses the JS name. A grep for the database spelling finds the mapper and nothing else.

Grep both spellings. Always. And even then, grep misses dynamic access, string-built selects, and anything assembled at runtime.

What Actually Works

The reliable sequence, in order:

1. Remove the field from the schema first, then let typecheck enumerate the consumers.

This is the trick that turns a search problem into a compiler problem. Delete the field from the Zod schema or the type definition before touching the database. Now tsc walks the entire codebase and hands you a complete list of every place that reads it — including the camelCase consumers grep missed, including ones in files you'd never have thought to check.

The type system is a far better search engine than grep, because it understands the reference graph rather than matching text. Use it as the audit.

2. Regenerate types after the migration, before believing anything.

supabase gen types typescript > src/app/types/supabase.ts

Until you do this, every green typecheck is measured against the old schema.

3. Dry-run the migration against the real schema without persisting it.

Postgres DDL is transactional, which is genuinely useful here:

BEGIN;
\i supabase/migrations/20260918_drop_old_column.sql
-- verification queries: does the app's real query still run?
SELECT id, name FROM the_table LIMIT 1;
ROLLBACK;

That proves the SQL executes against production's actual schema — not the one your migration history implies it has — and leaves zero changes behind. For anything destructive this is the highest-value five minutes available.

It matters because migration files are not ground truth. Migrations get edited, a change gets made in a dashboard, a branch gets applied out of order. The live schema is the only authority.

4. Rewrite the mocked tests to the new shape, deliberately.

A mocked test that still passes after a schema change is telling you nothing. Update the fixtures to the real new shape — otherwise you're carrying a test that will stay green through the next break too.

Better where practical: assert on the actual query being constructed — the select string, the filter columns — so the test pins the column names rather than a synthetic response.

The Pattern Underneath

Every check I trusted was checking code against code. The change was at a boundary where code meets something external.

That's the general shape, and it recurs everywhere:

  • RLS policies that outlive their trust model — the code didn't change, the meaning of authenticated did, and nothing in the toolchain models that.
  • A worker var typed as a literal, so env.FLAG === "true" fails to compile for reasons no local test surfaces.
  • A cron job whose query silently errors every run because a joined column was removed — caught only by reading production logs.

Your toolchain verifies the parts of the system it can see. Anything on the far side of an external boundary — a database, a runtime config, a third-party API — is outside the verification perimeter, and confidence from inside the perimeter doesn't extend across it.

The Checklist I Use Now

Before any destructive migration:

  • Remove the field from the schema/type first; let tsc enumerate every consumer
  • Grep both snake_case and camelCase spellings
  • Check for string-built selects and dynamic access the compiler can't see
  • BEGIN; \i migration; <verify>; ROLLBACK; against the real remote schema
  • Regenerate types, then typecheck again
  • Rewrite affected mocked tests to the new shape
  • After deploy, actually read the logs — a cron that fails silently will not page you

That last one is how I found a distribution job that had been erroring every fifteen minutes on a column that didn't exist. Caught in a log tail, months after it started, because nothing else was looking.

Green checks are necessary. They were never sufficient, and the gap is exactly the size of everything your tests had to pretend about.

GET_TRANSMISSIONS

Raw signal on finance, freedom, fitness, and tech. No spam. Unsubscribe anytime.

D
Dominic Baca

Lead software engineer. I plan the work, direct AI agents to build it, and verify every result. This site is where I build in public, from money to the occasional 2am migration. About me →

FOLLOW THE LOGS →
// NEXT IN THE LOGS