-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f40d75
commit 6423bde
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
deployment/hasura/migrations/Aerie/8_span_event_linkage/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-- event table revert | ||
alter table merlin.event | ||
drop column span_id; | ||
|
||
-- span table revert | ||
alter table merlin.span | ||
alter column span_id add generated by default as identity; | ||
|
||
select setval(pg_get_serial_sequence('merlin.span', 'span_id'), coalesce(max(span_id),0) + 1, false) FROM merlin.span; | ||
|
||
with conflicts as ( | ||
with subTable as ( | ||
select p.span_id, | ||
p.dataset_id, | ||
ROW_NUMBER() over(partition by p.span_id order by p.dataset_id) as rk | ||
from merlin.span p) | ||
select s.* | ||
from subTable s | ||
where s.rk > 1) | ||
update merlin.span s | ||
set span_id = nextval(pg_get_serial_sequence('merlin.span', 'span_id')) | ||
from conflicts c | ||
where (c.span_id, c.dataset_id) = (s.span_id, s.dataset_id); | ||
|
||
alter table merlin.span | ||
rename column span_id to id; | ||
|
||
alter table merlin.span | ||
alter column id set generated always; | ||
|
||
drop view merlin.simulated_activity; | ||
create view merlin.simulated_activity as | ||
( | ||
select span.id as id, | ||
sd.id as simulation_dataset_id, | ||
span.parent_id as parent_id, | ||
span.start_offset as start_offset, | ||
span.duration as duration, | ||
span.attributes as attributes, | ||
span.type as activity_type_name, | ||
(span.attributes#>>'{directiveId}')::integer as directive_id, | ||
sd.simulation_start_time + span.start_offset as start_time, | ||
sd.simulation_start_time + span.start_offset + span.duration as end_time | ||
from merlin.span span | ||
join merlin.dataset d on span.dataset_id = d.id | ||
join merlin.simulation_dataset sd on d.id = sd.dataset_id | ||
join merlin.simulation s on s.id = sd.simulation_id | ||
); | ||
|
||
call migrations.mark_migration_rolled_back('8') | ||
|
31 changes: 31 additions & 0 deletions
31
deployment/hasura/migrations/Aerie/8_span_event_linkage/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- Span Table update | ||
alter table merlin.span | ||
rename column id to span_id; | ||
|
||
alter table merlin.span | ||
alter column span_id drop identity; | ||
|
||
drop view merlin.simulated_activity; | ||
create view merlin.simulated_activity as | ||
( | ||
select span.span_id as id, | ||
sd.id as simulation_dataset_id, | ||
span.parent_id as parent_id, | ||
span.start_offset as start_offset, | ||
span.duration as duration, | ||
span.attributes as attributes, | ||
span.type as activity_type_name, | ||
(span.attributes#>>'{directiveId}')::integer as directive_id, | ||
sd.simulation_start_time + span.start_offset as start_time, | ||
sd.simulation_start_time + span.start_offset + span.duration as end_time | ||
from merlin.span span | ||
join merlin.dataset d on span.dataset_id = d.id | ||
join merlin.simulation_dataset sd on d.id = sd.dataset_id | ||
join merlin.simulation s on s.id = sd.simulation_id | ||
); | ||
|
||
-- event table update | ||
alter table merlin.event | ||
add column span_id integer; | ||
|
||
call migrations.mark_migration_applied('8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters