MFS401 : Table of Contents

Chapter 3

Lesson 6

Triggers and Webhooks: Action-packed Database Management

Foundational

Overview of triggers and webhooks

Building triggers using Supabase's GUI

Adding basic webhooks through Supabase

Best practices for optimal triggers and webhooks

Advanced

Complex triggers and webhooks using plpgsql

Clean deletions using cascading deletion triggers

Safeguarded data through modification prevention triggers

Robust data practices through integrity constraints

Quiz it to win it

Take the quiz

3 Questions
12 XP

In the previous lessons, we learned how to build, interact with, and secure databases with Supabase. Database operations can be regarded as events that allow the consumer to query or mutate data. The mutation events include inserting, updating, or deleting data based on various conditions.

In this event-driven paradigm, it is also essential to be “aware” of these events and be able to take auxiliary actions around them. In other words, when an event happens, it is powerful to take action before or after the event. This is where database triggers come in. This lesson discusses how to build, manage, and run Postgres triggers with Supabase triggers and webhooks.

Postgres triggers


Postgres triggers are a specific procedural code that runs automatically before or after a database event.

Maintain data integrity is one of the most common use cases of Postgres triggers. As we learned in previous lessons, we can already provide some database constraints directly with a query (e.g., with check, unique, or foreign key). However, in most use cases, we need to maintain more complex relationships and data integrity. Some examples include:

  • Keeping a 'summary' column up-to-date, such as a count of related records. For example, count of reactions on a post,
  • Get started for free today!

    No commitments. No contracts. Enjoy all features for a day — join in just three clicks!

    No credit card required.

    Quiz it to win it

    Complete this quiz successfully to proceed to the next lesson and win upto 12XP.

    Start quiz for this lesson

    Completing this quiz will get you

    +12 Experience Points

    +5% course progress