diff --git a/deployment/hasura/migrations/Aerie/11_external_events/down.sql b/deployment/hasura/migrations/Aerie/11_external_events/down.sql index 6a9f1faddf..5280dfe186 100644 --- a/deployment/hasura/migrations/Aerie/11_external_events/down.sql +++ b/deployment/hasura/migrations/Aerie/11_external_events/down.sql @@ -1,24 +1,31 @@ -- up.sql creates table and sequence, delete them -drop trigger refresh_derived_events_on_external_event on merlin.external_event; -drop trigger refresh_derived_events_on_external_source on merlin.external_source; drop trigger refresh_derived_events_on_derivation_group on merlin.derivation_group; +drop trigger refresh_derived_events_on_external_source on merlin.external_source; +drop trigger refresh_derived_events_on_external_event on merlin.external_event; drop function merlin.refresh_derived_events_on_trigger cascade; drop materialized view merlin.derived_events; + drop function merlin.subtract_later_ranges cascade; -drop trigger check_external_event_boundaries on merlin.external_event; -drop function merlin.check_external_event_boundaries cascade; + drop trigger external_source_pdg_association_delete on merlin.external_source; drop function merlin.external_source_pdg_association_delete cascade; drop trigger external_source_pdg_ack_update on merlin.external_source; drop function merlin.external_source_pdg_ack_update cascade; + drop trigger pdg_update_ack_at on merlin.plan_derivation_group; drop function merlin.pdg_update_ack_at cascade; drop table merlin.plan_derivation_group cascade; + +drop trigger check_external_event_boundaries on merlin.external_event; +drop function merlin.check_external_event_boundaries cascade; + drop trigger check_external_event_duration_is_nonnegative_trigger on merlin.external_event; drop table merlin.external_event cascade; + drop trigger external_source_type_matches_dg_on_add on merlin.external_source; drop function merlin.external_source_type_matches_dg_on_add; drop table merlin.external_source cascade; + drop table merlin.derivation_group cascade; drop table merlin.external_event_type cascade; drop table merlin.external_source_type cascade; diff --git a/deployment/hasura/migrations/Aerie/11_external_events/up.sql b/deployment/hasura/migrations/Aerie/11_external_events/up.sql index f2bf2d29ab..44dfe85c9e 100644 --- a/deployment/hasura/migrations/Aerie/11_external_events/up.sql +++ b/deployment/hasura/migrations/Aerie/11_external_events/up.sql @@ -240,6 +240,22 @@ comment on column merlin.plan_derivation_group.derivation_group_name is e'' comment on column merlin.plan_derivation_group.last_acknowledged_at is e'' 'The time at which changes to the derivation group were last acknowledged.'; +-- update last_acknowledged whenever acknowledged is set to true +create function merlin.pdg_update_ack_at() + returns trigger + language plpgsql as $$ +begin + if new.acknowledged = true then + new.last_acknowledged_at = now(); + end if; + return new; +end; +$$; + +create trigger pdg_update_ack_at +before update on merlin.plan_derivation_group + for each row execute function merlin.pdg_update_ack_at(); + -- if an external source is linked to a plan it cannot be deleted create function merlin.external_source_pdg_association_delete() returns trigger @@ -272,22 +288,6 @@ create trigger external_source_pdg_ack_update after insert on merlin.external_source for each row execute function merlin.external_source_pdg_ack_update(); --- update last_acknowledged whenever acknowledged is set to true -create function merlin.pdg_update_ack_at() - returns trigger - language plpgsql as $$ -begin - if new.acknowledged = true then - new.last_acknowledged_at = now(); - end if; - return new; -end; -$$; - -create trigger pdg_update_ack_at -before update on merlin.plan_derivation_group - for each row execute function merlin.pdg_update_ack_at(); - create function merlin.subtract_later_ranges(curr_date tstzmultirange, later_dates tstzmultirange[]) returns tstzmultirange immutable