Changeset 7710784460d9831062155d3e99f3bf22e4d978b0

Show
Ignore:
Timestamp:
06/30/08 19:32:15 (6 years ago)
Author:
Denish Patel <denish@omniti.com>
git-committer:
Denish Patel <denish@omniti.com> 1214854335 +0000
git-parent:

[8d0941e9be7bff1c68d8452295990fdc72a0fe53]

git-author:
Denish Patel <denish@omniti.com> 1214854335 +0000
Message:

added node configuration tables and trigger.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sql/schema.sql

    r6b9f38f r7710784  
    135135  PRIMARY KEY (sid,metric_name,metric_type) 
    136136); 
     137 
     138CREATE TABLE stratcon.current_node_config ( 
     139  remote_address inet not null,  
     140  node_type text not null,  
     141  whence timestamptz not null,  
     142  config xml not null, 
     143  PRIMARY KEY (remote_address,node_type) 
     144); 
     145 
     146CREATE TABLE stratcon.current_node_config_changelog ( 
     147  remote_address inet not null,  
     148  node_type text not null,  
     149  whence timestamptz not null,  
     150  config xml not null, 
     151  PRIMARY KEY (remote_address,node_type) 
     152); 
     153 
    137154-- Schema Sequence  
    138155 
     
    231248$$ 
    232249    LANGUAGE plpgsql; 
     250 
     251 
     252-- Trigger Function to log node config change 
     253 
     254CREATE   TRIGGER current_node_config_changelog 
     255    AFTER INSERT ON stratcon.current_node_config 
     256    FOR EACH ROW 
     257    EXECUTE PROCEDURE stratcon.current_node_config_changelog(); 
     258 
     259 
     260CREATE OR REPLACE FUNCTION stratcon.current_node_config_changelog() RETURNS trigger 
     261    AS $$ 
     262DECLARE 
     263    v_config xml; 
     264     
     265BEGIN 
     266 
     267IF TG_OP = 'INSERT' THEN 
     268    SELECT config FROM  stratcon.current_node_config WHERE remote_address = NEW.remote_address AND node_type= NEW.node_type 
     269        AND whence = (SELECT max(whence) FROM stratcon.current_node_config_changelog 
     270                        WHERE  remote_address = NEW.remote_address AND node_type= NEW.node_type and  whence <> NEW.whence ) 
     271    INTO v_config; 
     272 
     273    IF v_config IS DISTINCT FROM NEW.config THEN 
     274 
     275        INSERT INTO stratcon.current_node_config_changelog (remote_address,node_type,whence,config) 
     276            VALUES (NEW.remote_address,NEW.node_type,NEW.whence,NEW.config);  
     277 
     278    END IF; 
     279 
     280ELSE 
     281        RAISE EXCEPTION 'Something wrong with stratcon.current_node_config_changelog'; 
     282END IF; 
     283 
     284    RETURN NULL; 
     285 
     286END 
     287$$ 
     288    LANGUAGE plpgsql;   
    233289 
    234290