5,000 tables gone, and nobody noticed
After a multi-year migration our platform had over 10,000 models in code, even more objects deployed, and a shared suspicion that a lot of it was dead. The hunt produced one finding that reframed the whole cleanup: the lineage graph is blind to most of what actually sits in a warehouse. Most of our dead weight was never in the code at all. This is how we found it, and the proof that made deleting it safe. Names are generic; the methods and numbers are real. The opposite case, models the code keeps updating for nobody, has its own post.
Nobody deletes anything, and that's rational
Deleting in a large warehouse is asymmetric: a dead table costs a little every day, but dropping a live one breaks somebody's Monday. Without evidence, keeping everything is the rational move, and that's how a platform ends up with thousands of objects nobody can vouch for.
The instinct is to hunt for dead models inside the transformation code
(that hunt is the companion post). The bigger finding was elsewhere:
most of the dead weight was not in the code at all. Migration
leftovers, hand-made backups (_bkp,
_old, tmp), experiments,
deployments of models long since deleted: objects the codebase never mentions,
which no code analysis can find because the code doesn't know they exist.
The method: diff, then grep
1 · Diff the warehouse against the code graph
Pull the full list of deployed objects from the warehouse catalog, reduce both sides to comparable keys (schema + object name), and subtract everything the code declares. What remains is the target list: objects nothing in the codebase even attempts to reference, invisible to every code-level analysis by definition. Every candidate carries its catalog metadata (row count, size, days since last altered), ready for the decision stage below.
Everything the code declares (left) is subtracted from what the warehouse holds (right). Matched objects pair up; whatever has no partner on the left is the target list.
2 · Before deleting: grep everything
The diff says "probably dead". We wanted provably unreferenced. So the last gate is deliberately dumb: take every candidate's name and search the entire repo for any mention at all, in any file: SQL, YAML, macros, docs, scripts, tests. The split decides the fate:
- Zero mentions anywhere: provably unreferenced. That was ~5,000 tables, and they were retired.
- One or more mentions: 2,000 objects that something, somewhere still names. Each needs a human to judge whether the mention is real usage or a stale comment, so they went to a review queue instead of the drop list.
Package it for the person who decides
The analyses produce candidates; people approve drops. So everything lands in one Excel workbook, one row per object with its schema and name spelled out, and the columns a decision actually needs: last altered date on Snowflake, row count, size, days since last change, and where any lingering mentions live. With that in front of a decision maker, the call stops being a debate: sort by last altered, start with objects untouched for nine months or more, and every "are we sure?" has a column that answers it. Clear metadata, clearly explained, is what turns a drop decision from an argument into a filter.
Deliberately not a pipeline
None of this is wired into CI. The scripts are read-only, run one at a time, and their outputs are reviewed by hand before anything is dropped. That's not a missing feature: deletion is the one operation where the process should be slow, boring, and reversible. The tooling's job is to make the candidate list trustworthy and the review easy, not to act. Order of operations for anyone repeating this: the warehouse diff first, and nothing gets dropped without passing the grep gate.
Even retirement itself is soft. Nothing goes straight to DROP:
a retired table or view is renamed with a to_be_deleted
marker, so any query that still touches it fails loudly while the data stays fully
intact and restorable in seconds. Only after a few quiet months do the renamed
objects get dropped for real. The rename is the one test no analysis can run:
production traffic itself proving that nothing needed the table.
What I learned
- The biggest dead weight wasn't in the code at all. Objects the codebase never mentions can only be found by diffing the catalog against the graph; no amount of code analysis will surface them.
- A dumb grep beats a clever analysis for confidence. Searching the whole repo for every candidate name is crude, and it is exactly what turned "probably dead" into 5,000 provably-unreferenced tables and 2,000 for a human.
- Metadata makes the decision objective. One workbook with last altered, row count, and size per object turns "dare we drop this?" into "filter for untouched for 9+ months and work down the list."
- Keep deletion human, and soft. Read-only scripts, manual
review, and a
to_be_deletedrename that waits out a few months of production traffic before the real drop: for destructive cleanup, slow is the design.
The dbt + Snowflake implementation
How the checks map onto our actual stack, folded away so the story stays short.
The code side: dbt's manifest
The code side of the diff reads target/manifest.json, dbt's compiled project graph:
nodes[uid]['schema']/['alias']: the(schema, alias)key each model is compared on.nodes[uid]['original_file_path']/['config']:inactive/folder detection and the enabled flag, so disabled models still count as declared.
The warehouse diff against Snowflake
One extract of INFORMATION_SCHEMA.TABLES covers the
in-scope schemas (log and metadata schemas excluded), bringing every table and
view name along with row_count,
bytes, created, and
last_altered. Both sides reduce to
(SCHEMA, ALIAS) keys, and everything the code declares
is subtracted from what the warehouse holds. The remaining orphans keep their
catalog metadata plus a days-since-altered column and land in one workbook,
numerics coerced for sorting.
The grep gate
Every candidate name is searched across the entire GitHub repository: any file type, any match, case-insensitive. The tally per name (zero vs one-or-more mentions) produces the final split: the zero-mention list is eligible for retirement, the rest goes to the review queue with the mention locations attached. Crude on purpose: the point of this gate is that it cannot be outsmarted by an edge the graph model didn't capture.