-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB: Add tables to track constraint requests.
- add a column to track errors that occur when a constraint is run - update Hasura metadata
- Loading branch information
1 parent
0927ae8
commit 615767e
Showing
10 changed files
with
217 additions
and
58 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
deployment/hasura/metadata/databases/tables/merlin/constraints/constraint_request.yaml
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,40 @@ | ||
table: | ||
name: constraint_request | ||
schema: merlin | ||
configuration: | ||
custom_name: "constraint_request" | ||
object_relationships: | ||
- name: plan | ||
using: | ||
foreign_key_constraint_on: plan_id | ||
- name: simulation_dataset | ||
using: | ||
foreign_key_constraint_on: simulation_dataset_id | ||
array_relationships: | ||
- name: constraints_run | ||
using: | ||
foreign_key_constraint_on: | ||
column: request_id | ||
table: | ||
name: constraint_run | ||
schema: merlin | ||
select_permissions: | ||
- role: aerie_admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: user | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: viewer | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
delete_permissions: | ||
- role: aerie_admin | ||
permission: | ||
filter: {} |
51 changes: 51 additions & 0 deletions
51
deployment/hasura/metadata/databases/tables/merlin/constraints/constraint_results.yaml
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 @@ | ||
table: | ||
name: constraint_results | ||
schema: merlin | ||
configuration: | ||
custom_name: "constraint_results" | ||
object_relationships: | ||
- name: constraint_definition | ||
using: | ||
foreign_key_constraint_on: | ||
- constraint_id | ||
- constraint_revision | ||
- name: constraint_metadata | ||
using: | ||
manual_configuration: | ||
column_mapping: | ||
constraint_id: id | ||
insertion_order: null | ||
remote_table: | ||
name: constraint_metadata | ||
schema: merlin | ||
- name: simulation_dataset | ||
using: | ||
foreign_key_constraint_on: simulation_dataset_id | ||
array_relationships: | ||
- name: constraint_runs | ||
using: | ||
foreign_key_constraint_on: | ||
column: constraint_results_id | ||
table: | ||
name: constraint_run | ||
schema: merlin | ||
select_permissions: | ||
- role: aerie_admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: user | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: viewer | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
delete_permissions: | ||
- role: aerie_admin | ||
permission: | ||
filter: {} |
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
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
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
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
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
37 changes: 37 additions & 0 deletions
37
deployment/postgres-init-db/sql/tables/merlin/constraints/constraint_request.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,37 @@ | ||
create table merlin.constraint_request ( | ||
id integer not null generated always as identity | ||
primary key, | ||
plan_id integer not null, | ||
simulation_dataset_id integer not null, -- "not null", as we reject rqs if there aren't up-to-date sim results | ||
-- (or if the provided sim dataset id is invalid) | ||
force_rerun boolean, | ||
|
||
-- Additional Metadata | ||
requested_by text, | ||
requested_at timestamptz not null default now(), | ||
|
||
constraint constraint_request_plan | ||
foreign key (plan_id) | ||
references merlin.plan | ||
on delete cascade, | ||
constraint constraint_request_simulation_dataset | ||
foreign key (simulation_dataset_id) | ||
references merlin.simulation_dataset | ||
on delete cascade, | ||
constraint constraint_request_requested_by | ||
foreign key (requested_by) | ||
references permissions.users | ||
on update cascade | ||
on delete set null | ||
); | ||
|
||
comment on table merlin.constraint_request is e'' | ||
'A record of the inputs to an executed constraint request.'; | ||
comment on column merlin.constraint_request.id is e'' | ||
'The generated identifier for this request.'; | ||
comment on column merlin.constraint_request.plan_id is e'' | ||
'The plan used during this request.'; | ||
comment on column merlin.constraint_request.simulation_dataset_id is e'' | ||
'The simulation results used during this request.'; | ||
comment on column merlin.constraint_request.force_rerun is e'' | ||
'Whether this request specified the "force" flag.'; |
48 changes: 48 additions & 0 deletions
48
deployment/postgres-init-db/sql/tables/merlin/constraints/constraint_results.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,48 @@ | ||
create table merlin.constraint_results ( | ||
id integer not null generated always as identity, | ||
|
||
-- inputs | ||
constraint_id integer not null, | ||
constraint_revision integer not null, | ||
simulation_dataset_id integer not null, | ||
arguments jsonb not null, | ||
priority int not null, | ||
|
||
-- outputs | ||
results jsonb not null default '{}', | ||
errors jsonb not null default '{}', | ||
|
||
constraint constraint_results_key | ||
primary key (id), | ||
constraint constraint_results_to_constraint_definition | ||
foreign key (constraint_id, constraint_revision) | ||
references merlin.constraint_definition | ||
on delete cascade, | ||
constraint constraint_results_to_simulation_dataset | ||
foreign key (simulation_dataset_id) | ||
references merlin.simulation_dataset | ||
on delete cascade | ||
); | ||
|
||
create index constraint_results_simulation_dataset_id_index | ||
on merlin.constraint_results (simulation_dataset_id); | ||
|
||
comment on table merlin.constraint_results is e'' | ||
'The output of running a single constraint. Results are cached to avoid unnecessary execution.'; | ||
|
||
comment on column merlin.constraint_results.id is e'' | ||
'The generated identifier for this results.'; | ||
comment on column merlin.constraint_results.constraint_id is e'' | ||
'The constraint that was checked.'; | ||
comment on column merlin.constraint_results.constraint_revision is e'' | ||
'The version of the constraint definition that was checked.'; | ||
comment on column merlin.constraint_results.simulation_dataset_id is e'' | ||
'The simulation dataset the constraint was checked against.'; | ||
comment on column merlin.constraint_results.arguments is e'' | ||
'The arguments provided to the constraint when checked.'; | ||
comment on column merlin.constraint_results.priority is e'' | ||
'The priority the constraint had when checked.'; | ||
comment on column merlin.constraint_results.results is e'' | ||
'Results that were computed during the constraint check.'; | ||
comment on column merlin.constraint_results.results is e'' | ||
'Errors that occurred while checking the constraint.'; |
63 changes: 21 additions & 42 deletions
63
deployment/postgres-init-db/sql/tables/merlin/constraints/constraint_run.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 |
---|---|---|
@@ -1,48 +1,27 @@ | ||
create table merlin.constraint_run ( | ||
constraint_id integer not null, | ||
constraint_revision integer not null, | ||
simulation_dataset_id integer not null, | ||
create table merlin.constraint_run( | ||
request_id integer not null, | ||
constraint_invocation_id integer not null, | ||
arguments jsonb not null, | ||
constraint_results_id integer not null, | ||
|
||
results jsonb not null default '{}', | ||
|
||
-- Additional Metadata | ||
requested_by text, | ||
requested_at timestamptz not null default now(), | ||
|
||
constraint constraint_run_key | ||
primary key (constraint_invocation_id, constraint_revision, simulation_dataset_id), | ||
constraint constraint_run_to_constraint_definition | ||
foreign key (constraint_id, constraint_revision) | ||
references merlin.constraint_definition | ||
on delete cascade, | ||
constraint constraint_run_to_simulation_dataset | ||
foreign key (simulation_dataset_id) | ||
references merlin.simulation_dataset | ||
on delete cascade, | ||
constraint constraint_run_requested_by | ||
foreign key (requested_by) | ||
references permissions.users | ||
on update cascade | ||
on delete set null | ||
constraint constraint_run_pkey | ||
primary key (request_id, constraint_invocation_id, constraint_results_id), | ||
constraint constraint_run_request foreign key (request_id) | ||
references merlin.constraint_request | ||
on delete cascade, | ||
constraint constraint_run_invocation foreign key (constraint_invocation_id) | ||
references merlin.constraint_specification | ||
on delete cascade, | ||
constraint constraint_run_results foreign key (constraint_results_id) | ||
references merlin.constraint_results | ||
on delete restrict | ||
); | ||
|
||
create index constraint_run_simulation_dataset_id_index | ||
on merlin.constraint_run (simulation_dataset_id); | ||
|
||
comment on table merlin.constraint_run is e'' | ||
'A single constraint run, used to cache violation results to be reused if the constraint definition is not stale.'; | ||
'A join table connecting each constraint run during a request to its result.'; | ||
|
||
comment on column merlin.constraint_run.constraint_id is e'' | ||
'The constraint that we are evaluating during the run.'; | ||
comment on column merlin.constraint_run.constraint_revision is e'' | ||
'The version of the constraint definition that was checked.'; | ||
comment on column merlin.constraint_run.simulation_dataset_id is e'' | ||
'The simulation dataset id from when the constraint was checked.'; | ||
comment on column merlin.constraint_run.results is e'' | ||
'Results that were computed during the constraint check.'; | ||
comment on column merlin.constraint_run.requested_by is e'' | ||
'The user who requested the constraint run.'; | ||
comment on column merlin.constraint_run.requested_at is e'' | ||
'When the constraint run was created.'; | ||
comment on column merlin.constraint_run.request_id is e'' | ||
'The constraint request during which this constraint was checked.'; | ||
comment on column merlin.constraint_run.constraint_invocation_id is e'' | ||
'The constraint that was checked.'; | ||
comment on column merlin.constraint_run.constraint_results_id is e'' | ||
'The output of checking the constraint.'; |