Skip to content

The Caption Said 9 Tables, the Matrix Said 7

Adityo Guni Waluyo

A diagram caption claimed 9 tables, the appendix matrix said 7. A recount against the live schema found a table that had silently left the cluster list.

TL;DR

A mismatched table count in a report turned out to hide a missing table, not a typo. Querying the live schema and generating diagrams, captions, and the PDF automatically fixed the drift. The rule going forward: every published count must be reproducible by a query at render time.

While QA-reading the data-architecture report for KotaPortal, one line stopped the review cold: a diagram caption claimed "cluster C: 9 tables", and the appendix matrix for that same cluster listed 7. Both numbers sat inside one 8-page A4 PDF, generated minutes earlier from the same session as the diagrams themselves.

One of them had to be wrong. My first guess was a typo. Someone, possibly me, had typed one of the two numbers by hand and slipped. I never established which side drifted first. The journal records the catch and the fix, not the origin. The guess itself was the real error: it treated the disagreement as a writing slip where patching one line would close the issue.

A recount against the live schema

The right move was to stop trusting either number and ask the database. MariaDB's documentation on information_schema.tables states the principle plainly: those system tables "provides metadata about all tables in the databases, including their names, types, storage engines, and other crucial properties" [4]. The database itself reports what exists.

SELECT table_name, engine
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY table_name;

The query returned 35 rows in total: 34 domain tables plus schema_migrations, the one system table every migration-managed schema carries. Grouped by cluster, the 34 domain tables break down as A11, B9, C7, D2, and E5.

The cluster enumeration inside the document accounted for 33 of them. One row never made it into any cluster: reports, the ticketed complaint channel. It existed in the live schema, it was covered by the migration folder, and it was simply absent from the list I had been trusting.

The 9-versus-7 disagreement was the symptom. Hand-copied numbers were the disease. Nothing had errored when reports dropped out, which is exactly why the mismatch was worth treating as a bug report rather than a typo hunt.

Numbers that come with their source

Three habits now keep this class of drift out of the document.

First, every count is read from the schema and the migration folder in one session, never retyped. The migration folder is the schema's history: 118 migration files in this project. golang-migrate's README describes the behavior worth wanting from such tooling: "Database drivers don't assume things or try to correct user input. When in doubt, fail." [7] A migration that cannot be applied cleanly fails instead of quietly reshaping the schema, so the folder and the live database stay reconcilable. The 26 foreign-key relations in the report come from the same read.

ls migrations/*.sql | wc -l
# 118

Second, the diagrams are generated, not drawn. drawsvg describes itself as "A Python 3 library for programmatically generating SVG images and animations" [5], and every table, column, and edge in the four ERD and cluster diagrams is emitted from the introspection result. Captions such as "cluster C: 7 tables" are computed values. Regenerate, and the caption is recounted for free.

Third, the document renders to PDF as a build step, not as a manual export. A print script drives a headless browser; this is the same step Puppeteer documents for Page.pdf(), which "Generates a PDF of the page with the print CSS media type" [6]. The regenerated document is then checked, not eyeballed:

pdfinfo dist/report-4.pdf | grep -E 'Pages|Page size'
# Pages:          8
# Page size:      595 x 842 pts (A4)

After regeneration the checks came back clean: 8 A4 pages, diagram labels reaching the PDF as selectable vector text, and an ink-bounds scan at 150 dpi reporting 0 violations.

The same rule reached the CMS manual interface afterwards. The index chip and footer pill used to display hardcoded counts; they now compute from the source lists and render values such as "29 groups · 3 documents". A count shown to a reader is either derived at render time or it will eventually lie.

Treating a mismatch as evidence

The working rule is short: a number in a design document that nobody can reproduce with a query is a decoration. Numbers that arrive with their query are evidence.

Practically, that gives three checks anyone can apply to their own architecture documents. If a stated count cannot be regenerated by a query in the same session, mark it as unverified. If two sections disagree on a count, recount against the live schema before assuming a typo, because a disagreement usually points at a missing or duplicated item, not a mis-typed digit. And if a number is hand-copied anywhere in the pipeline, move the copy into the generator so the next mismatch is impossible rather than merely unlikely.

The fix here cost less than the diagnosis. One table had silently left the cluster list, and one recount found it.

---

Sources

  • [4] MariaDB Knowledge Base, Information Schema Tables mariadb.com
  • [5] cduck/drawsvg, Python SVG library github.com
  • [6] Puppeteer API, Page.pdf() pptr.dev
  • [7] golang-migrate/migrate, database migration tooling github.com

Related articles