triggers.py 794 B

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