Using PostgreSQL triggers to automate processes with Supabase

Поделиться
HTML-код
  • Опубликовано: 27 дек 2021
  • For the introductory video on PostgreSQL functions, check out 👉 • Create PostgreSQL Func...
    Functions in Postgres allow us to encapsulate some logic in our database, but we don't want to have to call these functions manually, whenever data in our database changes. In order to automate this, we can use Postgres Triggers.
    Triggers in PostgreSQL allow us to subscribe to particular events that occur in the database - insert, update or delete - and call a Postgres function whenever they occur. This allows us to automate some of those manual processes - such as creating a row in our profiles table for each user who signs in.
    In this video, Jon Meyers ( / jonmeyers_io ) explains how we can model our database schema by creating a profiles table to hold additional data about our user. We can then create a trigger that listens for insert events on the auth.users table and automatically creates a profile for them.
    This is part of a series of videos about functions in PostgreSQL, check out the rest of the playlist to learn more: • PostgreSQL Functions
    👮‍♀️ Learn about Row Level Security: • Implement Authorizatio...
    💰 Get really good at Supabase and build a SaaS product (free course): egghead.io/courses/build-a-sa...
    ---
    Learn more about Supabase 👇
    🕸 Website: supabase.com/
    🏁 Get started: app.supabase.com/
    📄 Docs: supabase.com/docs
    🐙 Github: github.com/supabase
    💬 Discord: discord.supabase.com/
    🐦 Twitter: / supabase
    Jon Meyers 👇
    🕸 Website: jonmeyers.io/
    🎥 RUclips Channel: / jonmeyers
    🐦 Twitter: / jonmeyers_io
    ---

Комментарии • 68

  • @selique
    @selique 2 года назад +15

    dude if you knew how much the community racked their brains over this authoring feature...

  • @yoapps137
    @yoapps137 Год назад +6

    I appreciate the way you are also describing, the options on the path you arent taking... it helps because when a developer really sits down to make his scratch they come across the same options and wonder "...but what might this do?"... and you have already prepped us for that. thanks

  • @hu3m4n90
    @hu3m4n90 2 года назад +18

    Please keep this going!! We need this beautiful level of documentation.

  • @deoarlo

    note that this is 2 years ago. now you must create a trigger with SQL editor if you listen to auth

  • @evanrosz
    @evanrosz Год назад

    Thanks for the overview. I pressed the like button twice to send you a very kind message!

  • @__joellee__
    @__joellee__ 2 года назад +9

    0:47

  • @tattran2263
    @tattran2263 2 года назад +3

    it's exactly what I'm looking for, thank you!

  • @albertodeagostini6143
    @albertodeagostini6143 2 года назад

    This is incredibly useful

  • @anthonyngooo

    8:05

  • @alfonguti1

    Great video due! Thx :)

  • @hermeschi
    @hermeschi Год назад

    Thanks, it was helpful

  • @MishaMoroshko
    @MishaMoroshko Год назад

    @JonMeyers @Supabase I'd like to create a profile row only after the user confirms their email. Do I understand correctly that the UPDATE event will call the trigger function on any update, and there is no way to trigger the function on update of a specific column? Ideally, I'd like to trigger the function when `email_confirmed_at` is changing from NULL to a non-NULL value in `auth.users`. Is this possible to achieve this?

  • @ofeenee
    @ofeenee Год назад +2

    Please make more videos like these on triggers and plpgsql! 🙏🏼🙏🏼🙏🏼

  • @shohzodzet
    @shohzodzet Год назад

    Thank you, it works)

  • @loribryant4999

    He please upddate this video there is no auth autho option anymore in trigger

  • @yellowsubmarine12321
    @yellowsubmarine12321 2 года назад +3

    Every time I try this I get a "Database error saving new user" 500 error response. I've rewatched many times now and I'm doing exactly what you are. Any ideas?

  • @Broski_Rodragweez

    I almost scoffed at the idea of using Supabase because for one I don't care much for SQL (got burned out on it a few years ago), for two I don't care for putting business logic in my database. BUT, since it appears that I can build apps without all the API layer boilerplate I am starting to come around. Plus having the AI available to help write sql makes it less painful.

  • @Troy-ol5fk
    @Troy-ol5fk 2 года назад +1

    How to do scheduled publish in Supabase ?

  • @PinasPiliNa999

    is it a good practice for a production application for Inventory management to use Triggers? Hope you can make a video to demonstrate inventory management using Triggers. Thanks!

  • @leandroosterne
    @leandroosterne Год назад

    How would the automatic creation of records in a monthly table be, so that every month records were automatically generated in a table?