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
---
dude if you knew how much the community racked their brains over this authoring feature...
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
Please keep this going!! We need this beautiful level of documentation.
note that this is 2 years ago. now you must create a trigger with SQL editor if you listen to auth
Thanks for the overview. I pressed the like button twice to send you a very kind message!
0:47
it's exactly what I'm looking for, thank you!
This is incredibly useful
8:05
Great video due! Thx :)
Thanks, it was helpful
@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?
Please make more videos like these on triggers and plpgsql! 🙏🏼🙏🏼🙏🏼
Thank you, it works)
He please upddate this video there is no auth autho option anymore in trigger
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?
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.
How to do scheduled publish in Supabase ?
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!
How would the automatic creation of records in a monthly table be, so that every month records were automatically generated in a table?