triggers.py 756 B

12345678910111213141516171819202122232425
  1. # No longer used
  2. UPDATE_ISSUE_TRIGGER = """
  3. DROP TRIGGER IF EXISTS event_issue_update on events_event;
  4. """
  5. INCREMENT_PROJECT_COUNTER_TRIGGER = """
  6. DROP TRIGGER IF EXISTS increment_project_counter on issues_issue;
  7. CREATE OR REPLACE FUNCTION increment_project_counter() RETURNS trigger AS $$
  8. DECLARE
  9. counter_value int;
  10. BEGIN
  11. INSERT INTO projects_projectcounter (value, project_id)
  12. VALUES (0, NEW.project_id)
  13. ON CONFLICT (project_id) DO UPDATE SET value = projects_projectcounter.value + 1
  14. RETURNING value into counter_value;
  15. NEW.short_id=counter_value;
  16. RETURN NEW;
  17. END;
  18. $$ LANGUAGE plpgsql;;
  19. CREATE TRIGGER increment_project_counter BEFORE INSERT
  20. ON issues_issue FOR EACH ROW EXECUTE PROCEDURE
  21. increment_project_counter();
  22. """