Sitemap

Schemalint Support for Triggers

2 min readMay 24, 2025

--

Schemalint is a tool that inspects a PostgreSQL database and prints out errors if the schema diverges from a defined set of rules.

I am big fan of linter rules in general. They offer a nice way of establishing rules for your code base. This is handy both for aligning with team mates as well as your future self. With Schemalint, you can apply this to the database schema which is often a fundamental part of a software systems architecture.

The newest version adds support for triggers. I have been wanting this for a long time, because triggers are one of the more subtle parts of a schema and therefor arguable one of the more important aspects for a tool like this. A trigger (or the lack thereof) is not very visible in most database inspection tools, so it’s easy to miss when something is wrong.

Photo by Tsvetoslav Hristov on Unsplash

For instance, I greatly prefer having a dedicated table and a trigger for soft deletes over having an archived_at column, as outlined in this blog post. I like this because the archived_at approach requires an extra is null condition in every single query you make to this table. And what’s worse: forgetting to do so often doesn’t look like a bug when developing. However, the dedicated table approach requires that you have the trigger in place and forgetting to set that is also easy to miss (though only needs to happen once per table). But now, Schemalint can catch those for you!

There is a custom example rule for enforcing setting a last_update column in the examples folder. There is a triggers field on tables and views in the input to the rules (see the details here).

--

--

No responses yet