Skip to main content

14. Triggers

Triggers run automatically when changes occur. They are useful for enforcing rules close to the data, but they can also make behavior harder to reason about if overused.

Decision Guide

NeedPreferNotes
Audit changesAFTER triggerWrite to an audit table
Validate data beyond constraintsBEFORE triggerPrefer constraints when possible
Maintain derived columns (e.g., updated_at)BEFORE UPDATE triggerKeep it small and deterministic

Lessons

What's Next