| | 215 | CREATE OR REPLACE FUNCTION stratcon.update_config( |
|---|
| | 216 | v_remote_address_in inet, |
|---|
| | 217 | v_node_type_in text, |
|---|
| | 218 | v_whence_in timestamptz, |
|---|
| | 219 | v_config_in xml) RETURNS void |
|---|
| | 220 | AS $$ |
|---|
| | 221 | DECLARE |
|---|
| | 222 | v_config xml; |
|---|
| | 223 | BEGIN |
|---|
| | 224 | select config into v_config from stratcon.current_node_config |
|---|
| | 225 | where remote_address = v_remote_address_in |
|---|
| | 226 | and node_type = v_node_type_in; |
|---|
| | 227 | IF FOUND THEN |
|---|
| | 228 | IF v_config::text = v_config_in::text THEN |
|---|
| | 229 | RETURN; |
|---|
| | 230 | END IF; |
|---|
| | 231 | delete from stratcon.current_node_config |
|---|
| | 232 | where _address = v_remote_address_in |
|---|
| | 233 | and node_type = v_node_type_in; |
|---|
| | 234 | END IF; |
|---|
| | 235 | insert into stratcon.current_node_config |
|---|
| | 236 | (remote_address, node_type, whence, config) |
|---|
| | 237 | values (v_remote_address_in, v_node_type_in, v_whence_in, v_config_in); |
|---|
| | 238 | insert into stratcon.current_node_config_changelog |
|---|
| | 239 | (remote_address, node_type, whence, config) |
|---|
| | 240 | values (v_remote_address_in, v_node_type_in, v_whence_in, v_config_in); |
|---|
| | 241 | END |
|---|
| | 242 | $$ LANGUAGE plpgsql; |
|---|
| | 243 | |
|---|
| 250 | | |
|---|
| 251 | | |
|---|
| 252 | | -- Trigger Function to log node config change |
|---|
| 253 | | |
|---|
| 254 | | CREATE 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 | | |
|---|
| 260 | | CREATE OR REPLACE FUNCTION stratcon.current_node_config_changelog() RETURNS trigger |
|---|
| 261 | | AS $$ |
|---|
| 262 | | DECLARE |
|---|
| 263 | | v_config xml; |
|---|
| 264 | | |
|---|
| 265 | | BEGIN |
|---|
| 266 | | |
|---|
| 267 | | IF 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 | | |
|---|
| 280 | | ELSE |
|---|
| 281 | | RAISE EXCEPTION 'Something wrong with stratcon.current_node_config_changelog'; |
|---|
| 282 | | END IF; |
|---|
| 283 | | |
|---|
| 284 | | RETURN NULL; |
|---|
| 285 | | |
|---|
| 286 | | END |
|---|
| 287 | | $$ |
|---|
| 288 | | LANGUAGE plpgsql; |
|---|