Skip to content

Commit 258629a

Browse files
authored
Merge pull request #1831 from NASA-AMMOS/feature/model_derivation_group_associations_v2
Add default Derivation Group associations for Plans at the Model level
2 parents 9d761ff + fdb72b0 commit 258629a

9 files changed

Lines changed: 160 additions & 1 deletion

File tree

deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ array_relationships:
3939
table:
4040
name: plan
4141
schema: merlin
42+
- name: derivation_group_specification
43+
using:
44+
foreign_key_constraint_on:
45+
column: model_id
46+
table:
47+
name: model_derivation_group
48+
schema: merlin
4249
- name: resource_types
4350
using:
4451
foreign_key_constraint_on:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
table:
2+
name: model_derivation_group
3+
schema: merlin
4+
configuration:
5+
custom_name: "model_derivation_group"
6+
object_relationships:
7+
- name: mission_model
8+
using:
9+
foreign_key_constraint_on: model_id
10+
- name: derivation_group
11+
using:
12+
foreign_key_constraint_on: derivation_group_name
13+
array_relationships:
14+
- name: external_events
15+
using:
16+
manual_configuration:
17+
remote_table:
18+
name: external_event
19+
schema: merlin
20+
column_mapping:
21+
derivation_group_name: derivation_group_name
22+
select_permissions:
23+
- role: aerie_admin
24+
permission:
25+
columns: '*'
26+
filter: {}
27+
allow_aggregations: true
28+
- role: user
29+
permission:
30+
columns: '*'
31+
filter: {}
32+
allow_aggregations: true
33+
- role: viewer
34+
permission:
35+
columns: '*'
36+
filter: {}
37+
allow_aggregations: true
38+
insert_permissions:
39+
- role: aerie_admin
40+
permission:
41+
columns: [model_id, derivation_group_name]
42+
check: {}
43+
- role: user
44+
permission:
45+
columns: [model_id, derivation_group_name]
46+
check: {"mission_model": {"owner": {"_eq": "X-Hasura-User-Id"}}}
47+
delete_permissions:
48+
- role: aerie_admin
49+
permission:
50+
filter: {}
51+
- role: user
52+
permission:
53+
filter: {"mission_model": {"owner": {"_eq": "X-Hasura-User-Id"}}}

deployment/hasura/metadata/databases/tables/tables.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
- "!include merlin/external_source.yaml"
114114
- "!include merlin/external_source_type.yaml"
115115
- "!include merlin/plan_derivation_group.yaml"
116+
- "!include merlin/model_derivation_group.yaml"
116117

117118
# Constraints
118119
- "!include merlin/constraints/constraint_metadata.yaml"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
drop trigger populate_derivation_groups_new_plan_trigger on merlin.plan;
2+
drop function merlin.populate_derivation_groups_new_plan cascade;
3+
drop table merlin.model_derivation_group cascade;
4+
5+
call migrations.mark_migration_rolled_back('35');
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
create table merlin.model_derivation_group (
2+
model_id integer not null,
3+
derivation_group_name text not null,
4+
5+
constraint model_derivation_group_pkey
6+
primary key (model_id, derivation_group_name),
7+
constraint mdg_model_exists
8+
foreign key (model_id)
9+
references merlin.mission_model(id)
10+
on delete cascade,
11+
constraint mdg_derivation_group_exists
12+
foreign key (derivation_group_name)
13+
references merlin.derivation_group(name)
14+
on update cascade
15+
on delete restrict
16+
);
17+
18+
comment on table merlin.model_derivation_group is e''
19+
'The default set of derivation groups that any new plans created using this model would have linked to them.';
20+
21+
comment on column merlin.model_derivation_group.model_id is e''
22+
'The model with which the derivation group is associated.';
23+
comment on column merlin.model_derivation_group.derivation_group_name is e''
24+
'The derivation group being associated with the model.';
25+
26+
27+
create function merlin.populate_derivation_groups_new_plan()
28+
returns trigger
29+
language plpgsql as $$
30+
begin
31+
insert into merlin.plan_derivation_group (plan_id, derivation_group_name)
32+
select new.id, mdg.derivation_group_name
33+
from merlin.model_derivation_group mdg
34+
where mdg.model_id = new.model_id;
35+
return new;
36+
end;
37+
$$;
38+
39+
comment on function merlin.populate_derivation_groups_new_plan() is e''
40+
'Populates the plan''s derivation group associations with the contents of its model''s derivation group associations.';
41+
42+
create trigger populate_derivation_groups_new_plan_trigger
43+
after insert on merlin.plan
44+
for each row
45+
execute function merlin.populate_derivation_groups_new_plan();
46+
47+
call migrations.mark_migration_applied('35');

