Advertisement
digimer

Untitled

Feb 9th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. BEGIN TRANSACTION ;
  2. ALTER TABLE history.hosts ADD COLUMN host_health numeric;
  3. ALTER TABLE hosts ADD COLUMN host_health numeric not null default 0;
  4. ALTER TABLE history.hosts ADD COLUMN host_status text;
  5. ALTER TABLE hosts ADD COLUMN host_status text not null default 'unknown';
  6. DROP FUNCTION history_hosts() CASCADE ;
  7.  
  8. CREATE FUNCTION history_hosts() RETURNS trigger
  9. AS $$
  10. DECLARE
  11. history_hosts RECORD;
  12. BEGIN
  13. SELECT INTO history_hosts * FROM hosts WHERE host_uuid = new.host_uuid;
  14. INSERT INTO history.hosts
  15. (host_uuid,
  16. host_name,
  17. host_type,
  18. host_key,
  19. host_ipmi,
  20. host_health,
  21. host_status,
  22. modified_date)
  23. VALUES
  24. (history_hosts.host_uuid,
  25. history_hosts.host_name,
  26. history_hosts.host_type,
  27. history_hosts.host_key,
  28. history_hosts.host_ipmi,
  29. history_hosts.host_health,
  30. history_hosts.host_status,
  31. history_hosts.modified_date);
  32. RETURN NULL;
  33. END;
  34. $$
  35. LANGUAGE plpgsql;
  36. ALTER FUNCTION history_hosts() OWNER TO admin;
  37.  
  38. CREATE TRIGGER trigger_hosts
  39. AFTER INSERT OR UPDATE ON hosts
  40. FOR EACH ROW EXECUTE PROCEDURE history_hosts();
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement