From f6089beea630699efd10e5b6aec4cbc0ff33a6e1 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Wed, 10 Jun 2026 22:40:53 +0000 Subject: [PATCH] Change names: FOLLOWS -> WATCHES, FOLLOWS.FID -> WATCHES.WID --- conversion/Makefile | 8 +- conversion/load_aggressions.m4 | 16 +- conversion/load_finish.sql | 11 +- conversion/load_follow_arrival.m4 | 19 +- conversion/load_follow_to_other.sql | 23 +- ...follows.sql => load_follow_to_watches.sql} | 57 ++- db/schemas/lib/triggers/Makefile | 2 +- db/schemas/lib/triggers/create/aggressions.m4 | 22 +- db/schemas/lib/triggers/create/arrivals.m4 | 182 ++++----- db/schemas/lib/triggers/create/arrivals_a.m4 | 24 +- .../lib/triggers/create/biography_data.m4 | 196 +++++----- db/schemas/lib/triggers/create/events.m4 | 36 +- .../lib/triggers/create/follow_observers.m4 | 42 +-- db/schemas/lib/triggers/create/food_events.m4 | 66 ++-- .../lib/triggers/create/groom_scans_b.m4 | 22 +- db/schemas/lib/triggers/create/groomings.m4 | 44 +-- db/schemas/lib/triggers/create/humans.m4 | 36 +- db/schemas/lib/triggers/create/locations_b.m4 | 48 +-- db/schemas/lib/triggers/create/pantgrunts.m4 | 22 +- db/schemas/lib/triggers/create/roles.m4 | 346 +++++++++--------- .../lib/triggers/create/species_present.m4 | 36 +- .../create/{follows.m4 => watches.m4} | 124 +++---- .../triggers/drop/{follows.m4 => watches.m4} | 8 +- .../functions/create/build_arrivals_seq.m4 | 18 +- db/schemas/sokwedb/indexes/Makefile | 4 +- db/schemas/sokwedb/indexes/create/events.m4 | 14 +- .../indexes/create/follow_observers.m4 | 6 +- .../sokwedb/indexes/create/follow_studies.m4 | 6 +- .../sokwedb/indexes/create/locations_b.m4 | 12 +- .../indexes/create/{follows.m4 => watches.m4} | 8 +- db/schemas/sokwedb/indexes/drop/events.m4 | 4 +- .../sokwedb/indexes/drop/follow_observers.m4 | 4 +- .../sokwedb/indexes/drop/follow_studies.m4 | 4 +- .../sokwedb/indexes/drop/locations_b.m4 | 4 +- .../indexes/drop/{follows.m4 => watches.m4} | 6 +- db/schemas/sokwedb/tables/Makefile | 2 +- db/schemas/sokwedb/tables/create/events.m4 | 24 +- .../sokwedb/tables/create/follow_observers.m4 | 6 +- .../sokwedb/tables/create/follow_studies.m4 | 6 +- .../sokwedb/tables/create/locations_b.m4 | 8 +- .../tables/create/{follows.m4 => watches.m4} | 8 +- doc/src/epilog.inc.m4 | 38 +- doc/src/functions/build_arrivals_seq.m4 | 8 +- doc/src/tables.m4 | 2 +- doc/src/tables/aggressions.m4 | 4 +- doc/src/tables/events.m4 | 34 +- doc/src/tables/follow_observers.m4 | 16 +- doc/src/tables/follow_studies.m4 | 14 +- doc/src/tables/locations_b.m4 | 32 +- doc/src/tables/pantgrunts.m4 | 3 +- doc/src/tables/roles.m4 | 14 +- doc/src/tables/{follows.m4 => watches.m4} | 50 +-- 52 files changed, 875 insertions(+), 874 deletions(-) rename conversion/{load_follow_to_follows.sql => load_follow_to_watches.sql} (73%) rename db/schemas/lib/triggers/create/{follows.m4 => watches.m4} (91%) rename db/schemas/lib/triggers/drop/{follows.m4 => watches.m4} (77%) rename db/schemas/sokwedb/indexes/create/{follows.m4 => watches.m4} (85%) rename db/schemas/sokwedb/indexes/drop/{follows.m4 => watches.m4} (88%) rename db/schemas/sokwedb/tables/create/{follows.m4 => watches.m4} (91%) rename doc/src/tables/{follows.m4 => watches.m4} (72%) diff --git a/conversion/Makefile b/conversion/Makefile index 81fda2e..0098d38 100644 --- a/conversion/Makefile +++ b/conversion/Makefile @@ -301,7 +301,7 @@ after_compare_state: load_data load_data: load_support load_biography load_community_membership \ load_biography_update_log load_community_membership_update_log \ load_aggression_event_log \ - load_follow_to_follows load_follow_to_other \ + load_follow_to_watches load_follow_to_other \ load_follow_arrival_sanity load_follow_arrival \ load_aggressions load_finish @@ -343,10 +343,10 @@ load_aggression_event_log: $(PSQL_DEPENDS) cat load_aggression_event_log.sql ;) \ | psql $(PSQL_ARGS) $(PSQL_SINGLE_TRANS) --set=ON_ERROR_STOP=y -.PHONY: load_follow_to_follows -load_follow_to_follows: $(PSQL_DEPENDS) +.PHONY: load_follow_to_watches +load_follow_to_watches: $(PSQL_DEPENDS) ( $(PSQL_SETUP) \ - cat load_follow_to_follows.sql ;) \ + cat load_follow_to_watches.sql ;) \ | psql $(PSQL_ARGS) $(PSQL_SINGLE_TRANS) --set=ON_ERROR_STOP=y .PHONY: load_follow_to_other diff --git a/conversion/load_aggressions.m4 b/conversion/load_aggressions.m4 index 74aaf9a..b05b613 100644 --- a/conversion/load_aggressions.m4 +++ b/conversion/load_aggressions.m4 @@ -29,7 +29,7 @@ SET search_path TO sokwedb, codes, lib, clean, libconv; DO $$ DECLARE this_ae clean.aggression_event%ROWTYPE; - related_fid follows.fid%TYPE; + related_wid watches.wid%TYPE; BEGIN @@ -43,22 +43,22 @@ BEGIN OFFSET m4_chunk_offset_amount LOOP -- Which follow belongs to the aggression_event? - SELECT follows.fid - INTO STRICT related_fid - FROM follows - WHERE follows.focal = this_ae.ae_fol_b_focal_id - AND follows.date = this_ae.ae_date; + SELECT watches.wid + INTO STRICT related_wid + FROM watches + WHERE watches.focal = this_ae.ae_fol_b_focal_id + AND watches.date = this_ae.ae_date; -- aggression_event -> EVENTS INSERT INTO events ( - fid + wid , behavior , start , stop , certainty , notes) VALUES ( - related_fid + related_wid , 'AGG' , this_ae.ae_time , this_ae.ae_time diff --git a/conversion/load_finish.sql b/conversion/load_finish.sql index 29e6553..1fe5097 100644 --- a/conversion/load_finish.sql +++ b/conversion/load_finish.sql @@ -1,5 +1,4 @@ --- Copyright (C) 2023, 2024, 2025 The Meme Factory, Inc. --- http://www.karlpinc.com/ +-- Copyright (C) 2023-2026 The Meme Factory, Inc. http://www.karlpinc.com/ -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -33,10 +32,10 @@ if false then PERFORM * FROM clean.follow_arrival WHERE NOT EXISTS - (SELECT follows.fid - FROM follows - WHERE follows.focal = follow_arrival.fa_fol_b_focal_animid - AND follows.date = follow_arrival.fa_fol_date); + (SELECT watches.wid + FROM watches + WHERE watches.focal = follow_arrival.fa_fol_b_focal_animid + AND watches.date = follow_arrival.fa_fol_date); IF FOUND THEN RAISE data_exception USING MESSAGE = 'There are follow_arrivals where there is no follow'; diff --git a/conversion/load_follow_arrival.m4 b/conversion/load_follow_arrival.m4 index 0cbdb74..ef7791d 100644 --- a/conversion/load_follow_arrival.m4 +++ b/conversion/load_follow_arrival.m4 @@ -1,5 +1,4 @@ --- Copyright (C) 2023, 2024, 2025 The Meme Factory, Inc. --- http://www.karlpinc.com/ +-- Copyright (C) 2023-2025 The Meme Factory, Inc. http://www.karlpinc.com/ -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -40,7 +39,7 @@ SET search_path TO sokwedb, codes, lib, clean, libconv; DO $$ DECLARE this_fa clean.follow_arrival%ROWTYPE; - related_fid follows.fid%TYPE; + related_wid watches.wid%TYPE; BEGIN @@ -55,22 +54,22 @@ BEGIN OFFSET m4_chunk_offset_amount LOOP -- Which follow belongs to the follow_arrival? - SELECT follows.fid - INTO STRICT related_fid - FROM follows - WHERE follows.focal = this_fa.fa_fol_b_focal_animid - AND follows.date = this_fa.fa_fol_date; + SELECT watches.wid + INTO STRICT related_wid + FROM watches + WHERE watches.focal = this_fa.fa_fol_b_focal_animid + AND watches.date = this_fa.fa_fol_date; -- follow_arrival -> EVENTS INSERT INTO events ( - fid + wid , behavior , start , stop , certainty , notes) VALUES ( - related_fid + related_wid , 'ARR' , this_fa.fa_time_start , this_fa.fa_time_end diff --git a/conversion/load_follow_to_other.sql b/conversion/load_follow_to_other.sql index b0a293e..958ef00 100644 --- a/conversion/load_follow_to_other.sql +++ b/conversion/load_follow_to_other.sql @@ -1,5 +1,4 @@ --- Copyright (C) 2023, 2024, 2025 The Meme Factory, Inc. --- http://www.karlpinc.com/ +-- Copyright (C) 2023-2026 The Meme Factory, Inc. http://www.karlpinc.com/ -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -43,23 +42,23 @@ INSERT INTO studies (study, description) DO NOTHING; -- follow.fol_study_code_1 -> FOLLOW_STUDIES -INSERT INTO follow_studies (fid, code) +INSERT INTO follow_studies (wid, code) SELECT - (SELECT follows.fid - FROM follows - WHERE follows.focal = follow.fol_b_animid - AND follows.date = follow.fol_date) + (SELECT watches.wid + FROM watches + WHERE watches.focal = follow.fol_b_animid + AND watches.date = follow.fol_date) , UPPER(follow.fol_study_code_1) FROM clean.follow WHERE fol_study_code_1 IS NOT NULL; -- follow.fol_study_code_2 -> FOLLOW_STUDIES -INSERT INTO follow_studies (fid, code) +INSERT INTO follow_studies (wid, code) SELECT - (SELECT follows.fid - FROM follows - WHERE follows.focal = follow.fol_b_animid - AND follows.date = follow.fol_date) + (SELECT watches.wid + FROM watches + WHERE watches.focal = follow.fol_b_animid + AND watches.date = follow.fol_date) , UPPER(follow.fol_study_code_2) FROM clean.follow WHERE fol_study_code_2 IS NOT NULL; diff --git a/conversion/load_follow_to_follows.sql b/conversion/load_follow_to_watches.sql similarity index 73% rename from conversion/load_follow_to_follows.sql rename to conversion/load_follow_to_watches.sql index 9a54294..c7f9cc2 100644 --- a/conversion/load_follow_to_follows.sql +++ b/conversion/load_follow_to_watches.sql @@ -1,5 +1,4 @@ --- Copyright (C) 2023, 2024, 2025 The Meme Factory, Inc. --- http://www.karlpinc.com/ +-- Copyright (C) 2023-2026 The Meme Factory, Inc. http://www.karlpinc.com/ -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -17,14 +16,14 @@ -- Karl O. Pinc -- -- Remarks: --- This does both FOLLOWS and FOLLOW_OBSERVERS because a FOLLOW_OBSERVERS --- row is required for every FOLLOWS row. +-- This does both WATCHES and FOLLOW_OBSERVERS because a FOLLOW_OBSERVERS +-- row is required for every WATCHES row. -- Setup the search path SET search_path TO sokwedb, codes, lib, clean, libconv; --- follow -> follows +-- follow -> watches -- Sanity checks DO $$ @@ -53,9 +52,9 @@ END; $$; -- --- follow -> FOLLOWS +-- follow -> WATCHES -- -INSERT INTO follows ( +INSERT INTO watches ( focal , commid , date @@ -74,7 +73,7 @@ SELECT fol_b_animid -- AM rows INSERT INTO follow_observers ( - fid + wid , period , obs_brec , obs_tiki) @@ -88,23 +87,23 @@ SELECT follow.fol_b_animid FROM clean.follow ) SELECT - (SELECT follows.fid - FROM follows - WHERE follows.focal = obs.fol_b_animid - AND follows.date = obs.fol_date) + (SELECT watches.wid + FROM watches + WHERE watches.focal = obs.fol_b_animid + AND watches.date = obs.fol_date) , 'AM' , COALESCE(obs.am_obs1, 'NONE') -- problem #38 , COALESCE(obs.am_obs2, 'NONE') -- problem #38 FROM obs - -- Don't try to load follows that haven't been converted - JOIN follows ON (follows.focal = obs.fol_b_animid - AND follows.date = obs.fol_date) + -- Don't try to load watches that haven't been converted + JOIN watches ON (watches.focal = obs.fol_b_animid + AND watches.date = obs.fol_date) WHERE COALESCE(obs.am_obs1, obs.am_obs2) IS NOT NULL; -- PM rows INSERT INTO follow_observers ( - fid + wid , period , obs_brec , obs_tiki) @@ -118,36 +117,36 @@ SELECT follow.fol_b_animid FROM clean.follow ) SELECT - (SELECT follows.fid - FROM follows - WHERE follows.focal = obs.fol_b_animid - AND follows.date = obs.fol_date) + (SELECT watches.wid + FROM watches + WHERE watches.focal = obs.fol_b_animid + AND watches.date = obs.fol_date) , 'PM' , COALESCE(obs.pm_obs1, 'NONE') -- problem #38 , COALESCE(obs.pm_obs2, 'NONE') -- problem #38 FROM obs - -- Don't try to load follows that haven't been converted - JOIN follows ON (follows.focal = obs.fol_b_animid - AND follows.date = obs.fol_date) + -- Don't try to load watches that haven't been converted + JOIN watches ON (watches.focal = obs.fol_b_animid + AND watches.date = obs.fol_date) WHERE COALESCE(obs.pm_obs1, obs.pm_obs2) IS NOT NULL; -- The UNK time period INSERT INTO follow_observers ( - fid + wid , period , obs_brec , obs_tiki) SELECT - (SELECT follows.fid - FROM follows - WHERE follows.focal = follow.fol_b_animid - AND follows.date = follow.fol_date) + (SELECT watches.wid + FROM watches + WHERE watches.focal = follow.fol_b_animid + AND watches.date = follow.fol_date) , 'UNK' , 'NONE' , 'NONE' FROM clean.follow; -ANALYZE follows +ANALYZE watches , follow_observers; diff --git a/db/schemas/lib/triggers/Makefile b/db/schemas/lib/triggers/Makefile index e5402ab..d7af9d8 100644 --- a/db/schemas/lib/triggers/Makefile +++ b/db/schemas/lib/triggers/Makefile @@ -29,7 +29,7 @@ ORDER := comm_ids \ _error_immutable_view \ follow_observers \ biography \ - follows \ + watches \ events \ roles \ arrivals \ diff --git a/db/schemas/lib/triggers/create/aggressions.m4 b/db/schemas/lib/triggers/create/aggressions.m4 index 31e5fe6..12f5e91 100644 --- a/db/schemas/lib/triggers/create/aggressions.m4 +++ b/db/schemas/lib/triggers/create/aggressions.m4 @@ -46,10 +46,10 @@ CREATE OR REPLACE FUNCTION aggressions_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -57,13 +57,13 @@ CREATE OR REPLACE FUNCTION aggressions_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) LEFT OUTER JOIN roles ON (roles.eid = events.eid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_aggression'; @@ -112,11 +112,11 @@ CREATE OR REPLACE FUNCTION aggressions_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/arrivals.m4 b/db/schemas/lib/triggers/create/arrivals.m4 index b1d2196..aadb179 100644 --- a/db/schemas/lib/triggers/create/arrivals.m4 +++ b/db/schemas/lib/triggers/create/arrivals.m4 @@ -13,7 +13,7 @@ dnl dnl You should have received a copy of the GNU Affero General Public License dnl along with this program. If not, see . dnl -dnl Triggers for the follows table +dnl Triggers for the arrivals table dnl dnl Karl O. Pinc @@ -42,7 +42,7 @@ define([_update_seqs], [ FROM roles AS this_role , events AS this_event JOIN events AS next_events - ON (next_events.fid = this_event.fid + ON (next_events.wid = this_event.wid AND next_events.behavior = 'sdb_arrival') JOIN roles AS next_roles ON (next_roles.eid = next_events.eid) @@ -68,7 +68,7 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () AS $$ DECLARE a_seq arrivals.seq%TYPE; - a_fid follows.fid%TYPE; + a_wid watches.wid%TYPE; BEGIN -- Function for arrivals before insert and before update triggers @@ -92,9 +92,9 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -102,13 +102,13 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) LEFT OUTER JOIN roles ON (roles.eid = events.eid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_arrival'; @@ -137,22 +137,22 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; -- There must be a related ROLES row. SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = NEW.eid AND NOT EXISTS (SELECT 1 @@ -182,11 +182,11 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -206,13 +206,13 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () -- Use the Start time value to sequence arrivals. -- Find the right sequence number to use - SELECT MAX(arrivals.seq) + 1, follows.fid - INTO a_seq , a_fid + SELECT MAX(arrivals.seq) + 1, watches.wid + INTO a_seq , a_wid FROM events - JOIN follows - ON (follows.fid = events.fid) + JOIN watches + ON (watches.wid = events.wid) JOIN events AS prior_aevents - ON (prior_aevents.fid = events.fid + ON (prior_aevents.wid = events.wid AND prior_aevents.behavior = 'sdb_arrival') JOIN roles AS prior_roles ON (prior_roles.eid = prior_aevents.eid) @@ -227,11 +227,11 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () AND prior_aevents.eid < NEW.eid)))) AND roles.eid = NEW.eid AND prior_roles.participant = roles.participant - GROUP BY follows.fid; -- Which does nothing, really + GROUP BY watches.wid; -- Which does nothing, really IF NOT FOUND THEN a_seq := 1; - SELECT events.fid - INTO a_fid + SELECT events.wid + INTO a_wid FROM events WHERE events.eid = NEW.eid; END IF; @@ -249,19 +249,19 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () a_pid roles.pid%TYPE; a_role roles.role%TYPE; a_participant roles.participant%TYPE; - -- FOLLOWS - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; BEGIN SELECT events.behavior, events.start, events.stop , roles.pid, roles.role, roles.participant - , follows.focal, follows.date + , watches.focal, watches.date INTO a_behavior , a_start , a_stop , a_pid , a_role , a_participant , a_focal , a_date FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) JOIN roles ON (roles.eid = NEW.eid) WHERE events.eid = NEW.eid ORDER BY roles.pid; -- Consistent error message @@ -296,11 +296,11 @@ CREATE OR REPLACE FUNCTION arrivals_before_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END; @@ -336,10 +336,10 @@ CREATE OR REPLACE FUNCTION arrivals_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -354,22 +354,22 @@ CREATE OR REPLACE FUNCTION arrivals_func () , roles.role, roles.pid , biography_data.animid, biography_data.sex , biography_data.birthdate - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_eid , a_behavior , a_start , a_stop , a_role , a_pid , a_animid , a_sex , a_birthdate - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM events JOIN roles ON (roles.eid = events.eid) JOIN biography_data ON (biography_data.animid = roles.participant) - JOIN follows - ON (follows.fid = events.fid) + JOIN watches + ON (watches.wid = events.wid) WHERE events.eid = NEW.eid -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , events.start, events.stop, events.eid , roles.role, roles.pid; @@ -404,11 +404,11 @@ CREATE OR REPLACE FUNCTION arrivals_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -456,11 +456,11 @@ CREATE OR REPLACE FUNCTION arrivals_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -504,11 +504,11 @@ CREATE OR REPLACE FUNCTION arrivals_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -555,11 +555,11 @@ CREATE OR REPLACE FUNCTION arrivals_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -601,11 +601,11 @@ CREATE OR REPLACE FUNCTION arrivals_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -646,11 +646,11 @@ CREATE OR REPLACE FUNCTION arrivals_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -723,10 +723,10 @@ CREATE OR REPLACE FUNCTION arrivals_commit_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -749,14 +749,14 @@ CREATE OR REPLACE FUNCTION arrivals_commit_func () IF NEW.seq > 1 THEN -- Does the expected NEW.seq - 1 row exist? SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM roles , events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.eid = NEW.eid AND events.eid = NEW.eid AND NOT EXISTS @@ -764,7 +764,7 @@ CREATE OR REPLACE FUNCTION arrivals_commit_func () FROM events AS pevents JOIN arrivals AS parrivals ON (parrivals.eid = pevents.eid) JOIN roles AS proles ON (proles.eid = pevents.eid) - WHERE pevents.fid = follows.fid + WHERE pevents.wid = watches.wid AND pevents.behavior = 'sdb_arrival' AND proles.participant = roles.participant AND parrivals.seq = NEW.seq - 1); @@ -804,11 +804,11 @@ CREATE OR REPLACE FUNCTION arrivals_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -818,15 +818,15 @@ CREATE OR REPLACE FUNCTION arrivals_commit_func () -- When there is an OLD.Seq + 1 row, -- does the expected OLD.seq row exist? SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM roles , events - JOIN follows ON (follows.fid = events.fid) - JOIN events AS oldslot ON (oldslot.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) + JOIN events AS oldslot ON (oldslot.wid = events.wid) JOIN arrivals ON (arrivals.eid = oldslot.eid) WHERE roles.eid = OLD.eid AND events.eid = OLD.eid @@ -839,7 +839,7 @@ CREATE OR REPLACE FUNCTION arrivals_commit_func () ON (parrivals.eid = pevents.eid) JOIN roles AS proles ON (proles.eid = pevents.eid) - WHERE pevents.fid = follows.fid + WHERE pevents.wid = watches.wid AND pevents.behavior = 'sdb_arrival' AND proles.participant = roles.participant AND parrivals.seq = OLD.seq); @@ -879,11 +879,11 @@ CREATE OR REPLACE FUNCTION arrivals_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/arrivals_a.m4 b/db/schemas/lib/triggers/create/arrivals_a.m4 index 6b06c70..3ff6341 100644 --- a/db/schemas/lib/triggers/create/arrivals_a.m4 +++ b/db/schemas/lib/triggers/create/arrivals_a.m4 @@ -13,7 +13,7 @@ dnl dnl You should have received a copy of the GNU Affero General Public License dnl along with this program. If not, see . dnl -dnl Triggers for the follows table +dnl Triggers for the arrivals_a table dnl dnl Karl O. Pinc @@ -47,10 +47,10 @@ CREATE OR REPLACE FUNCTION arrivals_a_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -58,13 +58,13 @@ CREATE OR REPLACE FUNCTION arrivals_a_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) LEFT OUTER JOIN roles ON (roles.eid = events.eid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_arrival_a'; @@ -92,11 +92,11 @@ CREATE OR REPLACE FUNCTION arrivals_a_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/biography_data.m4 b/db/schemas/lib/triggers/create/biography_data.m4 index 06b2e57..2262d22 100644 --- a/db/schemas/lib/triggers/create/biography_data.m4 +++ b/db/schemas/lib/triggers/create/biography_data.m4 @@ -436,20 +436,20 @@ CREATE OR REPLACE FUNCTION biography_data_func () -- Other table checking -- IF TG_OP = 'UPDATE' THEN - -- FOLLOWS + -- WATCHES DECLARE - a_fid follows.fid%TYPE; - a_commid follows.commid%TYPE; - a_date follows.date%TYPE; + a_wid watches.wid%TYPE; + a_commid watches.commid%TYPE; + a_date watches.date%TYPE; BEGIN -- Cannot have a follow before the individual was studied. IF NEW.entrydate <> OLD.entrydate THEN - SELECT follows.fid, follows.commid, follows.date - INTO a_fid , a_commid , a_date - FROM follows - WHERE follows.focal = NEW.animid - AND follows.date < NEW.entrydate - ORDER BY follows.date; -- consistency + SELECT watches.wid, watches.commid, watches.date + INTO a_wid , a_commid , a_date + FROM watches + WHERE watches.focal = NEW.animid + AND watches.date < NEW.entrydate + ORDER BY watches.date; -- consistency IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on UPDATE of BIOGRAPHY_DATA' @@ -459,8 +459,8 @@ CREATE OR REPLACE FUNCTION biography_data_func () || NEW.animid || '), Value (EntryDate) = (' || NEW.entrydate - || ': Key (FOLLOWS.FID) = (' - || a_fid + || ': Key (WATCHES.WID) = (' + || a_wid || '), Value (Date) = (' || a_date || '), Value (CommID) = (' @@ -471,12 +471,12 @@ CREATE OR REPLACE FUNCTION biography_data_func () -- Cannot have a follow after study of the individual has ceased. IF NEW.departdate <> OLD.departdate THEN - SELECT follows.fid, follows.commid, follows.date - INTO a_fid , a_commid , a_date - FROM follows - WHERE follows.focal = NEW.animid - AND follows.date > NEW.departdate - ORDER BY follows.date DESC; -- consistency + SELECT watches.wid, watches.commid, watches.date + INTO a_wid , a_commid , a_date + FROM watches + WHERE watches.focal = NEW.animid + AND watches.date > NEW.departdate + ORDER BY watches.date DESC; -- consistency IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on UPDATE of BIOGRAPHY_DATA' @@ -486,8 +486,8 @@ CREATE OR REPLACE FUNCTION biography_data_func () || NEW.animid || '), Value (DepartDate) = (' || NEW.departdate - || ': Key (FOLLOWS.FID) = (' - || a_fid + || ': Key (WATCHES.WID) = (' + || a_wid || '), Value (Date) = (' || a_date || '), Value (CommID) = (' @@ -908,10 +908,10 @@ CREATE OR REPLACE FUNCTION biography_data_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; BEGIN -- The participants in an event cannot be in a follow that is @@ -919,17 +919,17 @@ CREATE OR REPLACE FUNCTION biography_data_func () IF NEW.entrydate > OLD.entrydate THEN SELECT roles.pid, roles.role , events.eid, events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_pid , a_role , a_eid , a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid - AND follows.date < NEW.entrydate + AND watches.date < NEW.entrydate -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , roles.role, roles.pid , events.behavior, events.start, events.stop, events.eid; IF FOUND THEN @@ -955,11 +955,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -970,17 +970,17 @@ CREATE OR REPLACE FUNCTION biography_data_func () IF NEW.departdate < OLD.departdate THEN SELECT roles.pid, roles.role , events.eid, events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_pid , a_role , a_eid , a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid - AND follows.date > NEW.departdate + AND watches.date > NEW.departdate -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , roles.role, roles.pid , events.behavior, events.start, events.stop, events.eid; IF FOUND THEN @@ -1006,11 +1006,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -1026,10 +1026,10 @@ CREATE OR REPLACE FUNCTION biography_data_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_role roles.role%TYPE; @@ -1047,19 +1047,19 @@ CREATE OR REPLACE FUNCTION biography_data_func () SELECT roles.role , events.eid, events.behavior, events.start, events.stop , arrivals.cycle - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_role , a_eid , a_behavior , a_start , a_stop , a_cycle - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) JOIN arrivals ON (arrivals.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid AND arrivals.cycle = 'sdb_male_swelling' -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , events.start, events.stop, events.eid , roles.role, roles.pid; IF FOUND THEN @@ -1089,11 +1089,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_eid || '), Value (ARRIVALS.Cycle) = (' || a_cycle - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -1112,23 +1112,23 @@ CREATE OR REPLACE FUNCTION biography_data_func () SELECT roles.role , events.eid, events.behavior, events.start, events.stop , arrivals.cycle - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_role , a_eid , a_behavior , a_start , a_stop , a_cycle - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) JOIN arrivals ON (arrivals.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid AND arrivals.cycle = 'sdb_adolescent_swelling' AND NEW.birthdate - > (follows.date + > (watches.date - 'sdb_min_adolescent_age sdb_min_adolescent_age_units'::INTERVAL ) -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , events.start, events.stop, events.eid , roles.role, roles.pid; IF FOUND THEN @@ -1162,11 +1162,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_eid || '), Value (ARRIVALS.Cycle) = (' || a_cycle - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -1177,24 +1177,24 @@ CREATE OR REPLACE FUNCTION biography_data_func () SELECT roles.role , events.eid, events.behavior, events.start, events.stop , arrivals.cycle - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_role , a_eid , a_behavior , a_start , a_stop , a_eid , a_cycle - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) JOIN arrivals ON (arrivals.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid AND arrivals.cycle = 'sdb_adolescent_swelling' AND NEW.birthdate - <= (follows.date + <= (watches.date - '1 sdb_max_adolescent_age_units'::INTERVAL - 'sdb_max_adolescent_age sdb_max_adolescent_age_units'::INTERVAL ) -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , events.start, events.stop, events.eid , roles.role, roles.pid; IF FOUND THEN @@ -1228,11 +1228,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_eid || '), Value (ARRIVALS.Cycle) = (' || a_cycle - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -1247,25 +1247,25 @@ CREATE OR REPLACE FUNCTION biography_data_func () SELECT roles.role , events.eid, events.behavior, events.start, events.stop , arrivals.cycle - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_role , a_eid , a_behavior , a_start , a_stop , a_eid , a_cycle - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) JOIN arrivals ON (arrivals.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid AND arrivals.cycle <> 'sdb_no_swelling' AND arrivals.cycle <> 'sdb_adolescent_swelling' AND arrivals.cycle <> 'sdb_missing_swelling' AND NEW.birthdate - > (follows.date + > (watches.date - 'sdb_min_swelling_age sdb_min_swelling_age_units'::INTERVAL ) -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , events.start, events.stop, events.eid , roles.role, roles.pid; IF FOUND THEN @@ -1298,11 +1298,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_eid || '), Value (ARRIVALS.Cycle) = (' || a_cycle - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -1312,26 +1312,26 @@ CREATE OR REPLACE FUNCTION biography_data_func () SELECT roles.role , events.eid, events.behavior, events.start, events.stop , arrivals.cycle - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_role , a_eid , a_behavior , a_start , a_stop , a_cycle - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) JOIN arrivals ON (arrivals.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid AND arrivals.cycle <> 'sdb_no_swelling' AND arrivals.cycle <> 'sdb_adolescent_swelling' AND arrivals.cycle <> 'sdb_missing_swelling' AND NEW.birthdate - <= (follows.date + <= (watches.date - '1 sdb_max_swelling_age_units'::INTERVAL - 'sdb_max_swelling_age sdb_max_swelling_age_units'::INTERVAL ) -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , events.start, events.stop, events.eid , roles.role, roles.pid; IF FOUND THEN @@ -1364,11 +1364,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_eid || '), Value (ARRIVALS.Cycle) = (' || a_cycle - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')' , HINT = 'sdb_follow_age_hint'; @@ -1383,19 +1383,19 @@ CREATE OR REPLACE FUNCTION biography_data_func () SELECT roles.role , events.eid, events.behavior, events.start, events.stop , arrivals.cycle - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_role , a_eid , a_behavior , a_start , a_stop , a_cycle - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM roles JOIN events ON (events.eid = roles.eid) JOIN arrivals ON (arrivals.eid = roles.eid) - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE roles.participant = NEW.animid AND arrivals.cycle <> 'sdb_male_swelling' -- Produce a consistent error message - ORDER BY follows.date, follows.fid + ORDER BY watches.date, watches.wid , events.start, events.stop, events.eid , roles.role, roles.pid; IF FOUND THEN @@ -1426,11 +1426,11 @@ CREATE OR REPLACE FUNCTION biography_data_func () || a_eid || '), Value (ARRIVALS.Cycle) = (' || a_cycle - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/events.m4 b/db/schemas/lib/triggers/create/events.m4 index bbe26b7..44876d9 100644 --- a/db/schemas/lib/triggers/create/events.m4 +++ b/db/schemas/lib/triggers/create/events.m4 @@ -13,7 +13,7 @@ dnl dnl You should have received a copy of the GNU Affero General Public License dnl along with this program. If not, see . dnl -dnl Triggers for the follows table +dnl Triggers for the events table dnl dnl Karl O. Pinc @@ -38,13 +38,13 @@ CREATE OR REPLACE FUNCTION events_update_func () -- Allowing the EID to change makes life too complicated. cannot_change(`EVENTS', `EID') - -- If the FID is allowed to change, at minimum -- there may be other + -- If the WID is allowed to change, at minimum -- there may be other -- cases, the check that ROLES.Participant must be under study -- becomes complicated. It would require code in the triggers -- to trace the BIOGRAPHY_DATA.Animid <- ROLES.Participant -> - -- EVENTS.EID --> FOLLOWS.FID chain to check FOLLOWS.Date + -- EVENTS.EID --> WATCHES.WID chain to check WATCHES.Date -- against biography. Simpler to dis-allow change. - cannot_change(`EVENTS', `FID') + cannot_change(`EVENTS', `WID') -- Likewise, allowing the AtID to change adds too much complication. cannot_change(`EVENTS', `AtID') @@ -103,10 +103,10 @@ CREATE OR REPLACE FUNCTION events_delete_commit_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -119,19 +119,19 @@ CREATE OR REPLACE FUNCTION events_delete_commit_func () SELECT arrivals.seq, arrivals.neststart , arrivals.nestend, arrivals.cycle, arrivals.datasource , events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_seq , a_neststart , a_nestend , a_cycle , a_datasource , a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant - FROM follows + FROM watches , events JOIN arrivals ON (arrivals.eid = events.eid) JOIN roles ON (roles.eid = events.eid) - WHERE follows.fid = OLD.fid - AND events.fid = OLD.fid + WHERE watches.wid = OLD.wid + AND events.wid = OLD.wid AND events.behavior = 'sdb_arrival' AND arrivals.seq > 1 AND NOT EXISTS @@ -141,7 +141,7 @@ CREATE OR REPLACE FUNCTION events_delete_commit_func () ON (p1roles.eid = p1events.eid) JOIN arrivals AS p1arrivals ON (p1arrivals.eid = p1events.eid) - WHERE p1events.fid = OLD.fid + WHERE p1events.wid = OLD.wid AND p1roles.participant = roles.participant AND p1arrivals.seq = arrivals.seq - 1) -- Produce a consistent error message @@ -182,11 +182,11 @@ CREATE OR REPLACE FUNCTION events_delete_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS .Date) = (' + || '), Value (WATCHES .Date) = (' || a_date || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/follow_observers.m4 b/db/schemas/lib/triggers/create/follow_observers.m4 index b7a6e5d..d6fae84 100644 --- a/db/schemas/lib/triggers/create/follow_observers.m4 +++ b/db/schemas/lib/triggers/create/follow_observers.m4 @@ -43,36 +43,36 @@ CREATE OR REPLACE FUNCTION follow_observers_func () person_active({FOLLOW_OBSERVERS}, {OBS_BRec}, {'Key (FOID) = (' || NEW.FOID - || '): Value (FID) = (' - || NEW.FID + || '): Value (WID) = (' + || NEW.WID || '): ' - || (SELECT 'Value (FOLLOWS.Focal) = (' - || follows.focal - || '): Value (FOLLOWS.CommID) = (' - || follows.commid - || '): Value (FOLLOWS.Date) = (' - || follows.date + || (SELECT 'Value (WATCHES.Focal) = (' + || watches.focal + || '): Value (WATCHES.CommID) = (' + || watches.commid + || '): Value (WATCHES.Date) = (' + || watches.date || '): ' - FROM follows - WHERE follows.fid = NEW.fid) + FROM watches + WHERE watches.wid = NEW.wid) || '(Period) = (' || NEW.period || ')'}) person_active({FOLLOW_OBSERVERS}, {OBS_Tiki}, {'Key (FOID) = (' - || NEW.FOID - || '): Value (FID) = (' - || NEW.FID + || NEW.foid + || '): Value (WID) = (' + || NEW.wid || '): ' - || (SELECT 'Value (FOLLOWS.Focal) = (' - || follows.focal - || '): Value (FOLLOWS.CommID) = (' - || follows.commid - || '): Value (FOLLOWS.Date) = (' - || follows.date + || (SELECT 'Value (WATCHES.Focal) = (' + || watches.focal + || '): Value (WATCHES.CommID) = (' + || watches.commid + || '): Value (WATCHES.Date) = (' + || watches.date || '): ' - FROM follows - WHERE follows.fid = NEW.fid) + FROM watches + WHERE watches.wid = NEW.wid) || 'Value (Period) = (' || NEW.period || ')'}) diff --git a/db/schemas/lib/triggers/create/food_events.m4 b/db/schemas/lib/triggers/create/food_events.m4 index 6b38dfe..232cf3d 100644 --- a/db/schemas/lib/triggers/create/food_events.m4 +++ b/db/schemas/lib/triggers/create/food_events.m4 @@ -46,10 +46,10 @@ CREATE OR REPLACE FUNCTION food_events_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -57,13 +57,13 @@ CREATE OR REPLACE FUNCTION food_events_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) LEFT OUTER JOIN roles ON (roles.eid = events.eid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_food'; @@ -98,11 +98,11 @@ CREATE OR REPLACE FUNCTION food_events_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -156,10 +156,10 @@ CREATE OR REPLACE FUNCTION food_events_commit_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -167,13 +167,13 @@ CREATE OR REPLACE FUNCTION food_events_commit_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) -- It would be nice to also check, and know, that -- a ROLES row exists, but we leave this to the warnings. LEFT OUTER JOIN roles ON (roles.eid = events.eid) @@ -209,11 +209,11 @@ CREATE OR REPLACE FUNCTION food_events_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END; @@ -262,10 +262,10 @@ CREATE OR REPLACE FUNCTION food_events_delete_commit_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -273,13 +273,13 @@ CREATE OR REPLACE FUNCTION food_events_delete_commit_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) -- It would be nice to also check, and know, that -- a ROLES row exists, but we leave this to the warnings. LEFT OUTER JOIN roles ON (roles.eid = events.eid) @@ -315,11 +315,11 @@ CREATE OR REPLACE FUNCTION food_events_delete_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END; diff --git a/db/schemas/lib/triggers/create/groom_scans_b.m4 b/db/schemas/lib/triggers/create/groom_scans_b.m4 index fafe7e6..af42f5d 100644 --- a/db/schemas/lib/triggers/create/groom_scans_b.m4 +++ b/db/schemas/lib/triggers/create/groom_scans_b.m4 @@ -46,10 +46,10 @@ CREATE OR REPLACE FUNCTION groom_scans_b_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -57,13 +57,13 @@ CREATE OR REPLACE FUNCTION groom_scans_b_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) LEFT OUTER JOIN roles ON (roles.eid = events.eid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_groom_scan'; @@ -96,11 +96,11 @@ CREATE OR REPLACE FUNCTION groom_scans_b_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/groomings.m4 b/db/schemas/lib/triggers/create/groomings.m4 index 7678c41..86fac95 100644 --- a/db/schemas/lib/triggers/create/groomings.m4 +++ b/db/schemas/lib/triggers/create/groomings.m4 @@ -46,10 +46,10 @@ CREATE OR REPLACE FUNCTION groomings_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -57,13 +57,13 @@ CREATE OR REPLACE FUNCTION groomings_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) LEFT OUTER JOIN roles ON (roles.eid = events.eid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_grooming' @@ -97,11 +97,11 @@ CREATE OR REPLACE FUNCTION groomings_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -137,11 +137,11 @@ define({_sdb_grm_actor_or_actee}, -- The $1 must be one of the participants in the grooming SELECT events.start, events.stop, events.behavior - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_start , a_stop , a_behavior - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = NEW.eid AND NOT EXISTS (SELECT 1 @@ -177,11 +177,11 @@ define({_sdb_grm_actor_or_actee}, || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -208,10 +208,10 @@ CREATE OR REPLACE FUNCTION groomings_commit_func () a_start events.start%TYPE; a_stop events.stop%TYPE; a_behavior events.behavior%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; BEGIN _sdb_grm_actor_or_actee(`Initiator') diff --git a/db/schemas/lib/triggers/create/humans.m4 b/db/schemas/lib/triggers/create/humans.m4 index 0f33944..423cc8c 100644 --- a/db/schemas/lib/triggers/create/humans.m4 +++ b/db/schemas/lib/triggers/create/humans.m4 @@ -45,20 +45,20 @@ CREATE OR REPLACE FUNCTION humans_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; BEGIN -- The EVENTS.Behavior must be sdb_other_species SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_other_species'; IF FOUND THEN @@ -80,11 +80,11 @@ CREATE OR REPLACE FUNCTION humans_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -96,13 +96,13 @@ CREATE OR REPLACE FUNCTION humans_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , species_present.species INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_species FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) , species_present WHERE events.eid = NEW.eid AND species_present.eid = NEW.eid; @@ -127,11 +127,11 @@ CREATE OR REPLACE FUNCTION humans_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || '): Key (SPECIES_PRESENT.EID) = (' || NEW.eid diff --git a/db/schemas/lib/triggers/create/locations_b.m4 b/db/schemas/lib/triggers/create/locations_b.m4 index ac12804..46742af 100644 --- a/db/schemas/lib/triggers/create/locations_b.m4 +++ b/db/schemas/lib/triggers/create/locations_b.m4 @@ -23,29 +23,29 @@ include(`constants.m4')dnl include(`macros.m4')dnl -dnl Plpgsql fragment that checks that there is not a FOLLOWS row with +dnl Plpgsql fragment that checks that there is not a WATCHES row with dnl the same Focal and Date as the new row. dnl -dnl Syntax: _check_no_related_follow() +dnl Syntax: _check_no_related_watch() dnl changequote({,}) -define({_check_no_related_follow}, {dnl - -- Cannot have a FOLLOWS row related on Focal and Date +define({_check_no_related_watch}, {dnl + -- Cannot have a WATCHES row related on Focal and Date DECLARE - a_fid follows.fid%TYPE; + a_wid watches.wid%TYPE; BEGIN - SELECT follows.fid - INTO a_fid - FROM follows - WHERE follows.animid IS NOT DISTINCT FROM NEW.focal - AND follows.date IS NOT DISTINCT FROM NEW.date; + SELECT watches.wid + INTO a_wid + FROM watches + WHERE watches.animid IS NOT DISTINCT FROM NEW.focal + AND watches.date IS NOT DISTINCT FROM NEW.date; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on ' || TG_OP || ' of LOCATIONS_B' - , DETAIL = 'A FOLLOWS row cannot exist that has the same Focal' + , DETAIL = 'A WATCHES row cannot exist that has the same Focal' || ' and same Date as a LOCATIONS_B row, but such' - || ' a row exists on FOLLOWS' + || ' a row exists on WATCHES' || ': Key (LBID) = (' || NEW.lbid || '), Value (Focal) = (' @@ -74,8 +74,8 @@ define({_check_no_related_follow}, {dnl || NEW.notes || '), Value (Entered) = (' || NEW.entered - || '), Key (FOLLOWS.FID) = (' - || a_fid + || '), Key (WATCHES.WID) = (' + || a_wid || ')'; END IF; END; @@ -202,15 +202,15 @@ CREATE OR REPLACE FUNCTION locations_b_func () IF TG_OP = 'INSERT' AND NEW.focal IS NOT NULL THEN - _check_no_related_follow() + _check_no_related_watch() END IF; changequote({,})dnl person_active({LOCATIONS_B}, {EnteredBy}, {'Key (LBID = (' || NEW.lbid - || '): Value (FID) = (' - || textualize(NEW.fid) + || '): Value (WID) = (' + || textualize(NEW.wid) || '): Value (AnimID) = (' || textualize(NEW.animid) || '): Value (Date) = (' @@ -254,20 +254,20 @@ CREATE OR REPLACE FUNCTION locations_b_update_commit_func () `The Meme Factory, Inc., www.karlpinc.com') -- -- Remarks: - -- In order to be able to delete a FOLLOWS row that has related - -- LOCATIONS_B rows, the FID must be removed from the LOCATIONS_B + -- In order to be able to delete a WATCHES row that has related + -- LOCATIONS_B rows, the WID must be removed from the LOCATIONS_B -- row, because of the referential constraint, and then the - -- FOLLOWS row can be deleted. But removing a FID means adding + -- WATCHES row can be deleted. But removing a WID means adding -- Focal and Date values, and we don't want these when there's - -- a related FOLLOWS row, which still exists at the time the - -- FID is removed and Focal and Date added. So, wait to check - -- for a related FOLLOWS row until after transaction commit. + -- a related WATCHES row, which still exists at the time the + -- WID is removed and Focal and Date added. So, wait to check + -- for a related WATCHES row until after transaction commit. IF (NEW.focal IS DISTINCT FROM OLD.focal OR NEW.date IS DISTINCT FROM OLD.date) AND NEW.focal IS NOT NULL THEN - _check_no_related_follow() + _check_no_related_watch() END IF; RETURN NULL; diff --git a/db/schemas/lib/triggers/create/pantgrunts.m4 b/db/schemas/lib/triggers/create/pantgrunts.m4 index dbe2e47..d9b1ac7 100644 --- a/db/schemas/lib/triggers/create/pantgrunts.m4 +++ b/db/schemas/lib/triggers/create/pantgrunts.m4 @@ -46,10 +46,10 @@ CREATE OR REPLACE FUNCTION pantgrunts_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; -- ROLES a_pid roles.pid%TYPE; a_role roles.role%TYPE; @@ -57,13 +57,13 @@ CREATE OR REPLACE FUNCTION pantgrunts_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , roles.pid, roles.role, roles.participant INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_pid , a_role , a_participant FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) LEFT OUTER JOIN roles ON (roles.eid = events.eid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_pantgrunt' @@ -99,11 +99,11 @@ CREATE OR REPLACE FUNCTION pantgrunts_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; diff --git a/db/schemas/lib/triggers/create/roles.m4 b/db/schemas/lib/triggers/create/roles.m4 index 99493a0..26c78f8 100644 --- a/db/schemas/lib/triggers/create/roles.m4 +++ b/db/schemas/lib/triggers/create/roles.m4 @@ -13,7 +13,7 @@ dnl dnl You should have received a copy of the GNU Affero General Public License dnl along with this program. If not, see . dnl -dnl Triggers for the follows table +dnl Triggers for the roles table dnl dnl Karl O. Pinc @@ -33,7 +33,7 @@ CREATE OR REPLACE FUNCTION roles_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - a_fid events.fid%TYPE; + a_wid events.wid%TYPE; a_atid events.atid%TYPE; BEGIN @@ -66,8 +66,8 @@ CREATE OR REPLACE FUNCTION roles_func () -- Get the event information so we have the behavior and -- don't select the same data multiple times. -- (An over-optimization -- the benefit is to keep the code simple.) - SELECT events.behavior ,events.start, events.stop, events.fid, events.atid - INTO a_behavior , a_start , a_stop , a_fid , a_atid + SELECT events.behavior ,events.start, events.stop, events.wid, events.atid + INTO a_behavior , a_start , a_stop , a_wid , a_atid FROM events WHERE events.eid = NEW.eid; END IF; @@ -76,14 +76,14 @@ CREATE OR REPLACE FUNCTION roles_func () IF TG_OP = 'INSERT' AND a_behavior = 'sdb_other_species' THEN DECLARE - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; BEGIN - SELECT follows.focal, follows.date + SELECT watches.focal, watches.date INTO a_focal , a_date - FROM follows - WHERE follows.fid = a_fid; + FROM watches + WHERE watches.wid = a_wid; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on ' || TG_OP || ' of ROLES' @@ -104,11 +104,11 @@ CREATE OR REPLACE FUNCTION roles_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -120,20 +120,20 @@ CREATE OR REPLACE FUNCTION roles_func () DECLARE a_entrydate biography_data.entrydate%TYPE; a_departdate biography_data.departdate%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; BEGIN -- The follow cannot be before the participant's entrydate. SELECT biography_data.entrydate - , follows.focal, follows.date + , watches.focal, watches.date INTO a_entrydate , a_focal , a_date FROM biography_data - , follows + , watches WHERE biography_data.animid = NEW.participant - AND follows.fid = a_fid - AND follows.date < biography_data.entrydate; + AND watches.wid = a_wid + AND watches.date < biography_data.entrydate; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on ' || TG_OP || ' of ROLES' @@ -156,25 +156,25 @@ CREATE OR REPLACE FUNCTION roles_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; -- The follow cannot be after the participant's departdate. SELECT biography_data.entrydate - , follows.focal, follows.date + , watches.focal, watches.date INTO a_departdate , a_focal , a_date FROM biography_data - , follows + , watches WHERE biography_data.animid = NEW.participant - AND follows.fid = a_fid - AND follows.date > biography_data.departdate; + AND watches.wid = a_wid + AND watches.date > biography_data.departdate; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on ' || TG_OP || ' of ROLES' @@ -198,11 +198,11 @@ CREATE OR REPLACE FUNCTION roles_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -220,7 +220,7 @@ CREATE OR REPLACE FUNCTION roles_func () a_role roles.role%TYPE; a_participant roles.participant%TYPE; - a_focal follows.focal%TYPE; + a_focal watches.focal%TYPE; a_animid attendance.animid%TYPE; a_date DATE; @@ -252,18 +252,18 @@ CREATE OR REPLACE FUNCTION roles_func () || a_commid || ')'; ELSE -- a_behavior is sdb_arrival or sdb_food - SELECT follows.focal, follows.date, follows.commid + SELECT watches.focal, watches.date, watches.commid INTO a_focal , a_date , a_commid - FROM follows - WHERE follows.fid = a_fid; + FROM watches + WHERE watches.wid = a_wid; - observation_msg := 'Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + observation_msg := 'Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -314,7 +314,7 @@ CREATE OR REPLACE FUNCTION roles_func () a_role roles.role%TYPE; a_participant roles.participant%TYPE; - a_focal follows.focal%TYPE; + a_focal watches.focal%TYPE; a_animid attendance.animid%TYPE; a_date DATE; @@ -332,10 +332,10 @@ CREATE OR REPLACE FUNCTION roles_func () AND NEW.role <> 'sdb_actee' THEN -- The ROLES rows for aggression events must have -- a role of sdb_actor or sdb_actee. - SELECT follows.focal, follows.date, follows.commid + SELECT watches.focal, watches.date, watches.commid INTO a_focal , a_date , a_commid - FROM follows - WHERE follows.fid = a_fid; + FROM watches + WHERE watches.wid = a_wid; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on INSERT of ROLES' @@ -354,13 +354,13 @@ CREATE OR REPLACE FUNCTION roles_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')' , HINT = 'The ROLES.Role must be either (sdb_actor)' @@ -385,7 +385,7 @@ CREATE OR REPLACE FUNCTION roles_func () SELECT attendance.animid, attendance.date, attendance.commid INTO a_animid , a_date , a_commid FROM attendance - WHERE follows.fid = a_fid; + WHERE watches.wid = a_wid; observation_msg := 'Value (ATTENDANCE.AtID) = (' || a_atid @@ -398,17 +398,17 @@ CREATE OR REPLACE FUNCTION roles_func () || ')'; ELSE -- Behavior is sdb_aggression or sdb_grooming or sdb_groom_scan - SELECT follows.focal, follows.date, follows.commid + SELECT watches.focal, watches.date, watches.commid INTO a_focal , a_date , a_commid - FROM follows - WHERE follows.fid = a_fid; - observation_msg := 'Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + FROM watches + WHERE watches.wid = a_wid; + observation_msg := 'Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -455,16 +455,16 @@ CREATE OR REPLACE FUNCTION roles_func () IF TG_OP = 'INSERT' AND a_behavior = 'sdb_food' THEN DECLARE - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; - a_commid follows.commid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; + a_commid watches.commid%TYPE; BEGIN - SELECT follows.focal, follows.date, follows.commid + SELECT watches.focal, watches.date, watches.commid INTO a_focal , a_date , a_commid - FROM follows - WHERE follows.fid = a_fid - AND NEW.participant <> follows.focal; + FROM watches + WHERE watches.wid = a_wid + AND NEW.participant <> watches.focal; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on INSERT of ROLES' @@ -483,13 +483,13 @@ CREATE OR REPLACE FUNCTION roles_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -559,15 +559,15 @@ CREATE OR REPLACE FUNCTION roles_func () AND NEW.role <> 'sdb_actee' AND NEW.role <> 'sdb_mutual' THEN DECLARE - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; - a_commid follows.commid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; + a_commid watches.commid%TYPE; BEGIN - SELECT follows.focal, follows.date, follows.commid + SELECT watches.focal, watches.date, watches.commid INTO a_focal , a_date , a_commid - FROM follows - WHERE follows.fid = a_fid; + FROM watches + WHERE watches.wid = a_wid; RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on INSERT of ROLES' , DETAIL = 'Invalid Roles value for a sdb_pantgrunt event' @@ -585,13 +585,13 @@ CREATE OR REPLACE FUNCTION roles_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')' , HINT = 'When EVENTS.Behavior = (sdb_pantgrunt) the only' @@ -613,21 +613,21 @@ CREATE OR REPLACE FUNCTION roles_func () a_role roles.role%TYPE; a_participant roles.participant%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; - a_commid follows.commid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; + a_commid watches.commid%TYPE; BEGIN SELECT roles.pid, roles.role, roles.participant - , follows.focal, follows.date, follows.commid + , watches.focal, watches.date, watches.commid INTO a_pid , a_role , a_participant , a_focal , a_date , a_commid FROM roles - , follows + , watches WHERE roles.eid = NEW.eid AND roles.pid <> NEW.pid AND roles.role = NEW.role - AND follows.fid = a_fid; + AND watches.wid = a_wid; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on INSERT of ROLES' @@ -658,13 +658,13 @@ CREATE OR REPLACE FUNCTION roles_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')' , HINT = 'The roles in an ' @@ -691,11 +691,11 @@ CREATE OR REPLACE FUNCTION roles_delete_func () a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; - a_commid follows.commid%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; + a_commid watches.commid%TYPE; -- ARRIVALS a_seq arrivals.seq%TYPE; @@ -711,15 +711,15 @@ CREATE OR REPLACE FUNCTION roles_delete_func () -- Arrival events must have a related participant -- (Because otherwise we cannot sequence them per arriving individual.) SELECT events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid , arrivals.seq, arrivals.neststart, arrivals.nestend , arrivals.cycle INTO a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid , a_seq , a_neststart , a_nestend , a_cycle FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) , arrivals WHERE events.eid = OLD.eid AND arrivals.eid = OLD.eid; @@ -742,13 +742,13 @@ CREATE OR REPLACE FUNCTION roles_delete_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || '), Key (EID) = (' || a_eid @@ -781,10 +781,10 @@ CREATE OR REPLACE FUNCTION roles_insert_commit_func () a_start events.start%TYPE; a_stop events.stop%TYPE; - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; - a_commid follows.commid%TYPE; + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; + a_commid watches.commid%TYPE; missing_role role_codes.role%TYPE; @@ -806,11 +806,11 @@ CREATE OR REPLACE FUNCTION roles_insert_commit_func () END CASE; SELECT events.behavior ,events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = NEW.eid AND NOT EXISTS (SELECT 1 @@ -839,13 +839,13 @@ CREATE OR REPLACE FUNCTION roles_insert_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -855,11 +855,11 @@ CREATE OR REPLACE FUNCTION roles_insert_commit_func () -- When there is a sdb_mutual Role, the event must have another ROLES -- row that has a sdb_mutual Role. SELECT events.behavior ,events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = NEW.eid AND NOT EXISTS (SELECT 1 @@ -888,13 +888,13 @@ CREATE OR REPLACE FUNCTION roles_insert_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -904,18 +904,18 @@ CREATE OR REPLACE FUNCTION roles_insert_commit_func () -- the focal and must be the sdb_actor or the sdb_actee SELECT events.behavior ,events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = NEW.eid AND events.behavior = 'sdb_grooming' AND NOT EXISTS (SELECT 1 FROM roles WHERE roles.eid = NEW.eid - AND roles.participant = follows.focal + AND roles.participant = watches.focal AND (roles.role = 'sdb_actor' OR roles.role = 'sdb_actee')); IF FOUND THEN @@ -939,13 +939,13 @@ CREATE OR REPLACE FUNCTION roles_insert_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -967,11 +967,11 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; - a_commid follows.commid%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; + a_commid watches.commid%TYPE; -- GROOMINGS a_initiator groomings.initiator%TYPE; @@ -1017,11 +1017,11 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () AND actee_count = 0)) THEN SELECT events.behavior ,events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = OLD.eid; RAISE EXCEPTION integrity_constraint_violation USING @@ -1048,13 +1048,13 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -1080,11 +1080,11 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () IF mutual_count = 1 THEN SELECT events.behavior ,events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = OLD.eid; RAISE EXCEPTION integrity_constraint_violation USING @@ -1107,13 +1107,13 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -1124,19 +1124,19 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () -- the focal, who must be either the sdb_actor or the sdb_actee SELECT events.behavior ,events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = OLD.eid AND events.behavior = 'sdb_grooming' - AND follows.focal = OLD.participant + AND watches.focal = OLD.participant AND NOT EXISTS (SELECT 1 FROM roles WHERE roles.eid = OLD.eid - AND roles.participant = follows.focal + AND roles.participant = watches.focal AND (roles.role = 'sdb_actor' OR roles.role = 'sdb_actee')); IF FOUND THEN @@ -1160,13 +1160,13 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || ')'; END IF; @@ -1175,15 +1175,15 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () -- a participant and an sdb_actor or an sdb_actee. SELECT events.behavior ,events.start, events.stop - , follows.fid, follows.focal, follows.date, follows.commid + , watches.wid, watches.focal, watches.date, watches.commid , groomings.initiator, groomings.terminator , groomings.problems, groomings.extractedby INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date , a_commid + , a_wid , a_focal , a_date , a_commid , a_initiator , a_terminator , a_problems , a_extractedby FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) , groomings WHERE events.eid = OLD.eid AND events.behavior = 'sdb_grooming' @@ -1224,13 +1224,13 @@ CREATE OR REPLACE FUNCTION roles_delete_commit_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '), Value (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '), Value (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date - || '), Value (FOLLOWS.CommID) = (' + || '), Value (WATCHES.CommID) = (' || a_commid || '), Value (GROOMINGS.Initiator) = (' || textualize(`a_initiator') diff --git a/db/schemas/lib/triggers/create/species_present.m4 b/db/schemas/lib/triggers/create/species_present.m4 index 308ed37..b2a3ab7 100644 --- a/db/schemas/lib/triggers/create/species_present.m4 +++ b/db/schemas/lib/triggers/create/species_present.m4 @@ -45,20 +45,20 @@ CREATE OR REPLACE FUNCTION species_present_func () a_behavior events.behavior%TYPE; a_start events.start%TYPE; a_stop events.stop%TYPE; - -- FOLLOWS - a_fid follows.fid%TYPE; - a_focal follows.focal%TYPE; - a_date follows.date%TYPE; + -- WATCHES + a_wid watches.wid%TYPE; + a_focal watches.focal%TYPE; + a_date watches.date%TYPE; BEGIN -- The EVENTS.Behavior must be sdb_other_species SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) WHERE events.eid = NEW.eid AND events.behavior <> 'sdb_other_species'; IF FOUND THEN @@ -80,11 +80,11 @@ CREATE OR REPLACE FUNCTION species_present_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || ')'; END IF; @@ -97,13 +97,13 @@ CREATE OR REPLACE FUNCTION species_present_func () BEGIN SELECT events.behavior, events.start, events.stop - , follows.fid, follows.focal, follows.date + , watches.wid, watches.focal, watches.date , humans.researchers, humans.nonresearchers INTO a_behavior , a_start , a_stop - , a_fid , a_focal , a_date + , a_wid , a_focal , a_date , a_researchers , a_nonresearchers FROM events - JOIN follows ON (follows.fid = events.fid) + JOIN watches ON (watches.wid = events.wid) , humans WHERE events.eid = NEW.eid AND humans.eid = NEW.eid; @@ -128,11 +128,11 @@ CREATE OR REPLACE FUNCTION species_present_func () || a_start || '), Value (EVENTS.Stop) = (' || a_stop - || '): Key (FOLLOWS.FID) = (' - || a_fid - || '), Value (FOLLOWS.Focal) = (' + || '): Key (WATCHES.WID) = (' + || a_wid + || '), Value (WATCHES.Focal) = (' || a_focal - || '), Value (FOLLOWS.Date) = (' + || '), Value (WATCHES.Date) = (' || a_date || '): Key (HUMANS.EID) = (' || NEW.eid diff --git a/db/schemas/lib/triggers/create/follows.m4 b/db/schemas/lib/triggers/create/watches.m4 similarity index 91% rename from db/schemas/lib/triggers/create/follows.m4 rename to db/schemas/lib/triggers/create/watches.m4 index a8455bf..a79575c 100644 --- a/db/schemas/lib/triggers/create/follows.m4 +++ b/db/schemas/lib/triggers/create/watches.m4 @@ -13,7 +13,7 @@ dnl dnl You should have received a copy of the GNU Affero General Public License dnl along with this program. If not, see . dnl -dnl Triggers for the follows table +dnl Triggers for the watches table dnl dnl Karl O. Pinc @@ -23,8 +23,8 @@ include(`constants.m4')dnl include(`macros.m4')dnl -RAISE INFO 'follows_func'; -CREATE OR REPLACE FUNCTION follows_func () +RAISE INFO 'watches_func'; +CREATE OR REPLACE FUNCTION watches_func () RETURNS trigger LANGUAGE plpgsql sdb_function_set_search_path @@ -41,14 +41,14 @@ CREATE OR REPLACE FUNCTION follows_func () a_stop events.stop%TYPE; BEGIN - -- Function for follows insert and update triggers + -- Function for watches insert and update triggers -- -- AGPL_notice(` --', `2025, 2026', `The Meme Factory, Inc., www.karlpinc.com') IF TG_OP = 'UPDATE' THEN - -- Allowing the FID to change makes life too complicated. - cannot_change(`FOLLOWS', `FID') + -- Allowing the WID to change makes life too complicated. + cannot_change(`WATCHES', `WID') END IF; -- Cannot have a follow date before the individual was studied @@ -63,11 +63,11 @@ CREATE OR REPLACE FUNCTION follows_func () AND biography_data.entrydate > NEW.date; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on ' || TG_OP || ' of FOLLOWS' + MESSAGE = 'Error on ' || TG_OP || ' of WATCHES' , DETAIL = 'An individual cannot be followed before they are' || ' studied' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -92,11 +92,11 @@ CREATE OR REPLACE FUNCTION follows_func () AND NEW.date > biography_data.departdate; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on ' || TG_OP || ' of FOLLOWS' + MESSAGE = 'Error on ' || TG_OP || ' of WATCHES' , DETAIL = 'An individual cannot be followed when they are no' || ' longer under study' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -134,20 +134,20 @@ CREATE OR REPLACE FUNCTION follows_func () ON (roles.eid = events.eid) JOIN biography_data ON (biography_data.animid = roles.participant) - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND biography_data.entrydate < NEW.date -- A consistent error message ORDER BY events.start, events.stop, events.eid , roles.particpant, roles.role; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'An individual cannot particpate (be a' || ' ROLES.Participant) in a follow before' || ' their entry to the study' || ' (before BIOGRAPHY_DATA.EntryDate)' - || '): Key (FID) = (' - || NEW.fid + || '): Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (CommID) = (' @@ -186,20 +186,20 @@ CREATE OR REPLACE FUNCTION follows_func () ON (roles.eid = events.eid) JOIN biography_data ON (biography_data.animid = roles.participant) - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND biography_data.departdate > NEW.date -- A consistent error message ORDER BY events.start, events.stop, events.eid , roles.particpant, roles.role; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'An individual cannot particpate (be a' || ' ROLES.Participant) in a follow after' || ' their departure from the study' || ' (after BIOGRAPHY_DATA.EntryDate)' - || '): Key (FID) = (' - || NEW.fid + || '): Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (CommID) = (' @@ -244,7 +244,7 @@ CREATE OR REPLACE FUNCTION follows_func () JOIN biography_data ON (biography_data.animid = roles.participant) JOIN arrivals ON (arrivals.eid = events.eid) - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND roles.participant <> 'sdb_stranger_female' AND roles.participant <> 'sdb_stranger_female2' AND roles.participant <> 'sdb_stranger_female3' @@ -260,15 +260,15 @@ CREATE OR REPLACE FUNCTION follows_func () , roles.particpant, roles.role; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'A non-adolescent female, a female younger than' || ' sdb_min_adolescent_age' || ' sdb_min_adolescent_age_units old, cannot be' || ' assigned the' || ' (sdb_adolescent_swelling) code as a sexual' || ' cycle state' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -315,7 +315,7 @@ CREATE OR REPLACE FUNCTION follows_func () JOIN biography_data ON (biography_data.animid = roles.participant) JOIN arrivals ON (arrivals.eid = events.eid) - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND roles.participant <> 'sdb_stranger_female' AND roles.participant <> 'sdb_stranger_female2' AND roles.participant <> 'sdb_stranger_female3' @@ -332,15 +332,15 @@ CREATE OR REPLACE FUNCTION follows_func () , roles.particpant, roles.role; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'A non-adolescent female, a female older than' || ' sdb_max_adolescent_age' || ' sdb_max_adolescent_age_units old, cannot be' || ' assigned the' || ' (sdb_adolescent_swelling) code as a sexual' || ' cycle state' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -391,7 +391,7 @@ CREATE OR REPLACE FUNCTION follows_func () JOIN biography_data ON (biography_data.animid = roles.participant) JOIN arrivals ON (arrivals.eid = events.eid) - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND roles.participant <> 'sdb_stranger_female' AND roles.participant <> 'sdb_stranger_female2' AND roles.participant <> 'sdb_stranger_female3' @@ -410,14 +410,14 @@ CREATE OR REPLACE FUNCTION follows_func () , roles.particpant, roles.role; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'A non-mature female, a female younger than' || ' sdb_min_swelling_age' || ' sdb_min_swelling_age_units old, cannot be' || ' assigned a cycle code that indicates' || ' sexual swelling' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -468,7 +468,7 @@ CREATE OR REPLACE FUNCTION follows_func () JOIN biography_data ON (biography_data.animid = roles.participant) JOIN arrivals ON (arrivals.eid = events.eid) - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND roles.participant <> 'sdb_stranger_female' AND roles.participant <> 'sdb_stranger_female2' AND roles.participant <> 'sdb_stranger_female3' @@ -488,14 +488,14 @@ CREATE OR REPLACE FUNCTION follows_func () , roles.particpant, roles.role; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'A female older than' || ' sdb_max_swelling_age' || ' sdb_max_swelling_age_units old, cannot be' || ' assigned a cycle code that indicates' || ' sexual swelling' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -539,15 +539,15 @@ CREATE OR REPLACE FUNCTION follows_func () FROM events JOIN roles ON (roles.eid = events.eid) - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND events.behavior = 'sdb_food' AND roles.participant <> NEW.focal; IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'The individual eating must the the focal' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -588,7 +588,7 @@ CREATE OR REPLACE FUNCTION follows_func () BEGIN -- There cannot be a LOCATIONS_B row with the same Focal and Date - -- as the FOLLOWS row + -- as the WATCHES row SELECT locations_b.lbid, locations_b.time, locations_b.x, locations_b.y , locations_b.elevation, locations_b.mapseq , locations_b.meterstonextmapseq, locations_b.commid @@ -606,7 +606,7 @@ CREATE OR REPLACE FUNCTION follows_func () RAISE EXCEPTION integrity_constraint_violation USING MESSAGE = 'Error on ' || TG_OP || ' of LOCATIONS_B' , DETAIL = 'A LOCATIONS_B row cannot exist with the that shares' - || ' Focal and Date values with a FOLLOWS row, but' + || ' Focal and Date values with a WATCHES row, but' || ' such a row exists' || ': Key (LOCATIONS_B.LBID) = (' || a_lbid @@ -646,14 +646,14 @@ CREATE OR REPLACE FUNCTION follows_func () $$; -RAISE INFO 'follows_insert_commit_func'; -CREATE OR REPLACE FUNCTION follows_insert_commit_func () +RAISE INFO 'watches_insert_commit_func'; +CREATE OR REPLACE FUNCTION watches_insert_commit_func () RETURNS trigger LANGUAGE plpgsql sdb_function_set_search_path AS $$ BEGIN - -- Function for follows insert trigger fired on transaction commit + -- Function for watches insert trigger fired on transaction commit -- -- AGPL_notice(` --', `2025', `The Meme Factory, Inc., www.karlpinc.com') @@ -661,14 +661,14 @@ CREATE OR REPLACE FUNCTION follows_insert_commit_func () -- A row must exist on FOLLOW_OBSERVERS PERFORM 1 FROM follow_observers - WHERE follow_observers.fid = NEW.fid; + WHERE follow_observers.wid = NEW.wid; IF NOT FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on INSERT of FOLLOWS' - , DETAIL = 'A row on FOLLOWS must have a related row on' + MESSAGE = 'Error on INSERT of WATCHES' + , DETAIL = 'A row on WATCHES must have a related row on' || ' FOLLOW_OBSERVERS' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -694,7 +694,7 @@ CREATE OR REPLACE FUNCTION follows_insert_commit_func () SELECT events.eid, events.behavior, events.start, events.stop INTO a_eid , a_behavior , a_start , a_stop FROM events - WHERE events.fid = NEW.fid + WHERE events.wid = NEW.wid AND events.behavior = 'sdb_grooming' AND NOT EXISTS (SELECT 1 @@ -705,13 +705,13 @@ CREATE OR REPLACE FUNCTION follows_insert_commit_func () OR roles.role = 'sdb_actee')); IF FOUND THEN RAISE EXCEPTION integrity_constraint_violation USING - MESSAGE = 'Error on UPDATE of FOLLOWS' + MESSAGE = 'Error on UPDATE of WATCHES' , DETAIL = 'One of the individuals involved in the grooming event' || ' event must be the focal, who must be either the' || ' individual doing the grooming or the individual' || ' being groomed' - || ': Key (FID) = (' - || NEW.fid + || ': Key (WID) = (' + || NEW.wid || '), Value (Focal) = (' || NEW.focal || '), Value (Date) = (' @@ -733,16 +733,16 @@ CREATE OR REPLACE FUNCTION follows_insert_commit_func () END; $$; -RAISE INFO 'follows_trigger'; -CREATE TRIGGER follows_trigger +RAISE INFO 'watches_trigger'; +CREATE TRIGGER watches_trigger AFTER INSERT OR UPDATE - ON follows FOR EACH ROW - EXECUTE PROCEDURE follows_func(); + ON watches FOR EACH ROW + EXECUTE PROCEDURE watches_func(); -RAISE INFO 'follows_insert_commit_trigger'; -CREATE CONSTRAINT TRIGGER follows_insert_commit_trigger +RAISE INFO 'watches_insert_commit_trigger'; +CREATE CONSTRAINT TRIGGER watches_insert_commit_trigger AFTER INSERT - ON follows + ON watches DEFERRABLE INITIALLY DEFERRED FOR EACH ROW - EXECUTE PROCEDURE follows_insert_commit_func(); + EXECUTE PROCEDURE watches_insert_commit_func(); diff --git a/db/schemas/lib/triggers/drop/follows.m4 b/db/schemas/lib/triggers/drop/watches.m4 similarity index 77% rename from db/schemas/lib/triggers/drop/follows.m4 rename to db/schemas/lib/triggers/drop/watches.m4 index d430660..85a4c24 100644 --- a/db/schemas/lib/triggers/drop/follows.m4 +++ b/db/schemas/lib/triggers/drop/watches.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc. http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc. http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published by @@ -13,12 +13,12 @@ dnl dnl You should have received a copy of the GNU Affero General Public License dnl along with this program. If not, see . dnl -dnl Drop triggers for follows table +dnl Drop triggers for watches table dnl dnl Karl O. Pinc dnl m4 includes include(`copyright.m4')dnl -DROP FUNCTION IF EXISTS follows_func() CASCADE; -DROP FUNCTION IF EXISTS follows_insert_commit_func() CASCADE; +DROP FUNCTION IF EXISTS watches_func() CASCADE; +DROP FUNCTION IF EXISTS watches_insert_commit_func() CASCADE; diff --git a/db/schemas/sokwedb/functions/create/build_arrivals_seq.m4 b/db/schemas/sokwedb/functions/create/build_arrivals_seq.m4 index 9e6066e..4bb8034 100644 --- a/db/schemas/sokwedb/functions/create/build_arrivals_seq.m4 +++ b/db/schemas/sokwedb/functions/create/build_arrivals_seq.m4 @@ -50,16 +50,16 @@ CREATE OR REPLACE FUNCTION build_arrivals_seq() -- in the automatic ARRIVALS.Seq computations. DECLARE - a_fid follows.fid%TYPE; + a_wid watches.wid%TYPE; cnt INT := 0; a_result INT := 0; BEGIN - FOR a_fid IN - SELECT follows.fid - FROM follows + FOR a_wid IN + SELECT watches.wid + FROM watches LOOP - SELECT build_arrivals_seq(a_fid) + SELECT build_arrivals_seq(a_wid) INTO a_result; cnt := cnt + a_result; END LOOP; @@ -69,7 +69,7 @@ CREATE OR REPLACE FUNCTION build_arrivals_seq() $$; -CREATE OR REPLACE FUNCTION build_arrivals_seq(a_fid INT) +CREATE OR REPLACE FUNCTION build_arrivals_seq(a_wid INT) RETURNS INT LANGUAGE plpgsql VOLATILE @@ -83,10 +83,10 @@ CREATE OR REPLACE FUNCTION build_arrivals_seq(a_fid INT) -- -- AGPL_notice(` --', `2026', `Karl O. Pinc ') -- - -- Syntax: build_arrivals_seq(fid) + -- Syntax: build_arrivals_seq(wid) -- -- Input: - -- fid The FOLLOWS.FID of the follow for which ARRIVALS.Seq should + -- wid The WATCHES.WID of the follow for which ARRIVALS.Seq should -- be re-built. -- -- Returns: @@ -105,7 +105,7 @@ CREATE OR REPLACE FUNCTION build_arrivals_seq(a_fid INT) SELECT events.eid FROM events JOIN roles ON (roles.eid = events.eid) - WHERE events.fid = a_fid + WHERE events.wid = a_wid AND events.behavior = 'sdb_arrival' ORDER BY roles.participant , events.start, events.stop, events.eid -- Tiebreakers diff --git a/db/schemas/sokwedb/indexes/Makefile b/db/schemas/sokwedb/indexes/Makefile index 66ead0a..659d22f 100644 --- a/db/schemas/sokwedb/indexes/Makefile +++ b/db/schemas/sokwedb/indexes/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 2023 The Meme Factory, Inc. http://www.karlpinc.com/ +# Copyright (C) 2023, 2026 The Meme Factory, Inc. http://www.karlpinc.com/ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -20,7 +20,7 @@ # This determines the order in which the indexes are put into the database. # This is not really important but is needed for other types of db objects. ORDER := biography_data biography_log comm_membs comm_memb_log \ - follows follow_observers follow_studies events roles arrivals \ + watches follow_observers follow_studies events roles arrivals \ swelling_sources swelling_states aggression_event_log sightings \ aggressions food_events groomings attendance \ arrivals_a species_present repro_states locations_b diff --git a/db/schemas/sokwedb/indexes/create/events.m4 b/db/schemas/sokwedb/indexes/create/events.m4 index 040ace5..d5e5d94 100644 --- a/db/schemas/sokwedb/indexes/create/events.m4 +++ b/db/schemas/sokwedb/indexes/create/events.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -21,9 +21,9 @@ include(`copyright.m4')dnl include(`constants.m4')dnl include(`indexmacros.m4')dnl -CREATE INDEX IF NOT EXISTS events_fid ON events - (fid) - WHERE fid IS NOT NULL; +CREATE INDEX IF NOT EXISTS events_wid ON events + (wid) + WHERE wid IS NOT NULL; CREATE INDEX IF NOT EXISTS events_atid ON events (atid) WHERE atid IS NOT NULL; @@ -36,7 +36,7 @@ CREATE INDEX IF NOT EXISTS events_stop ON events -- If we felt like it, we could create a covering index to support -- arrival event sequencing. But it does not seem worth doing. --- CREATE INDEX IF NOT EXISTS events_fid_start ON events --- (fid, start) --- WHERE fid IS NOT NULL +-- CREATE INDEX IF NOT EXISTS events_wid_start ON events +-- (wid, start) +-- WHERE wid IS NOT NULL -- AND behavior = 'sdb_arrival'; diff --git a/db/schemas/sokwedb/indexes/create/follow_observers.m4 b/db/schemas/sokwedb/indexes/create/follow_observers.m4 index 383640d..944b243 100644 --- a/db/schemas/sokwedb/indexes/create/follow_observers.m4 +++ b/db/schemas/sokwedb/indexes/create/follow_observers.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -21,8 +21,8 @@ include(`copyright.m4')dnl include(`constants.m4')dnl include(`indexmacros.m4')dnl -CREATE INDEX IF NOT EXISTS follow_observers_fid ON follow_observers - (fid); +CREATE INDEX IF NOT EXISTS follow_observers_wid ON follow_observers + (wid); CREATE INDEX IF NOT EXISTS follow_observers_obs_brec ON follow_observers (obs_brec); CREATE INDEX IF NOT EXISTS follow_observers_obs_tiki ON follow_observers diff --git a/db/schemas/sokwedb/indexes/create/follow_studies.m4 b/db/schemas/sokwedb/indexes/create/follow_studies.m4 index 670b8dc..8770e42 100644 --- a/db/schemas/sokwedb/indexes/create/follow_studies.m4 +++ b/db/schemas/sokwedb/indexes/create/follow_studies.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -21,8 +21,8 @@ include(`copyright.m4')dnl include(`constants.m4')dnl include(`indexmacros.m4')dnl -CREATE INDEX IF NOT EXISTS follow_studies_fid ON follow_studies - (fid); +CREATE INDEX IF NOT EXISTS follow_studies_wid ON follow_studies + (wid); CREATE INDEX IF NOT EXISTS follow_studies_code ON follow_studies (code); diff --git a/db/schemas/sokwedb/indexes/create/locations_b.m4 b/db/schemas/sokwedb/indexes/create/locations_b.m4 index a56ebf8..99b89ab 100644 --- a/db/schemas/sokwedb/indexes/create/locations_b.m4 +++ b/db/schemas/sokwedb/indexes/create/locations_b.m4 @@ -30,14 +30,14 @@ CREATE UNIQUE INDEX IF NOT EXISTS AND focal IS NOT NULL; CREATE UNIQUE INDEX IF NOT EXISTS - "On LOCATIONS_B, FID + Time must be unique" + "On LOCATIONS_B, WID + Time must be unique" ON locations_b - (fid, time) - WHERE fid IS NOT NULL; + (wid, time) + WHERE wid IS NOT NULL; -CREATE INDEX IF NOT EXISTS locations_b_fid ON locations_b - (fid) - WHERE fid IS NOT NULL; +CREATE INDEX IF NOT EXISTS locations_b_wid ON locations_b + (wid) + WHERE wid IS NOT NULL; CREATE INDEX IF NOT EXISTS locations_b_focal ON locations_b (focal) WHERE focal IS NOT NULL; diff --git a/db/schemas/sokwedb/indexes/create/follows.m4 b/db/schemas/sokwedb/indexes/create/watches.m4 similarity index 85% rename from db/schemas/sokwedb/indexes/create/follows.m4 rename to db/schemas/sokwedb/indexes/create/watches.m4 index 7d00ae2..35565e3 100644 --- a/db/schemas/sokwedb/indexes/create/follows.m4 +++ b/db/schemas/sokwedb/indexes/create/watches.m4 @@ -22,11 +22,11 @@ include(`constants.m4')dnl include(`indexmacros.m4')dnl CREATE UNIQUE INDEX IF NOT EXISTS - "On FOLLOWS, Date + Focal must be unique" - ON follows + "On WATCHES, Date + Focal must be unique" + ON watches (date, focal); -CREATE INDEX IF NOT EXISTS follows_focal ON follows +CREATE INDEX IF NOT EXISTS watches_focal ON watches (focal); -CREATE INDEX IF NOT EXISTS follows_commid ON follows +CREATE INDEX IF NOT EXISTS watches_commid ON watches (commid); diff --git a/db/schemas/sokwedb/indexes/drop/events.m4 b/db/schemas/sokwedb/indexes/drop/events.m4 index 6143c34..8c583b5 100644 --- a/db/schemas/sokwedb/indexes/drop/events.m4 +++ b/db/schemas/sokwedb/indexes/drop/events.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -22,7 +22,7 @@ include(`constants.m4')dnl include(`indexmacros.m4')dnl -DROP INDEX IF EXISTS events_fid; +DROP INDEX IF EXISTS events_wid; DROP INDEX IF EXISTS events_atid; DROP INDEX IF EXISTS events_behavior; DROP INDEX IF EXISTS events_start; diff --git a/db/schemas/sokwedb/indexes/drop/follow_observers.m4 b/db/schemas/sokwedb/indexes/drop/follow_observers.m4 index c0889bb..c7d4204 100644 --- a/db/schemas/sokwedb/indexes/drop/follow_observers.m4 +++ b/db/schemas/sokwedb/indexes/drop/follow_observers.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -22,6 +22,6 @@ include(`constants.m4')dnl include(`indexmacros.m4')dnl -DROP INDEX IF EXISTS follow_observers_fid; +DROP INDEX IF EXISTS follow_observers_wid; DROP INDEX IF EXISTS follow_observers_obs_brec; DROP INDEX IF EXISTS follow_observers_obs_tiki; diff --git a/db/schemas/sokwedb/indexes/drop/follow_studies.m4 b/db/schemas/sokwedb/indexes/drop/follow_studies.m4 index 498dad4..e9c60cc 100644 --- a/db/schemas/sokwedb/indexes/drop/follow_studies.m4 +++ b/db/schemas/sokwedb/indexes/drop/follow_studies.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -22,6 +22,6 @@ include(`constants.m4')dnl include(`indexmacros.m4')dnl -DROP INDEX IF EXISTS follow_studies_fid; +DROP INDEX IF EXISTS follow_studies_wid; DROP INDEX IF EXISTS follow_studies_code; diff --git a/db/schemas/sokwedb/indexes/drop/locations_b.m4 b/db/schemas/sokwedb/indexes/drop/locations_b.m4 index 1315040..1f5b3e1 100644 --- a/db/schemas/sokwedb/indexes/drop/locations_b.m4 +++ b/db/schemas/sokwedb/indexes/drop/locations_b.m4 @@ -25,9 +25,9 @@ include(`indexmacros.m4')dnl DROP INDEX IF EXISTS "On LOCATIONS_B, Date + Focal + Time must be unique"; DROP INDEX IF EXISTS - "On LOCATIONS_B, FID + Time must be unique"; + "On LOCATIONS_B, WID + Time must be unique"; -DROP INDEX IF EXISTS locations_b_fid; +DROP INDEX IF EXISTS locations_b_wid; DROP INDEX IF EXISTS locations_b_focal; DROP INDEX IF EXISTS locations_b_x; DROP INDEX IF EXISTS locations_b_y; diff --git a/db/schemas/sokwedb/indexes/drop/follows.m4 b/db/schemas/sokwedb/indexes/drop/watches.m4 similarity index 88% rename from db/schemas/sokwedb/indexes/drop/follows.m4 rename to db/schemas/sokwedb/indexes/drop/watches.m4 index aa4619b..6ff0f31 100644 --- a/db/schemas/sokwedb/indexes/drop/follows.m4 +++ b/db/schemas/sokwedb/indexes/drop/watches.m4 @@ -23,7 +23,7 @@ include(`indexmacros.m4')dnl DROP INDEX IF EXISTS - "On FOLLOWS, Date + Focal must be unique"; + "On WATCHES, Date + Focal must be unique"; -DROP INDEX IF EXISTS follows_focal; -DROP INDEX IF EXISTS follows_commid; +DROP INDEX IF EXISTS watches_focal; +DROP INDEX IF EXISTS watches_commid; diff --git a/db/schemas/sokwedb/tables/Makefile b/db/schemas/sokwedb/tables/Makefile index d2f771e..6445706 100644 --- a/db/schemas/sokwedb/tables/Makefile +++ b/db/schemas/sokwedb/tables/Makefile @@ -27,7 +27,7 @@ ORDER := biography_data \ comm_membs \ comm_memb_log \ sightings \ - follows \ + watches \ follow_observers \ follow_studies \ attendance \ diff --git a/db/schemas/sokwedb/tables/create/events.m4 b/db/schemas/sokwedb/tables/create/events.m4 index ba45ce8..3ad6215 100644 --- a/db/schemas/sokwedb/tables/create/events.m4 +++ b/db/schemas/sokwedb/tables/create/events.m4 @@ -30,13 +30,13 @@ dnl Syntax: _pair_behavior_source(behavior, source) dnl dnl Input: dnl behavior An EVENTS.Behavior value -dnl source Either FID, for follow behaviors, or AtID for feeding +dnl source Either WID, for follow behaviors, or AtID for feeding dnl station attendance behaviors. dnl dnl Remarks: dnl This macro exists because there is a 63 character limit on the dnl constraint names. All the behavior codes won't fit into a single -dnl constraint name or we'd have a single constraint for FID and +dnl constraint name or we'd have a single constraint for WID and dnl another for AtID. The constraint name is used to tell the end-user dnl what the problem is. So "cheat" and use separate constraints. dnl (This is simpler to maintain in any case, and we don't care about @@ -85,8 +85,8 @@ changequote(`,')dnl See above CREATE TABLE events ( key_column(`EVENTS', `EID', INTEGER) - ,fid INTEGER - REFERENCES follows + ,wid INTEGER + REFERENCES watches ,atid INTEGER REFERENCES attendance ,behavior TEXT NOT NULL @@ -116,20 +116,20 @@ CREATE TABLE events ( CONSTRAINT "Start cannot be after Stop" CHECK (start <= stop) - null_xor_null(`FID', `AtID') + null_xor_null(`WID', `AtID') _point_behavior_time(`sdb_aggression') _point_behavior_time(`sdb_groom_scan') _point_behavior_time(`sdb_groom_scan_a') _point_behavior_time(`sdb_pantgrunt') - _pair_behavior_source(`sdb_aggression', `FID') - _pair_behavior_source(`sdb_arrival', `FID') - _pair_behavior_source(`sdb_food', `FID') - _pair_behavior_source(`sdb_grooming', `FID') - _pair_behavior_source(`sdb_groom_scan', `FID') - _pair_behavior_source(`sdb_other_species', `FID') - _pair_behavior_source(`sdb_pantgrunt', `FID') + _pair_behavior_source(`sdb_aggression', `WID') + _pair_behavior_source(`sdb_arrival', `WID') + _pair_behavior_source(`sdb_food', `WID') + _pair_behavior_source(`sdb_grooming', `WID') + _pair_behavior_source(`sdb_groom_scan', `WID') + _pair_behavior_source(`sdb_other_species', `WID') + _pair_behavior_source(`sdb_pantgrunt', `WID') _pair_behavior_source(`sdb_arrival_a', `AtID') _pair_behavior_source(`sdb_groom_scan_a', `AtID') diff --git a/db/schemas/sokwedb/tables/create/follow_observers.m4 b/db/schemas/sokwedb/tables/create/follow_observers.m4 index a7b4738..96cd21c 100644 --- a/db/schemas/sokwedb/tables/create/follow_observers.m4 +++ b/db/schemas/sokwedb/tables/create/follow_observers.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -25,8 +25,8 @@ dnl CREATE TABLE follow_observers ( key_column(`FOLLOW_OBSERVERS', `FOID', INTEGER) - ,fid INTEGER NOT NULL - REFERENCES follows + ,wid INTEGER NOT NULL + REFERENCES watches ,period TEXT NOT NULL REFERENCES obs_periods ,obs_brec TEXT NOT NULL diff --git a/db/schemas/sokwedb/tables/create/follow_studies.m4 b/db/schemas/sokwedb/tables/create/follow_studies.m4 index 7e0b685..38f3747 100644 --- a/db/schemas/sokwedb/tables/create/follow_studies.m4 +++ b/db/schemas/sokwedb/tables/create/follow_studies.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc., http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published @@ -25,8 +25,8 @@ dnl CREATE TABLE follow_studies ( key_column(`FOLLOW_STUDIES', `FSID', INTEGER) - ,fid INTEGER NOT NULL - REFERENCES follows + ,wid INTEGER NOT NULL + REFERENCES watches ,code TEXT NOT NULL REFERENCES studies ); diff --git a/db/schemas/sokwedb/tables/create/locations_b.m4 b/db/schemas/sokwedb/tables/create/locations_b.m4 index f00c7df..9595a7e 100644 --- a/db/schemas/sokwedb/tables/create/locations_b.m4 +++ b/db/schemas/sokwedb/tables/create/locations_b.m4 @@ -25,8 +25,8 @@ include(`grants.m4')dnl CREATE TABLE locations_b ( key_column(`LOCATIONS_B', `LBID', INTEGER) - ,fid INTEGER - REFERENCES follows + ,wid INTEGER + REFERENCES watches ,animid_type_column(`focal', `Focal', `NULL') ,date DATE NOT NULL CONSTRAINT "Date cannot be before sdb_min_follow_date" @@ -70,8 +70,8 @@ CREATE TABLE locations_b ( ,entered TEXT NOT NULL REFERENCES people - null_xor_null(`Focal', `FID') - null_xor_null(`Date', `FID') + null_xor_null(`Focal', `WID') + null_xor_null(`Date', `WID') null_iff_null(`Date', `Focal') ); diff --git a/db/schemas/sokwedb/tables/create/follows.m4 b/db/schemas/sokwedb/tables/create/watches.m4 similarity index 91% rename from db/schemas/sokwedb/tables/create/follows.m4 rename to db/schemas/sokwedb/tables/create/watches.m4 index 3eea529..18dd64d 100644 --- a/db/schemas/sokwedb/tables/create/follows.m4 +++ b/db/schemas/sokwedb/tables/create/watches.m4 @@ -40,16 +40,16 @@ define({birth_constraint}, {dnl changequote(`,') -CREATE TABLE follows ( - key_column(`FOLLOWS', `FID', INTEGER) +CREATE TABLE watches ( + key_column(`WATCHES', `WID', INTEGER) ,animid_type_column(`focal', `Focal', `NOT NULL') ,commid TEXT NOT NULL REFERENCES comm_ids ,date DATE NOT NULL - CONSTRAINT "The FOLLOWS.Date must not be before sdb_min_follow_date" + CONSTRAINT "The WATCHES.Date must not be before sdb_min_follow_date" CHECK(date >= 'sdb_min_follow_date') ,notes TEXT NOT NULL notonlyspaces_check(`Notes') ); -grant_priv(`FOLLOWS') +grant_priv(`WATCHES') diff --git a/doc/src/epilog.inc.m4 b/doc/src/epilog.inc.m4 index ec264fa..63b3bd4 100644 --- a/doc/src/epilog.inc.m4 +++ b/doc/src/epilog.inc.m4 @@ -325,8 +325,8 @@ sdb_generated_rst()dnl .. |EVENTS| replace:: :ref:`EVENTS ` .. |EVENTS.EID| replace:: :ref:`EID ` -.. |EVENTS.FID| replace:: - :ref:`FID ` +.. |EVENTS.WID| replace:: + :ref:`WID ` .. |EVENTS.AtID| replace:: :ref:`AtID ` .. |EVENTS.BEHAVIOR| replace:: @@ -365,23 +365,23 @@ sdb_generated_rst()dnl .. |FOOD_PARTS.Part| replace:: :ref:`Part ` -.. |FOLLOWS| replace:: :ref:`FOLLOWS ` -.. |FOLLOWS.FID| replace:: - :ref:`FID ` -.. |FOLLOWS.Focal| replace:: - :ref:`Focal ` -.. |FOLLOWS.CommID| replace:: - :ref:`CommID ` -.. |FOLLOWS.Notes| replace:: - :ref:`Notes ` -.. |FOLLOWS.Date| replace:: - :ref:`Date ` +.. |WATCHES| replace:: :ref:`WATCHES ` +.. |WATCHES.WID| replace:: + :ref:`WID ` +.. |WATCHES.Focal| replace:: + :ref:`Focal ` +.. |WATCHES.CommID| replace:: + :ref:`CommID ` +.. |WATCHES.Notes| replace:: + :ref:`Notes ` +.. |WATCHES.Date| replace:: + :ref:`Date ` .. |FOLLOW_OBSERVERS| replace:: :ref:`FOLLOW_OBSERVERS ` .. |FOLLOW_OBSERVERS.FOID| replace:: :ref:`FOID ` -.. |FOLLOW_OBSERVERS.FID| replace:: - :ref:`FID ` +.. |FOLLOW_OBSERVERS.WID| replace:: + :ref:`WID ` .. |FOLLOW_OBSERVERS.Period| replace:: :ref:`Period ` .. |FOLLOW_OBSERVERS.OBS_BRec| replace:: @@ -392,8 +392,8 @@ sdb_generated_rst()dnl .. |FOLLOW_STUIDES| replace:: :ref:`FOLLOW_STUDIES ` .. |FOLLOW_STUDIES.FSID| replace:: :ref:`FSID ` -.. |FOLLOW_STUDIES.FID| replace:: - :ref:`FID ` +.. |FOLLOW_STUDIES.WID| replace:: + :ref:`WID ` .. |FOLLOW_STUDIES.Code| replace:: :ref:`Code ` @@ -430,8 +430,8 @@ sdb_generated_rst()dnl .. |LOCATIONS_B| replace:: :ref:`LOCATIONS_B ` .. |LOCATIONS_B.LBID| replace:: :ref:`LBID ` -.. |LOCATIONS_B.FID| replace:: - :ref:`FID ` +.. |LOCATIONS_B.WID| replace:: + :ref:`WID ` .. |LOCATIONS_B.Focal| replace:: :ref:`Focal ` .. |LOCATIONS_B.Date| replace:: diff --git a/doc/src/functions/build_arrivals_seq.m4 b/doc/src/functions/build_arrivals_seq.m4 index 13a82cc..41999ed 100644 --- a/doc/src/functions/build_arrivals_seq.m4 +++ b/doc/src/functions/build_arrivals_seq.m4 @@ -31,15 +31,15 @@ Synopsis :: build_arrivals_seq() INT - build_arrivals_seq(fid INT) INT + build_arrivals_seq(wid INT) INT Input ````` -fid +wid ''' -A |FOLLOWS|.\ |FOLLOWS.FID| value, designating the follow which is to +A |WATCHES|.\ |WATCHES.WID| value, designating the follow which is to have its |ARRIVALS|.\ |ARRIVALS.Seq| values recomputed. Description @@ -52,7 +52,7 @@ Description |build_arrivals_seq_summary| When this function is called without an argument, it re-computes all the |ARRIVALS|.\ |ARRIVALS.Seq| values. -When called with a |FOLLOWS|.\ |FOLLOWS.FID| value, it re-computes the +When called with a |WATCHES|.\ |WATCHES.WID| value, it re-computes the the |ARRIVALS|.\ |ARRIVALS.Seq| values of the given follow. The function returns the number of rows processed, regardless of diff --git a/doc/src/tables.m4 b/doc/src/tables.m4 index 16fa0be..b481f87 100644 --- a/doc/src/tables.m4 +++ b/doc/src/tables.m4 @@ -43,7 +43,6 @@ and are therefore the result of at least a rudimentary analytical process. tables/comm_memb_log.rst tables/swelling_sources.rst tables/events.rst - tables/follows.rst tables/follow_observers.rst tables/follow_studies.rst tables/food_events.rst @@ -55,3 +54,4 @@ and are therefore the result of at least a rudimentary analytical process. tables/roles.rst tables/non_brec_sighting_sources.rst tables/species_present.rst + tables/watches.rst diff --git a/doc/src/tables/aggressions.m4 b/doc/src/tables/aggressions.m4 index fc8cbf1..aee953f 100644 --- a/doc/src/tables/aggressions.m4 +++ b/doc/src/tables/aggressions.m4 @@ -58,7 +58,7 @@ supplies information on the individuals involved. The system will generate a warning if the community of the follow is not the community associated with the aggression event. This means, if the AGGRESSIONS.\ |AGGRESSIONS.CommID| is not the -|FOLLOWS|.\ |FOLLOWS.CommID| of the follow. +|WATCHES|.\ |WATCHES.CommID| of the follow. For further information, including additional data integrity rules, see the documentation of the :ref:`EVENTS ` @@ -305,7 +305,7 @@ The |COMM_IDS|.\ |COMM_IDS.CommID| of the of the focal. .. note:: This is not the canonical source of information on the focal's community at the time of observation or :ref:`the community under - observation when the data was collected `. + observation when the data was collected `. It may, in fact, differ from the community recorded elsewhere. |notnull| diff --git a/doc/src/tables/events.m4 b/doc/src/tables/events.m4 index 443487c..9e7b9ba 100644 --- a/doc/src/tables/events.m4 +++ b/doc/src/tables/events.m4 @@ -35,7 +35,7 @@ EVENTS Events are either related to a follow or related to a record of attendance. -This means that either the |EVENTS.FID| or the |EVENTS.AtID| column +This means that either the |EVENTS.WID| or the |EVENTS.AtID| column must be |null|, and one of these columns must not be |null|. Whether an event is related to a follow or to an attendance record is @@ -112,7 +112,7 @@ The following table lists these rules and implications: ``sdb_aggression`` (Aggression) The EVENTS row must be associated with a follow. - This means the |EVENTS.FID| column must not be |null|. + This means the |EVENTS.WID| column must not be |null|. A related row should exist on |AGGRESSIONS|; there should be a row on |AGGRESSIONS| with an |AGGRESSIONS|.\ |AGGRESSIONS.EID| value of @@ -194,7 +194,7 @@ The following table lists these rules and implications: ``sdb_arrival`` (Arrival) The EVENTS row must be associated with a follow. - This means the |EVENTS.FID| column must not be |null|. + This means the |EVENTS.WID| column must not be |null|. A related row should exist on |ARRIVALS|; there should be a row on |ARRIVALS| with an |ARRIVALS|.\ |ARRIVALS.EID| value of the event's @@ -219,7 +219,7 @@ The following table lists these rules and implications: ``sdb_food`` (Food) The EVENTS row must be associated with a follow. - This means the |EVENTS.FID| column must not be |null|. + This means the |EVENTS.WID| column must not be |null|. A related row should exist on |FOOD_EVENTS|; there should be a row on |FOOD_EVENTS| with a |FOOD_EVENTS|.\ |FOOD_EVENTS.EID| value of @@ -239,8 +239,8 @@ The following table lists these rules and implications: The individual consuming the food must be the the focal of the follow. This means that the |ROLES| row related to the event must have a - |ROLES|.\ |ROLES.Participant| value equal to the |FOLLOWS|.\ - |FOLLOWS.Focal| of the follow that is related to the food event. + |ROLES|.\ |ROLES.Participant| value equal to the |WATCHES|.\ + |WATCHES.Focal| of the follow that is related to the food event. The EVENTS.\ |EVENTS.Start| column contains the time the food bout began. @@ -253,7 +253,7 @@ The following table lists these rules and implications: ``sdb_grooming`` (Grooming) The EVENTS row must be associated with a follow. - This means the |EVENTS.FID| column must not be |null|. + This means the |EVENTS.WID| column must not be |null|. A related row should exist on |GROOMINGS|; there should be a row on |GROOMINGS| with a |GROOMINGS|.\ |GROOMINGS.EID| value of the @@ -285,7 +285,7 @@ The following table lists these rules and implications: This means that on of the the |ROLES| rows related to the event must have a |ROLES|.\ |ROLES.Role| value of either ``sdb_actor`` or ``sdb_actee``, and have a |ROLES|.\ - |ROLES.Participant| value equal to the |FOLLOWS|.\ |FOLLOWS.Focal| + |ROLES.Participant| value equal to the |WATCHES|.\ |WATCHES.Focal| of the follow that is related to the grooming event. For grooming events, the |EVENTS|.\ |EVENTS.Certainty| column @@ -299,7 +299,7 @@ The following table lists these rules and implications: ``sdb_groom_scan`` (SCAN interval Groomings) The EVENTS row must be associated with a follow. - This means the |EVENTS.FID| column must not be |null|. + This means the |EVENTS.WID| column must not be |null|. A related row should exist on |GROOM_SCANS_B|; there should be a row on |GROOM_SCANS_B| with an |GROOM_SCANS_B|.\ |GROOM_SCANS_B.EID| value of @@ -348,7 +348,7 @@ The following table lists these rules and implications: ``sdb_other_species`` (Other Species) The EVENTS row must be associated with a follow. - This means the |EVENTS.FID| column must not be |null|. + This means the |EVENTS.WID| column must not be |null|. A related row should exist on either |SPECIES_PRESENT| or on |HUMANS|. @@ -371,7 +371,7 @@ The following table lists these rules and implications: ``sdb_pantgrunt`` (Pantgrunt) The EVENTS row must be associated with a follow. - This means the |EVENTS.FID| column must not be |null|. + This means the |EVENTS.WID| column must not be |null|. A related row should exist on |PANTGRUNTS|; there should be a row on |PANTGRUNTS| with a |PANTGRUNTS|.\ |PANTGRUNTS.EID| value of the @@ -426,16 +426,16 @@ EID (Event ID) |EVENTS.EID_summary| |notnull| -.. _EVENTS.FID: +.. _EVENTS.WID: -FID (Follow IDentifier) -``````````````````````` +WID (Watch period IDentifier) +````````````````````````````` -.. |EVENTS.FID_summary| replace:: - The |FOLLOWS|.\ |FOLLOWS.FID| that identifies the follow during +.. |EVENTS.WID_summary| replace:: + The |WATCHES|.\ |WATCHES.WID| that identifies the follow during which the event was recorded. -|EVENTS.FID_summary| |cannot_change| +|EVENTS.WID_summary| |cannot_change| .. _EVENTS.AtID: diff --git a/doc/src/tables/follow_observers.m4 b/doc/src/tables/follow_observers.m4 index 3b8dfe8..01ad65f 100644 --- a/doc/src/tables/follow_observers.m4 +++ b/doc/src/tables/follow_observers.m4 @@ -37,11 +37,11 @@ observer from being the same observer as the Tiki observer. More than two observers may be related to a follow by creating multiple FOLLOW_OBSERVERS rows that are related to a single row in the -|FOLLOWS| table. +|WATCHES| table. The system will generate a warning if there are multiple FOLLOW_OBSERVERS rows having the same |FOLLOW_OBSERVERS.Period|, -related to a single row in |FOLLOWS|. +related to a single row in |WATCHES|. .. contents:: :depth: 2 @@ -58,16 +58,16 @@ FOID (Follow Observers ID) |FOLLOW_OBSERVERS.FOID_summary| |notnull| -.. _FOLLOW_OBSERVERS.FID: +.. _FOLLOW_OBSERVERS.WID: -FID (Follow IDentifier) -``````````````````````` +WID (Watch period IDentifier) +````````````````````````````` -.. |FOLLOW_OBSERVERS.FID_summary| replace:: - The |FOLLOWS|.\ |FOLLOWS.FID| which identifies the +.. |FOLLOW_OBSERVERS.WID_summary| replace:: + The |WATCHES|.\ |WATCHES.WID| which identifies the follow which the observers participated in recording. -|FOLLOW_OBSERVERS.FID_summary| |notnull| +|FOLLOW_OBSERVERS.WID_summary| |notnull| .. _FOLLOW_OBSERVERS.Period: diff --git a/doc/src/tables/follow_studies.m4 b/doc/src/tables/follow_studies.m4 index 2d36b92..09bfb99 100644 --- a/doc/src/tables/follow_studies.m4 +++ b/doc/src/tables/follow_studies.m4 @@ -1,4 +1,4 @@ -.. Copyright (C) 2024 The Meme Factory, Inc. www.karlpinc.com +.. Copyright (C) 2024, 2026 The Meme Factory, Inc. www.karlpinc.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -44,16 +44,16 @@ FSID (Follow Studies ID) |FOLLOW_STUDIES.FSID_summary| |notnull| -.. _FOLLOW_STUDIES.FID: +.. _FOLLOW_STUDIES.WID: -FID (Follow IDentifier) -``````````````````````` +WID (Watch period IDentifier) +````````````````````````````` -.. |FOLLOW_STUDIES.FID_summary| replace:: - The |FOLLOWS|.\ |FOLLOWS.FID| which identifies the follow +.. |FOLLOW_STUDIES.WID_summary| replace:: + The |WATCHES|.\ |WATCHES.WID| which identifies the follow associated with the study. -|FOLLOW_STUDIES.FID_summary| |notnull| +|FOLLOW_STUDIES.WID_summary| |notnull| .. _FOLLOW_STUDIES.Code: diff --git a/doc/src/tables/locations_b.m4 b/doc/src/tables/locations_b.m4 index 2880db6..899bc87 100644 --- a/doc/src/tables/locations_b.m4 +++ b/doc/src/tables/locations_b.m4 @@ -27,8 +27,8 @@ LOCATIONS_B (spatial LOCATIONS from B records) .. |LOCATIONS_B_summary| replace:: Contains one row for each moment in time the spatial location of a follow's focal was recorded; even when there is no other - information on the follow when there is no |FOLLOWS| record for - the focal on the given day. + information on the follow -- when there is no |WATCHES| record typed + as a follow for the focal on the given day. |LOCATIONS_B_summary| To support recording spatial information when there is no follow @@ -39,13 +39,13 @@ There must either be a related follow row or there must be information in the |LOCATIONS_B.Focal| and |LOCATIONS_B.Date| columns, but there cannot be both. This means the the following rules are enforced: -sdb_null_xor_null(*m4[|LOCATIONS_B.Focal|]m4*, *m4[|LOCATIONS_B.FID|]m4*) -sdb_null_xor_null(*m4[|LOCATIONS_B.Date|]m4*, *m4[|LOCATIONS_B.FID|]m4*) +sdb_null_xor_null(*m4[|LOCATIONS_B.Focal|]m4*, *m4[|LOCATIONS_B.WID|]m4*) +sdb_null_xor_null(*m4[|LOCATIONS_B.Date|]m4*, *m4[|LOCATIONS_B.WID|]m4*) sdb_null_iff_null(*m4[|LOCATIONS_B.Date|]m4*, *m4[|LOCATIONS_B.Focal|]m4*) Further, follow information can be recorded in only one of SokweDB's tables, in one row. -This means that there cannot be a row on |FOLLOWS| with focal and date +This means that there cannot be a row on |WATCHES| with focal and date values that match a LOCATIONS_B row's focal and date values. (|transaction commit|) @@ -54,11 +54,11 @@ time.\ [#f1]_ This means two things. The combination of |LOCATIONS_B.Focal|, |LOCATIONS_B.Date|, and |LOCATIONS_B.Time| must be unique. -And, the combination of |LOCATIONS_B.FID| and |LOCATIONS_B.Time| must +And, the combination of |LOCATIONS_B.WID| and |LOCATIONS_B.Time| must be unique. The system will generate a warning when there is no related follow, -when the |LOCATIONS_B.FID| column is |null|. +when the |LOCATIONS_B.WID| column is |null|. The |LOCATIONS_B.Date| must be during a period when the focal individual was under study, on or after the focal's |BIOGRAPHY_DATA|.\ @@ -71,7 +71,7 @@ The system will generate a warning when a LOCATIONS_B row does not have a |ARRIVALS| related row that records the presence of the focal at the time the spatial observation occurred. This means that a warning will be generated when there is a non-|null| -|LOCATIONS_B.FID| value, but there is no related |EVENTS| row where +|LOCATIONS_B.WID| value, but there is no related |EVENTS| row where the |EVENTS.Behavior| code is ``sdb_arrival`` and the |EVENTS|.\ |EVENTS.Start| value is less than or equal to the |LOCATIONS_B.Time| value and the |EVENTS|.\ |EVENTS.Stop| value is greater than or equal @@ -100,16 +100,16 @@ LBID (spatial Location B-record ID) |LOCATIONS_B.LBID_summary| |notnull| -.. _LOCATIONS_B.FID: +.. _LOCATIONS_B.WID: -FID (Follow ID) -``````````````` +WID (Watch period ID) +````````````````````` -.. |LOCATIONS_B.FID_summary| replace:: - The |FOLLOWS|.\ |FOLLOWS.FID| that identifies the follow during +.. |LOCATIONS_B.WID_summary| replace:: + The |WATCHES|.\ |WATCHES.WID| that identifies the follow during which the spatial position of the focal was recorded. -|LOCATIONS_B.FID_summary| +|LOCATIONS_B.WID_summary| This column must be |null| when there is no information on the follow other than the recorded spatial placement of the focal. @@ -124,7 +124,7 @@ Focal (Focal animal id) focal individual. |LOCATIONS_B.Focal_summary| -This column must be |null| when there is a related |FOLLOWS| row. +This column must be |null| when there is a related |WATCHES| row. .. _LOCATIONS_B.Date: @@ -137,7 +137,7 @@ Date |LOCATIONS_B.Date_summary| This date may not be before ``sdb_min_follow_date``. -This column must be |null| when there is a related |FOLLOWS| row. +This column must be |null| when there is a related |WATCHES| row. .. _LOCATIONS_B.Time: diff --git a/doc/src/tables/pantgrunts.m4 b/doc/src/tables/pantgrunts.m4 index 11d2864..bf365ca 100644 --- a/doc/src/tables/pantgrunts.m4 +++ b/doc/src/tables/pantgrunts.m4 @@ -26,7 +26,8 @@ PANTGRUNTS .. |PANTGRUNTS_summary| replace:: Each row, taken together with the related |EVENTS| row, represents - a pantgrunt event recording during a follow. + a pantgrunt event recording during a watch period. + The watch period may be a follow. Pantgrunts are recorded as dyadic pairs. |PANTGRUNTS_summary| diff --git a/doc/src/tables/roles.m4 b/doc/src/tables/roles.m4 index 751eec1..308f183 100644 --- a/doc/src/tables/roles.m4 +++ b/doc/src/tables/roles.m4 @@ -26,20 +26,24 @@ ROLES .. |ROLES_summary| replace:: Each row represents a participant in an event that occurred. - Events occur during a follow, whether involving the focal or not, - and during attendance taking at the feeding station. + Events occur during a watch period. + The watch periods may be a follow, which may involve the focal of a + follow or not, may be attendance taking of an individual at the + feeding station, may be some variety of ad-hoc pantgrunt record, + or may be some other type of watch period. |ROLES_summary| Events may have zero or more participants involved; rows on |EVENTS| may have zero or more related rows on ROLES. Usually, there will be at least one participant. -But this is not true of events that are no more than a record of the -presence of other species sighted during a follow. +But this is not true of all events, for example events that are no +more than a record of the presence of other species sighted during a +follow. The participant in the event is required to be under study on the date of the follow, for follow related events. This means that, when the event occurs during a follow, the -|FOLLOWS|.\ |FOLLOWS.Date| related to the event must be between the +|WATCHES|.\ |WATCHES.Date| related to the event must be between the |ROLES.Participant|'s |BIOGRAPHY_DATA|.\ |BIOGRAPHY_DATA.EntryDate| and their |BIOGRAPHY_DATA|.\ |BIOGRAPHY_DATA.DepartDate|, inclusive of endpoints. diff --git a/doc/src/tables/follows.m4 b/doc/src/tables/watches.m4 similarity index 72% rename from doc/src/tables/follows.m4 rename to doc/src/tables/watches.m4 index ab4d915..4d72fb6 100644 --- a/doc/src/tables/follows.m4 +++ b/doc/src/tables/watches.m4 @@ -19,32 +19,32 @@ include(macros.m4)dnl sdb_rst_quotes(`on')dnl sdb_generated_rst()dnl -.. _FOLLOWS: +.. _WATCHES: -FOLLOWS +WATCHES ------- -.. |FOLLOWS_summary| replace:: +.. |WATCHES_summary| replace:: Each row represents a scheduled time during which observers are assigned to follow a focal individual. -|FOLLOWS_summary| A scheduled follow may or may not have any related +|WATCHES_summary| A scheduled follow may or may not have any related observations, related |EVENTS| rows. -The combination of |FOLLOWS.Focal| and |FOLLOWS.Date| must be unique. +The combination of |WATCHES.Focal| and |WATCHES.Date| must be unique. -The system will generate a warning when a FOLLOWS row does not have a +The system will generate a warning when a WATCHES row does not have a |ARRIVALS| related row that records the presence of the focal: does not have a related |EVENTS| row where the |EVENTS.Behavior| code is ``sdb_arrival``, and a |ROLES| row, related to the event, where the |ROLES|.\ |ROLES.Participant| has the same value as the follow's -|FOLLOWS.Focal| column. +|WATCHES.Focal| column. A scheduled follow must have at least one related |FOLLOW_OBSERVERS| rows, to record the observers scheduled to conduct the follow. |transaction commit| -The |FOLLOWS.Date| must be during a period when the focal individual +The |WATCHES.Date| must be during a period when the focal individual was under study, on or after the focal's |BIOGRAPHY_DATA|.\ |BIOGRAPHY_DATA.EntryDate| and on or before the focal's |BIOGRAPHY_DATA|.\ |BIOGRAPHY_DATA.DepartDate|. @@ -53,34 +53,34 @@ was under study, on or after the focal's |BIOGRAPHY_DATA|.\ :depth: 2 -.. _FOLLOWS.FID: +.. _WATCHES.WID: -FID (Follow ID) -``````````````` +WID (Watch period ID) +````````````````````` -.. |FOLLOWS.FID_summary| replace:: |idcol| +.. |WATCHES.WID_summary| replace:: |idcol| -|FOLLOWS.FID_summary| |notnull| +|WATCHES.WID_summary| |notnull| -.. _FOLLOWS.Focal: +.. _WATCHES.Focal: Focal (Focal animal id) ``````````````````````` -.. |FOLLOWS.Focal_summary| replace:: The |BIOGRAPHY_DATA|.\ +.. |WATCHES.Focal_summary| replace:: The |BIOGRAPHY_DATA|.\ |BIOGRAPHY_DATA.AnimID| identifying the individual intended to be the focal under observation for the follow. -|FOLLOWS.Focal_summary| |notnull| +|WATCHES.Focal_summary| |notnull| -.. _FOLLOWS.CommID: +.. _WATCHES.CommID: CommID `````` -.. |FOLLOWS.CommID_summary| replace:: +.. |WATCHES.CommID_summary| replace:: A code for the community the observers are associated with and intended to follow; the |COMM_IDS|.\ |COMM_IDS.CommID| of the @@ -88,29 +88,29 @@ CommID This is not necessarily the community the focal is a member of, although it usually is. -|FOLLOWS.CommID_summary| |cannot_change| |notnull| +|WATCHES.CommID_summary| |cannot_change| |notnull| -.. _FOLLOWS.Date: +.. _WATCHES.Date: Date ```` -.. |FOLLOWS.Date_summary| replace:: +.. |WATCHES.Date_summary| replace:: The date the follow was conducted. -|FOLLOWS.Date_summary| +|WATCHES.Date_summary| This date may not be before ``sdb_min_follow_date``. |notnull| -.. _FOLLOWS.Notes: +.. _WATCHES.Notes: Notes ````` -.. |FOLLOWS.Notes_summary| replace:: +.. |WATCHES.Notes_summary| replace:: Free form textual notes on the follow. -|FOLLOWS.Notes_summary| |notonlyspaces| |notnull| +|WATCHES.Notes_summary| |notonlyspaces| |notnull| -- 2.34.1