Skip to content

Commit c467d39

Browse files
authored
Merge pull request #1652 from NASA-AMMOS/hotfix/database-conventions-for-sequence-templating
Ensure database conventions are followed for sequence templating.
2 parents ed250b8 + 0209b09 commit c467d39

File tree

4 files changed

+125
-23
lines changed

4 files changed

+125
-23
lines changed

deployment/hasura/migrations/Aerie/14_sequence_templates/up.sql

+63-12
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,45 @@ create table sequencing.sequence_template (
1212

1313
constraint sequence_template_pkey primary key (id),
1414
constraint activity_type foreign key (activity_type, model_id)
15-
references merlin.activity_type (name, model_id) match simple
15+
references merlin.activity_type (name, model_id)
1616
on update cascade
1717
on delete set null,
18-
constraint "model_id -> merlin.mission_model.id" foreign key (model_id)
19-
references merlin.mission_model (id) match simple
18+
constraint seq_template_mission_model_exists foreign key (model_id)
19+
references merlin.mission_model (id)
2020
on update cascade
2121
on delete set null,
22-
constraint "parcel_id -> sequencing.parcel.id" foreign key (parcel_id)
23-
references sequencing.parcel (id) match simple
22+
constraint seq_template_parcel_exists foreign key (parcel_id)
23+
references sequencing.parcel (id)
2424
on update cascade
2525
on delete set null,
2626

2727
constraint only_one_template_per_model_activity_type
28-
unique (model_id, activity_type)
28+
unique (model_id, activity_type)
2929
);
3030

31+
comment on table sequencing.sequence_template is e''
32+
'A table of sequence templates for given activity types.';
33+
34+
comment on column sequencing.sequence_template.id is e''
35+
'The unique integer id for this sequence template.';
36+
comment on column sequencing.sequence_template.name is e''
37+
'The user-provided name for this template.';
38+
comment on column sequencing.sequence_template.model_id is e''
39+
'The mission model id that this template applies to.\n'
40+
'This id is used in correlating this template with a real activity type.';
41+
comment on column sequencing.sequence_template.parcel_id is e''
42+
'The parcel that this template uses.\n'
43+
'This id is used to define available commands for this template.';
44+
comment on column sequencing.sequence_template.template_definition is e''
45+
'The actual, text definition for this template.\n'
46+
'Text should be formatted as Handlebars/Mustache-compliant text.';
47+
comment on column sequencing.sequence_template.activity_type is e''
48+
'The activity type that this sequence template applies to.';
49+
comment on column sequencing.sequence_template.language is e''
50+
'The language (STOL, SeqN) that this sequence template is written in.';
51+
comment on column sequencing.sequence_template.owner is e''
52+
'The user that created this sequence template.';
53+
3154

