Skip to content

Commit

Permalink
Minor reordering of migrations
Browse files Browse the repository at this point in the history
- put `pdg_update_ack_at` next to `pdg` table def
- reorder down to match up
  • Loading branch information
Mythicaeda committed Oct 21, 2024
1 parent b95fb3b commit d07ff79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
15 changes: 11 additions & 4 deletions deployment/hasura/migrations/Aerie/11_external_events/down.sql
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
32 changes: 16 additions & 16 deletions deployment/hasura/migrations/Aerie/11_external_events/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d07ff79

Please sign in to comment.