@@ -107,45 +107,45 @@ comment on procedure merlin.validate_nonnegative_net_end_offset(_activity_id int
107107create procedure merlin .validate_nonegative_net_plan_start (_activity_id integer , _plan_id integer )
108108 security definer
109109 language plpgsql as $$
110- declare
111- net_offset interval;
112- _anchor_id integer ;
113- _start_offset interval;
114- _anchored_to_start boolean ;
115- begin
116- select anchor_id, start_offset, anchored_to_start
117- from merlin .activity_directive
118- where (id, plan_id) = (_activity_id, _plan_id)
119- into _anchor_id, _start_offset, _anchored_to_start;
120-
121- if (_start_offset < ' 0' and _anchored_to_start) then -- only need to check if anchored to start or something with a negative offset
122- with recursive anchors(activity_id, anchor_id, anchored_to_start, start_offset, total_offset) as (
123- select _activity_id, _anchor_id, _anchored_to_start, _start_offset, _start_offset
124- union
125- select ad .id , ad .anchor_id , ad .anchored_to_start , ad .start_offset , anchors .total_offset + ad .start_offset
126- from merlin .activity_directive ad, anchors
127- where anchors .anchor_id is not null -- stop at plan
128- and (ad .id , ad .plan_id ) = (anchors .anchor_id , _plan_id)
129- and anchors .anchored_to_start -- or, stop at end-time offset
130- )
131- select total_offset -- get the id of the activity that the selected activity is anchored to
132- from anchors a
133- where a .anchor_id is null
134- and a .anchored_to_start
135- limit 1
136- into net_offset;
110+ declare
111+ net_offset interval;
112+ _anchor_id integer ;
113+ _start_offset interval;
114+ _anchored_to_start boolean ;
115+ begin
116+ select anchor_id, start_offset, anchored_to_start
117+ from merlin .activity_directive
118+ where (id, plan_id) = (_activity_id, _plan_id)
119+ into _anchor_id, _start_offset, _anchored_to_start;
137120
138- if(net_offset < ' 0' ) then
139- raise notice ' Activity Directive % has a net negative offset relative to Plan Start.' , _activity_id;
121+ if (_anchored_to_start) then -- only need to check if anchored to start
122+ with recursive anchors(activity_id, anchor_id, anchored_to_start, start_offset, total_offset) as (
123+ select _activity_id, _anchor_id, _anchored_to_start, _start_offset, _start_offset
124+ union
125+ select ad .id , ad .anchor_id , ad .anchored_to_start , ad .start_offset , anchors .total_offset + ad .start_offset
126+ from merlin .activity_directive ad, anchors
127+ where anchors .anchor_id is not null -- stop at plan
128+ and (ad .id , ad .plan_id ) = (anchors .anchor_id , _plan_id)
129+ and anchors .anchored_to_start -- or, stop at end-time offset
130+ )
131+ select total_offset -- get the id of the activity that the selected activity is anchored to
132+ from anchors a
133+ where a .anchor_id is null
134+ and a .anchored_to_start
135+ limit 1
136+ into net_offset;
137+
138+ if(net_offset < ' 0' ) then
139+ raise notice ' Activity Directive % has a net negative offset relative to Plan Start.' , _activity_id;
140140
141- insert into merlin .anchor_validation_status (activity_id, plan_id, reason_invalid)
142- values (_activity_id, _plan_id, ' Activity Directive ' || _activity_id || ' has a net negative offset relative to Plan Start.' )
143- on conflict (activity_id, plan_id) do update
144- set reason_invalid = ' Activity Directive ' || excluded .activity_id || ' has a net negative offset relative to Plan Start.' ;
145- end if;
146- end if;
147- end
148- $$;
141+ insert into merlin .anchor_validation_status (activity_id, plan_id, reason_invalid)
142+ values (_activity_id, _plan_id, ' Activity Directive ' || _activity_id || ' has a net negative offset relative to Plan Start.' )
143+ on conflict (activity_id, plan_id) do update
144+ set reason_invalid = ' Activity Directive ' || excluded .activity_id || ' has a net negative offset relative to Plan Start.' ;
145+ end if;
146+ end if;
147+ end
148+ $$;
149149comment on procedure merlin .validate_nonegative_net_plan_start (_activity_id integer , _plan_id integer ) is e' '
150150 ' Returns true if the specified activity has a net negative offset from plan start. Otherwise, returns false.\n '
151151 ' If true, writes to anchor_validation_status.' ;
0 commit comments