From 11a50200047114b39c55c0d9356bb3d45a1e0548 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Fri, 2 Oct 2020 17:30:42 +0200 Subject: [PATCH] Remove old QCs when importing final shots. When final shots are inserted, updated or deleted, the corresponding QC info (which is always held in raw_shots.meta->'qc') is deleted. If applicable, it will be recreated on the next QC run. --- etc/db/schema-template.sql | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/etc/db/schema-template.sql b/etc/db/schema-template.sql index be3d8b0..723473b 100644 --- a/etc/db/schema-template.sql +++ b/etc/db/schema-template.sql @@ -122,6 +122,34 @@ All values are returned as being of type "text" and need casting before use. '; +-- +-- Name: clear_shot_qc(); Type: FUNCTION; Schema: _SURVEY__TEMPLATE_; Owner: postgres +-- + +CREATE FUNCTION _SURVEY__TEMPLATE_.clear_shot_qc() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE +pid text; +BEGIN + +-- Bail out early if there are no actual changes +IF TG_OP = 'UPDATE' AND NOT (NEW.* IS DISTINCT FROM OLD.*) THEN +RETURN NULL; +END IF; + +UPDATE raw_shots +SET meta = meta #- '{qc}' +WHERE (sequence = NEW.sequence OR sequence = OLD.sequence) +AND (point = NEW.point OR point = OLD.point); + +RETURN NULL; +END; +$$; + + +ALTER FUNCTION _SURVEY__TEMPLATE_.clear_shot_qc() OWNER TO postgres; + -- -- Name: events_timed_seq_match(); Type: FUNCTION; Schema: _SURVEY__TEMPLATE_; Owner: postgres -- @@ -1528,6 +1556,13 @@ CREATE TRIGGER events_timed_seq_match_tg AFTER INSERT OR UPDATE ON _SURVEY__TEMP CREATE TRIGGER events_timed_tg BEFORE INSERT OR UPDATE ON _SURVEY__TEMPLATE_.events_timed FOR EACH ROW EXECUTE FUNCTION _SURVEY__TEMPLATE_.assoc_tstamp(); +-- +-- Name: final_shots final_shots_qc_tg; Type: TRIGGER; Schema: _SURVEY__TEMPLATE_; Owner: postgres +-- + +CREATE TRIGGER final_shots_qc_tg AFTER INSERT OR DELETE OR UPDATE ON _SURVEY__TEMPLATE_.final_shots FOR EACH ROW EXECUTE FUNCTION _SURVEY__TEMPLATE_.clear_shot_qc(); + + -- -- Name: events_seq_labels events_seq_labels_id_fkey; Type: FK CONSTRAINT; Schema: _SURVEY__TEMPLATE_; Owner: postgres --