3255
-- introduce sequence filters
3356
create table sequencing.sequence_filter (
@@ -36,15 +59,29 @@ create table sequencing.sequence_filter (
3659
model_id integer not null,
3760
name text,
3861

39-
constraint sequence_filter_primary_key
40-
primary key (id),
62+
constraint sequence_filter_primary_key primary key (id),
4163

42-
foreign key (model_id)
64+
constraint seq_filter_mission_model_exists foreign key (model_id)
4365
references merlin.mission_model
4466
on update cascade
4567
on delete cascade
4668
);
4769

70+
comment on table sequencing.sequence_filter is e''
71+
'A table of sequence filters, which select the appropriate\n'
72+
'simulated activity instances for a given sequence.';
73+
74+
comment on column sequencing.sequence_filter.id is e''
75+
'The unique integer id for this sequence filter.';
76+
comment on column sequencing.sequence_filter.filter is e''
77+
'The JSON-formatted filter over the simulated activities that\n'
78+
'is used to select the appropriate simulated activity instances for a given sequence.';
79+
comment on column sequencing.sequence_filter.model_id is e''
80+
'The mission model that this filter applies to.\n'
81+
'This contextualizes the filter.';
82+
comment on column sequencing.sequence_filter.name is e''
83+
'The name of the sequence filter.';
84+
4885

4986
-- introduce a table to hold the result of expanded templates, in a separate table from expanded sequences because
5087
-- this result is in text, not necessarily jsonb.
@@ -66,13 +103,27 @@ create table sequencing.expanded_templates (
66103
on delete cascade,
67104

68105
constraint expanded_template_to_sequence
69-
foreign key (seq_id, simulation_dataset_id)
70-
references sequencing.sequence
71-
on delete cascade
106+
foreign key (seq_id, simulation_dataset_id)
107+
references sequencing.sequence
108+
on delete cascade
72109
);
73110

74111
comment on table sequencing.expanded_templates is e''
75112
'A cache of sequences that have already been expanded.';
76113

114+
comment on column sequencing.expanded_templates.id is e''
115+
'The integer-generated unique id for an expanded template.';
116+
comment on column sequencing.expanded_templates.seq_id is e''
117+
'The id of the sequence that this expansion correlates with.\n'
118+
'That sequence is what correlates this template with the activities it expands.';
119+
comment on column sequencing.expanded_templates.simulation_dataset_id is e''
120+
'The id of the simulation that this expansion correlates with.\n'
121+
'This id tells us for what exact simulation run of a given plan (and therefore for what\n'
122+
'simulated activity entries) this expansion covers.';
123+
comment on column sequencing.expanded_templates.expanded_template is e''
124+
'The content of the expanded template.';
125+
comment on column sequencing.expanded_templates.created_at is e''
126+
'A temporal identifier that indicates when exactly this sequence was expanded.';
127+
77128

78129
call migrations.mark_migration_applied('14');

deployment/postgres-init-db/sql/tables/sequencing/expanded_templates.sql

+17-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,24 @@ create table sequencing.expanded_templates (
1616
on delete cascade,
1717

1818
constraint expanded_template_to_sequence
19-
foreign key (seq_id, simulation_dataset_id)
20-
references sequencing.sequence
21-
on delete cascade
19+
foreign key (seq_id, simulation_dataset_id)
20+
references sequencing.sequence
21+
on delete cascade
2222
);
2323

2424
comment on table sequencing.expanded_templates is e''
2525
'A cache of sequences that have already been expanded.';
26+
27+
comment on column sequencing.expanded_templates.id is e''
28+
'The integer-generated unique id for an expanded template.';
29+
comment on column sequencing.expanded_templates.seq_id is e''
30+
'The id of the sequence that this expansion correlates with.\n'
31+
'That sequence is what correlates this template with the activities it expands.';
32+
comment on column sequencing.expanded_templates.simulation_dataset_id is e''
33+
'The id of the simulation that this expansion correlates with.\n'
34+
'This id tells us for what exact simulation run of a given plan (and therefore for what\n'
35+
'simulated activity entries) this expansion covers.';
36+
comment on column sequencing.expanded_templates.expanded_template is e''
37+
'The content of the expanded template.';
38+
comment on column sequencing.expanded_templates.created_at is e''
39+
'A temporal identifier that indicates when exactly this sequence was expanded.';

deployment/postgres-init-db/sql/tables/sequencing/sequence_filter.sql

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@ create table sequencing.sequence_filter (
44
model_id integer not null,
55
name text,
66

7-
constraint sequence_filter_primary_key
8-
primary key (id),
7+
constraint sequence_filter_primary_key primary key (id),
98

10-
foreign key (model_id)
9+
constraint seq_filter_mission_model_exists foreign key (model_id)
1110
references merlin.mission_model
1211
on update cascade
1312
on delete cascade
1413
);
14+
15+
comment on table sequencing.sequence_filter is e''
16+
'A table of sequence filters, which select the appropriate\n'
17+
'simulated activity instances for a given sequence.';
18+
19+
comment on column sequencing.sequence_filter.id is e''
20+
'The unique integer id for this sequence filter.';
21+
comment on column sequencing.sequence_filter.filter is e''
22+
'The JSON-formatted filter over the simulated activities that\n'
23+
'is used to select the appropriate simulated activity instances for a given sequence.';
24+
comment on column sequencing.sequence_filter.model_id is e''
25+
'The mission model that this filter applies to.\n'
26+
'This contextualizes the filter.';
27+
comment on column sequencing.sequence_filter.name is e''
28+
'The name of the sequence filter.';

deployment/postgres-init-db/sql/tables/sequencing/sequence_template.sql

+28-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,41 @@ create table sequencing.sequence_template (
1111

1212
constraint sequence_template_pkey primary key (id),
1313
constraint activity_type foreign key (activity_type, model_id)
14-
references merlin.activity_type (name, model_id) match simple
14+
references merlin.activity_type (name, model_id)
1515
on update cascade
1616
on delete set null,
17-
constraint "model_id -> merlin.mission_model.id" foreign key (model_id)
18-
references merlin.mission_model (id) match simple
17+
constraint seq_template_mission_model_exists foreign key (model_id)
18+
references merlin.mission_model (id)
1919
on update cascade
2020
on delete set null,
21-
constraint "parcel_id -> sequencing.parcel.id" foreign key (parcel_id)
22-
references sequencing.parcel (id) match simple
21+
constraint seq_template_parcel_exists foreign key (parcel_id)
22+
references sequencing.parcel (id)
2323
on update cascade
2424
on delete set null,
2525

2626
constraint only_one_template_per_model_activity_type
2727
unique (model_id, activity_type)
2828
);
29+
30+
comment on table sequencing.sequence_template is e''
31+
'A table of sequence templates for given activity types.';
32+
33+
comment on column sequencing.sequence_template.id is e''
34+
'The unique integer id for this sequence template.';
35+
comment on column sequencing.sequence_template.name is e''
36+
'The user-provided name for this template.';
37+
comment on column sequencing.sequence_template.model_id is e''
38+
'The mission model id that this template applies to.\n'
39+
'This id is used in correlating this template with a real activity type.';
40+
comment on column sequencing.sequence_template.parcel_id is e''
41+
'The parcel that this template uses.\n'
42+
'This id is used to define available commands for this template.';
43+
comment on column sequencing.sequence_template.template_definition is e''
44+
'The actual, text definition for this template.\n'
45+
'Text should be formatted as Handlebars/Mustache-compliant text.';
46+
comment on column sequencing.sequence_template.activity_type is e''
47+
'The activity type that this sequence template applies to.';
48+
comment on column sequencing.sequence_template.language is e''
49+
'The language (STOL, SeqN) that this sequence template is written in.';
50+
comment on column sequencing.sequence_template.owner is e''
51+
'The user that created this sequence template.';

0 commit comments

Comments
 (0)