Tech News
← Back to articles

You Should Add Debug Views to Your DB

read original related products more articles

This one will be quick.

Imagine this, you get a report from your bug tracker:

Sophie got an error when viewing the diff after her most recent push to her contribution to the @unison/cloud project on Unison Share

(BTW, contributions are like pull requests, but for Unison code)

Okay, this is great, we have something to start with, let's go look up that contribution and see if any of the data there is suspicious.

Uhhh, okay, I know the error is related to one of Sophie's contributions, but how do I actually find it?

I know Sophie's username from the bug report, that helps, but I don't know which project she was working on, or what the contribution ID is, which branches are involved, etc. Okay no problem, our data is relational, so I can dive in and figure it out with a query:

> SELECT * contribution. FROM contributions AS contribution contributionscontribution JOIN projects AS project projectsproject ON contribution.project_id = project. id contribution.project_idproject. JOIN users AS unison_user usersunison_user ON project.owner = unison_user. id project.ownerunison_user. JOIN users AS contribution_author userscontribution_author ON contribution.author_id = contribution_author. id contribution.author_idcontribution_author. JOIN branches AS source_branch branchessource_branch ON contribution.source_branch = source_branch. id contribution.source_branchsource_branch. WHERE contribution_author.username = 'sophie' contribution_author.username AND project.name = 'cloud' project.name AND unison_user.username = 'unison' unison_user.username ORDER BY source_branch.updated_at DESC source_branch.updated_at - [ RECORD 1 ] --------+---------------------------------------------------- id | C - 4567 | C - 9999 project_id | P 21 contribution_number | title | Fix bug the app from deleting the User 's hard drive description | PreventappdeletingUser status | open source_branch | B-1111 target_branch | B-2222 created_at | 2025-05-28 13:06:09.532103+00 updated_at | 2025-05-28 13:54:23.954913+00 author_id | U-1234

It's not the worst query I've ever had to write out, but if you're doing this a couple times a day on a couple different tables, writing out the joins gets pretty old real fast. Especially so if you're writing it in a CLI interface where's it's a royal pain to edit the middle of a query.

Even after we get the data we get a very ID heavy view of what's going on, what's the actual project name? What are the branch names? Etc.

... continue reading