课程: Supabase Essential Training

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Debugging triggers

Debugging triggers

- [Instructor] While triggers are helpful, there have been situations where they haven't behaved in the way that I anticipated. Let's have a closer look at how triggers can go wrong and what can be done to avoid problems. We have the gift_card_transactions table that has an ID, a timestamp, the amount in cents, a status, and now a notes field. I've added a trigger that looks at that status field as it changes and then reacts to that change. So let's take a look at that function. I'm going to the SQL Editor, and so this function is checking the new records status and if it's complete, it's going to update that table and set the notes to say, the transaction was completed where that ID equals the row's ID, and then we're returning the new record. And then here in the database, let's go to Triggers. We also have a complete_transaction_notes trigger that calls that function and it is ready to go. Now let's go to the Table Editor and go back to that gift_card_transactions table. Let's set…

内容