Skip to content

Commit

Permalink
Updated constraint run migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
cohansen committed Jul 6, 2023
1 parent 60f1825 commit 8fe0b14
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
comment on column constraint_run.constraint_id is null;
comment on column constraint_run.constraint_definition is null;
comment on column constraint_run.dataset_id is null;
comment on column constraint_run.plan_id is null;
comment on column constraint_run.simulation_dataset_id is null;
comment on column constraint_run.status is null;
comment on column constraint_run.violations is null;
comment on column constraint_run.requested_by is null;
Expand All @@ -15,4 +16,4 @@ drop function constraint_check_constraint_run();
drop trigger simulation_dataset_check_constraint_run_trigger on simulation_dataset;
drop function simulation_dataset_check_constraint_run();

call migrations.mark_migration_rolled_back('18');
call migrations.mark_migration_rolled_back('20');
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ create type constraint_status as enum('resolved', 'constraint-outdated', 'simula
create table constraint_run (
constraint_id integer not null,
constraint_definition text not null,
dataset_id integer not null,
plan_id integer not null,
simulation_dataset_id integer not null,

status constraint_status not null default 'resolved',
violations jsonb null,

-- Additional Metadata
requested_by text not null default '',
requested_by text,
requested_at timestamptz not null default now(),

constraint constraint_run_to_constraint
foreign key (constraint_id)
references "constraint"
on delete cascade,
constraint constraint_run_to_simulation_dataset
foreign key (dataset_id)
foreign key (simulation_dataset_id)
references simulation_dataset
on delete cascade
on delete cascade,
constraint constraint_run_requested_by
foreign key (requested_by)
references metadata.users
on update cascade
on delete set null
);

comment on table constraint_run is e''
Expand All @@ -29,7 +35,9 @@ comment on column constraint_run.constraint_id is e''
'The constraint that we are evaluating during the run.';
comment on column constraint_run.constraint_definition is e''
'The definition of the constraint that is being checked, used to determine staleness.';
comment on column constraint_run.dataset_id is e''
comment on column constraint_run.plan_id is e''
'The plan that the constraint run is associated with.';
comment on column constraint_run.simulation_dataset_id is e''
'The simulation dataset id from when the constraint was checked, used to determine staleness.';
comment on column constraint_run.status is e''
'The current status of the constraint run.';
Expand Down Expand Up @@ -59,12 +67,12 @@ create or replace function simulation_dataset_check_constraint_run()
returns trigger
security definer
language plpgsql as $$begin
if new.simulation_id = old.simulation_id
then
update constraint_run
set status = 'simulation-outdated'
where old.dataset_id = dataset_id;
end if;
update constraint_run cr
set status = 'simulation-outdated'
from simulation s
where cr.status = 'resolved'
and s.plan_id = cr.plan_id
and s.id = new.simulation_id;
return new;
end$$;

Expand All @@ -73,4 +81,4 @@ create trigger simulation_dataset_check_constraint_run_trigger
for each row
execute function simulation_dataset_check_constraint_run();

call migrations.mark_migration_applied('18');
call migrations.mark_migration_applied('20');
1 change: 1 addition & 0 deletions merlin-server/sql/merlin/applied_migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ call migrations.mark_migration_applied('16');
call migrations.mark_migration_applied('17');
call migrations.mark_migration_applied('18');
call migrations.mark_migration_applied('19');
call migrations.mark_migration_applied('20');
9 changes: 7 additions & 2 deletions merlin-server/sql/merlin/tables/constraint_run.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ create table constraint_run (
violations jsonb null,

-- Additional Metadata
requested_by text not null default '',
requested_by text,
requested_at timestamptz not null default now(),

constraint constraint_run_to_constraint
Expand All @@ -20,7 +20,12 @@ create table constraint_run (
constraint constraint_run_to_simulation_dataset
foreign key (simulation_dataset_id)
references simulation_dataset
on delete cascade
on delete cascade,
constraint constraint_run_requested_by
foreign key (requested_by)
references metadata.users
on update cascade
on delete set null
);

comment on table constraint_run is e''
Expand Down

0 comments on commit 8fe0b14

Please sign in to comment.