deployment/postgres-init-db/sql/applied_migrations.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ call migrations.mark_migration_applied(31);
3636
call migrations.mark_migration_applied(32);
3737
call migrations.mark_migration_applied(33);
3838
call migrations.mark_migration_applied(34);
39+
call migrations.mark_migration_applied(35);

deployment/postgres-init-db/sql/init_merlin.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ begin;
2929

3030
-- Scheduling Goals and Scheduling Goal Specification
3131
\ir init_scheduler_mid_merlin.sql
32-
32+
3333
-- Activity Directives
3434
\ir tables/merlin/activity_directive/activity_directive_metadata_schema.sql
3535
\ir tables/merlin/activity_directive/activity_directive.sql
@@ -85,6 +85,7 @@ begin;
8585
\ir tables/merlin/external_events/external_source.sql
8686
\ir tables/merlin/external_events/external_event.sql
8787
\ir tables/merlin/external_events/plan_derivation_group.sql
88+
\ir tables/merlin/external_events/model_derivation_group.sql
8889

8990
------------
9091
-- Functions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
create table merlin.model_derivation_group (
2+
model_id integer not null,
3+
derivation_group_name text not null,
4+
5+
constraint model_derivation_group_pkey
6+
primary key (model_id, derivation_group_name),
7+
constraint mdg_model_exists
8+
foreign key (model_id)
9+
references merlin.mission_model(id)
10+
on delete cascade,
11+
constraint mdg_derivation_group_exists
12+
foreign key (derivation_group_name)
13+
references merlin.derivation_group(name)
14+
on update cascade
15+
on delete restrict
16+
);
17+
18+
comment on table merlin.model_derivation_group is e''
19+
'The default set of derivation groups that any new plans created using this model would have linked to them.';
20+
21+
comment on column merlin.model_derivation_group.model_id is e''
22+
'The model with which the derivation group is associated.';
23+
comment on column merlin.model_derivation_group.derivation_group_name is e''
24+
'The derivation group being associated with the model.';

deployment/postgres-init-db/sql/tables/merlin/plan.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ after insert on merlin.plan
113113
for each row
114114
execute function merlin.populate_constraint_spec_new_plan();
115115

116+
create function merlin.populate_derivation_groups_new_plan()
117+
returns trigger
118+
language plpgsql as $$
119+
begin
120+
insert into merlin.plan_derivation_group (plan_id, derivation_group_name)
121+
select new.id, mdg.derivation_group_name
122+
from merlin.model_derivation_group mdg
123+
where mdg.model_id = new.model_id;
124+
return new;
125+
end;
126+
$$;
127+
128+
comment on function merlin.populate_derivation_groups_new_plan() is e''
129+
'Populates the plan''s derivation group associations with the contents of its model''s derivation group associations.';
130+
131+
create trigger populate_derivation_groups_new_plan_trigger
132+
after insert on merlin.plan
133+
for each row
134+
execute function merlin.populate_derivation_groups_new_plan();
135+
116136
-- Insert or Update Triggers
117137

118138
create trigger set_timestamp

0 commit comments

Comments
 (0)