Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1.  
  2.  
  3. create or replace function notify_manager_of_new_student_connection() returns trigger as $$
  4. declare
  5. v_notification_source_id uuid;
  6. v_activity_types_id uuid;
  7. v_notification_id uuid;
  8. begin
  9.  
  10. select id into v_activity_types_id
  11. from activity_types
  12. where activity_types.type = 'new_student_connection';
  13.  
  14. insert into notification_sources(student_id)
  15. values (NEW.student_id)
  16. returning id into v_notification_source_id;
  17.  
  18. insert into notifications(notification_source_id, activity_type_id)
  19. values (v_notification_source_id, v_activity_types_id)
  20. returning id into v_notification_id;
  21.  
  22. insert into manager_notifications(notification_id, manager_id)
  23. values (v_notification_id, NEW.manager_id);
  24. return NEW;
  25. end;
  26. && language plpgsql volatile set search_path from current security definer;
  27.  
  28. create trigger trigger_manager_of_new_student_connection
  29. after insert on manager_contacts
  30. for each row execute procedure notify_manager_of_new_student_connection();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement