How to setup a database trigger upon thing deletion?

It looks like the database trigger works on change within a data type, but not if a thing gets deleted?

Trigger when thing is deleted
Create a trigger → Only When → [thing] before is not empty and [thing] now is empty

Trigger when thing is created
Create a trigger → Only When → [thing] before is empty and [thing] now is not empty

I hope this helps!

7 Likes

Just realize you can’t actually reference the thing before anymore to do deletion chaining of others things in the subsequent workflow right? I assume that’s because it has already been deleted?

3 Likes

@redvivi this sounds like a case where you might need two additional states on the Thing in question: One that makes it “Marked for death” (do all of the pre-deletion things) and second in which it’s “Ready to die” (now just delete it).

3 Likes

Agreed. @keith

@redvivi
Setup

  1. Add a field to your thing called “deleted” and make it type yes/no
  2. Default to no
  3. Create a trigger → Only When → [thing] before’s deleted = no and [thing] now’s deleted = yes
  4. Add all the steps you want to complete under that trigger.
  5. Make one of the last steps of the above trigger “delete thing”

When you want to delete that thing

  1. Change things “deleted” field to “yes”
    This will cause the trigger to fire
4 Likes

quick q: since you mentioned “deletion chaining” are the “things” you are referring to related with the data that you’re trying to delete?

Yep, @Dillon_Schade, though I think my labels are more fun. :stuck_out_tongue_winking_eye:

2 Likes

:joy: I’m inspired and ill start adding “markedForDeath” on future things

1 Like

Thanks a lot for all your help.

I managed to sort it out.

I also trashed my computer science database design courses related to referential integrity.

Make of it what you will.

1 Like

It’s a shame bubble doesn’t have a trigger method that would run before the CRUD operation, like a “before delete” trigger so that we could do the process you just mentioned without the extra field and pre-delete update to the thing ; also this would allow the delete function from the bubble editor to un the trigger properly.

2 Likes

Vote for this feature here

1 Like