finds.dev

AmbitionEng/django-pgtrigger

Write Postgres triggers for your Django models

View on GitHubHomepage ↗

★ 647PythonBSD-3-Clauseupdated Dec 2025

// the take

A Django library that lets you define Postgres triggers declaratively through model Meta classes instead of writing raw SQL migrations or signal handlers. It's aimed at Django teams on Postgres who want DB-enforced guarantees — protected deletes, read-only fields, soft-deletes, FSM transitions — that can't be bypassed by application code.

Triggers are generated through makemigrations/migrate, so they're versioned and reviewed in the same migration history as everything else rather than applied out-of-band. It ships concrete, pre-built trigger classes (Protect, ReadOnly, SoftDelete, FSM, UpdateSearchVector) for recurring problems instead of being a thin DDL wrapper you have to build on top of. Conditional logic via pgtrigger.Q/F against OLD/NEW rows covers most cases without hand-written PL/pgSQL, while raw SQL is still available for the rest. Compatibility matrix is wide (Python 3.10-3.14, Django 4.2-6.0, Postgres 14-18) and the project is actively maintained, last push December 2025.

Postgres-only, so SQLite for local dev or tests is off the table unless you run Postgres everywhere. Logic enforced in triggers runs outside the ORM — application code, admin actions, and bulk operations can interact with trigger behavior in ways that aren't visible from Python, and debugging means reading Postgres logs/trigger SQL instead of a normal stack trace. Multi-database, multi-schema, and partitioning support exist but the docs carve out dedicated sections for them, which signals real edge cases once you're off a single default connection. Trigger semantics (deferred execution, dynamically ignoring triggers) are a genuine learning curve for a team that doesn't already know Postgres triggers, and a bad condition fails silently at the DB layer in a way that's easy to miss in code review.

We read the README, the directory tree and a key source file in November 2026. Nobody pays to be listed. How we judge →

search the same ground:

// at a glance

Stars
647
Forks
48
Language
Python
License
BSD-3-Clause
Last commit
4 Dec 2025

// nearby

If django-pgtrigger isn't quite it.

All repos →