Created
April 11, 2021 05:38
-
-
Save libovness/cf006846fda90bb160be427f2fdd06ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deletes the image object in storage when the corresponding record is deleted | |
CREATE OR REPLACE FUNCTION delete_corresponding_image() RETURNS trigger AS | |
$$BEGIN | |
DELETE | |
FROM storage.objects o | |
LEFT JOIN public.images ON i.id = o.image_id | |
RETURN NULL; | |
END;$$ LANGUAGE plpgsql; | |
CREATE TRIGGER delete_image_object_when_corresponding_record_is_deleted | |
BEFORE DELETE ON public.images FOR EACH ROW | |
EXECUTE PROCEDURE delete_corresponding_image(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment