From 6ace2b8016c65e7942030dfab49411f1cd3724d2 Mon Sep 17 00:00:00 2001 From: Cody Hansen Date: Thu, 30 May 2024 07:21:11 -1000 Subject: [PATCH 1/3] Added a table to track the default view for a given mission model --- .../metadata/databases/tables/tables.yaml | 1 + .../tables/ui/view_to_mission_model.yaml | 37 +++++++++++++++++ .../4_mission_model_default_view/down.sql | 5 +++ .../Aerie/4_mission_model_default_view/up.sql | 41 +++++++++++++++++++ .../sql/applied_migrations.sql | 1 + deployment/postgres-init-db/sql/init_ui.sql | 1 + .../sql/tables/ui/view_to_mission_model.sql | 39 ++++++++++++++++++ 7 files changed, 125 insertions(+) create mode 100644 deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml create mode 100644 deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql create mode 100644 deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql create mode 100644 deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql diff --git a/deployment/hasura/metadata/databases/tables/tables.yaml b/deployment/hasura/metadata/databases/tables/tables.yaml index e6c9809efe..9334de6512 100644 --- a/deployment/hasura/metadata/databases/tables/tables.yaml +++ b/deployment/hasura/metadata/databases/tables/tables.yaml @@ -165,4 +165,5 @@ ############ - "!include ui/extension_roles.yaml" - "!include ui/extensions.yaml" +- "!include ui/view_to_mission_model.yaml" - "!include ui/view.yaml" diff --git a/deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml b/deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml new file mode 100644 index 0000000000..b945c05a6c --- /dev/null +++ b/deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml @@ -0,0 +1,37 @@ +table: + name: view_to_mission_model + schema: ui +configuration: + custom_name: "view_to_mission_model" +object_relationships: + - name: mission_model + using: + foreign_key_constraint_on: mission_model_id + - name: view + using: + foreign_key_constraint_on: view_id +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 +insert_permissions: + - role: aerie_admin + permission: + columns: "*" + check: {} +delete_permissions: + - role: aerie_admin + permission: + filter: {} diff --git a/deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql new file mode 100644 index 0000000000..e400445618 --- /dev/null +++ b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql @@ -0,0 +1,5 @@ +drop trigger set_timestamp on view_to_mission_model; + +drop table view_to_mission_model; + +call migrations.mark_migration_rolled_back('4'); diff --git a/deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql new file mode 100644 index 0000000000..a316484806 --- /dev/null +++ b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql @@ -0,0 +1,41 @@ +create table ui.view_to_mission_model ( + created_at timestamptz not null default now(), + id integer generated always as identity, + mission_model_id integer not null, + updated_at timestamptz not null default now(), + view_id integer not null, + + constraint view_to_mission_model_primary_key + primary key (id), + + constraint one_view_per_mission_model + unique (mission_model_id, view_id), + + foreign key (mission_model_id) + references merlin.mission_model (id) + on delete cascade, + + foreign key (view_id) + references ui.view (id) + on delete cascade +); + +comment on table ui.view_to_mission_model is e'' + 'Default views set for a given mission model.'; +comment on column ui.view_to_mission_model.created_at is e'' + 'The time the default view was set.'; +comment on column ui.view_to_mission_model.id is e'' + 'Integer primary key of the view to mission model mapping.'; +comment on column ui.view_to_mission_model.mission_model_id is e'' + 'The mission model id that the view is mapped to.'; +comment on column ui.view_to_mission_model.updated_at is e'' + 'The time the mission model to view mapping was last updated at.'; +comment on column ui.view_to_mission_model.view_id is e'' + 'The view id that the mission model is mapped to.'; + +create trigger set_timestamp + before update on ui.view_to_mission_model + for each row +execute function util_functions.set_updated_at(); + +call migrations.mark_migration_applied('4'); diff --git a/deployment/postgres-init-db/sql/applied_migrations.sql b/deployment/postgres-init-db/sql/applied_migrations.sql index 27cacb7e06..f9c845e577 100644 --- a/deployment/postgres-init-db/sql/applied_migrations.sql +++ b/deployment/postgres-init-db/sql/applied_migrations.sql @@ -6,3 +6,4 @@ call migrations.mark_migration_applied('0'); call migrations.mark_migration_applied('1'); call migrations.mark_migration_applied('2'); call migrations.mark_migration_applied('3'); +call migrations.mark_migration_applied('4'); diff --git a/deployment/postgres-init-db/sql/init_ui.sql b/deployment/postgres-init-db/sql/init_ui.sql index 2acbb28845..ceab256f8d 100644 --- a/deployment/postgres-init-db/sql/init_ui.sql +++ b/deployment/postgres-init-db/sql/init_ui.sql @@ -10,4 +10,5 @@ begin; \ir tables/ui/extensions.sql \ir tables/ui/extension_roles.sql \ir tables/ui/view.sql + \ir tables/ui/view_to_mission_model.sql end; diff --git a/deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql b/deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql new file mode 100644 index 0000000000..5220f2ccc7 --- /dev/null +++ b/deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql @@ -0,0 +1,39 @@ +create table ui.view_to_mission_model ( + created_at timestamptz not null default now(), + id integer generated always as identity, + mission_model_id integer not null, + updated_at timestamptz not null default now(), + view_id integer not null, + + constraint view_to_mission_model_primary_key + primary key (id), + + constraint one_view_per_mission_model + unique (mission_model_id, view_id), + + foreign key (mission_model_id) + references merlin.mission_model (id) + on delete cascade, + + foreign key (view_id) + references ui.view (id) + on delete cascade +); + +comment on table ui.view_to_mission_model is e'' + 'Default views set for a given mission model.'; +comment on column ui.view_to_mission_model.created_at is e'' + 'The time the default view was set.'; +comment on column ui.view_to_mission_model.id is e'' + 'Integer primary key of the view to mission model mapping.'; +comment on column ui.view_to_mission_model.mission_model_id is e'' + 'The mission model id that the view is mapped to.'; +comment on column ui.view_to_mission_model.updated_at is e'' + 'The time the mission model to view mapping was last updated at.'; +comment on column ui.view_to_mission_model.view_id is e'' + 'The view id that the mission model is mapped to.'; + +create trigger set_timestamp + before update on ui.view_to_mission_model + for each row +execute function util_functions.set_updated_at(); From b62806c01640ff389e8f49a6b7abf0108be4e988 Mon Sep 17 00:00:00 2001 From: Cody Hansen Date: Thu, 30 May 2024 11:20:57 -1000 Subject: [PATCH 2/3] Changed to use a column on mission_model rather than using an association table --- .../tables/merlin/mission_model.yaml | 265 +++++++++--------- .../metadata/databases/tables/tables.yaml | 1 - .../tables/ui/view_to_mission_model.yaml | 37 --- .../4_mission_model_default_view/down.sql | 5 +- .../Aerie/4_mission_model_default_view/up.sql | 42 +-- deployment/postgres-init-db/sql/init.sql | 6 +- deployment/postgres-init-db/sql/init_ui.sql | 1 - .../sql/tables/merlin/mission_model.sql | 6 + .../sql/tables/ui/view_to_mission_model.sql | 39 --- 9 files changed, 151 insertions(+), 251 deletions(-) delete mode 100644 deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml delete mode 100644 deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql diff --git a/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml b/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml index 64969023ea..78c7b4be1f 100644 --- a/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml +++ b/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml @@ -4,97 +4,100 @@ table: configuration: custom_name: "mission_model" object_relationships: -- name: parameters - using: - foreign_key_constraint_on: - column: model_id - table: - name: mission_model_parameters - schema: merlin -- name: uploaded_file - using: - foreign_key_constraint_on: jar_id + - name: parameters + using: + foreign_key_constraint_on: + column: model_id + table: + name: mission_model_parameters + schema: merlin + - name: uploaded_file + using: + foreign_key_constraint_on: jar_id + - name: view + using: + foreign_key_constraint_on: default_view_id array_relationships: -- name: activity_types - using: - foreign_key_constraint_on: - column: model_id - table: - name: activity_type - schema: merlin -- name: constraint_specification - using: - foreign_key_constraint_on: - column: model_id - table: - name: constraint_model_specification - schema: merlin -- name: plans - using: - foreign_key_constraint_on: - column: model_id - table: - name: plan - schema: merlin -- name: resource_types - using: - foreign_key_constraint_on: - column: model_id - table: - name: resource_type - schema: merlin -- name: scheduling_specification_conditions - using: - foreign_key_constraint_on: - column: model_id - table: - name: scheduling_model_specification_conditions - schema: scheduler -- name: scheduling_specification_goals - using: - foreign_key_constraint_on: - column: model_id - table: - name: scheduling_model_specification_goals - schema: scheduler -- name: refresh_activity_type_logs - using: - manual_configuration: - remote_table: - name: refresh_activity_type_logs - schema: hasura - column_mapping: - id: model_id -- name: refresh_model_parameter_logs - using: - manual_configuration: - remote_table: - name: refresh_model_parameter_logs - schema: hasura - column_mapping: - id: model_id -- name: refresh_resource_type_logs - using: - manual_configuration: - remote_table: - name: refresh_resource_type_logs - schema: hasura - column_mapping: - id: model_id + - name: activity_types + using: + foreign_key_constraint_on: + column: model_id + table: + name: activity_type + schema: merlin + - name: constraint_specification + using: + foreign_key_constraint_on: + column: model_id + table: + name: constraint_model_specification + schema: merlin + - name: plans + using: + foreign_key_constraint_on: + column: model_id + table: + name: plan + schema: merlin + - name: resource_types + using: + foreign_key_constraint_on: + column: model_id + table: + name: resource_type + schema: merlin + - name: scheduling_specification_conditions + using: + foreign_key_constraint_on: + column: model_id + table: + name: scheduling_model_specification_conditions + schema: scheduler + - name: scheduling_specification_goals + using: + foreign_key_constraint_on: + column: model_id + table: + name: scheduling_model_specification_goals + schema: scheduler + - name: refresh_activity_type_logs + using: + manual_configuration: + remote_table: + name: refresh_activity_type_logs + schema: hasura + column_mapping: + id: model_id + - name: refresh_model_parameter_logs + using: + manual_configuration: + remote_table: + name: refresh_model_parameter_logs + schema: hasura + column_mapping: + id: model_id + - name: refresh_resource_type_logs + using: + manual_configuration: + remote_table: + name: refresh_resource_type_logs + schema: hasura + column_mapping: + id: model_id select_permissions: - role: aerie_admin permission: - columns: '*' + columns: "*" filter: {} allow_aggregations: true - role: user permission: - columns: '*' + columns: "*" filter: {} allow_aggregations: true - role: viewer permission: - columns: '*' + columns: "*" filter: {} allow_aggregations: true insert_permissions: @@ -103,7 +106,7 @@ insert_permissions: columns: [mission, name, version, description, jar_id] check: {} set: - owner: 'x-hasura-user-id' + owner: "x-hasura-user-id" update_permissions: - role: aerie_admin permission: @@ -115,54 +118,54 @@ delete_permissions: filter: {} event_triggers: -- definition: - enable_manual: false - insert: - columns: "*" - update: - columns: - - id - - revision - - jar_id - - mission - - name - - version - - owner - name: refreshActivityTypes - retry_conf: - interval_sec: 10 - num_retries: 0 - timeout_sec: 300 - webhook: "{{AERIE_MERLIN_URL}}/refreshActivityTypes" -- definition: - enable_manual: false - insert: - columns: "*" - update: - columns: - - id - - revision - - jar_id - - mission - - name - - version - - owner - name: refreshModelParameters - retry_conf: - interval_sec: 10 - num_retries: 0 - timeout_sec: 300 - webhook: "{{AERIE_MERLIN_URL}}/refreshModelParameters" -- definition: - enable_manual: false - insert: - columns: "*" - update: - columns: - - jar_id - name: refreshResourceTypes - retry_conf: - interval_sec: 10 - num_retries: 0 - timeout_sec: 300 - webhook: "{{AERIE_MERLIN_URL}}/refreshResourceTypes" + - definition: + enable_manual: false + insert: + columns: "*" + update: + columns: + - id + - revision + - jar_id + - mission + - name + - version + - owner + name: refreshActivityTypes + retry_conf: + interval_sec: 10 + num_retries: 0 + timeout_sec: 300 + webhook: "{{AERIE_MERLIN_URL}}/refreshActivityTypes" + - definition: + enable_manual: false + insert: + columns: "*" + update: + columns: + - id + - revision + - jar_id + - mission + - name + - version + - owner + name: refreshModelParameters + retry_conf: + interval_sec: 10 + num_retries: 0 + timeout_sec: 300 + webhook: "{{AERIE_MERLIN_URL}}/refreshModelParameters" + - definition: + enable_manual: false + insert: + columns: "*" + update: + columns: + - jar_id + name: refreshResourceTypes + retry_conf: + interval_sec: 10 + num_retries: 0 + timeout_sec: 300 + webhook: "{{AERIE_MERLIN_URL}}/refreshResourceTypes" diff --git a/deployment/hasura/metadata/databases/tables/tables.yaml b/deployment/hasura/metadata/databases/tables/tables.yaml index 9334de6512..e6c9809efe 100644 --- a/deployment/hasura/metadata/databases/tables/tables.yaml +++ b/deployment/hasura/metadata/databases/tables/tables.yaml @@ -165,5 +165,4 @@ ############ - "!include ui/extension_roles.yaml" - "!include ui/extensions.yaml" -- "!include ui/view_to_mission_model.yaml" - "!include ui/view.yaml" diff --git a/deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml b/deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml deleted file mode 100644 index b945c05a6c..0000000000 --- a/deployment/hasura/metadata/databases/tables/ui/view_to_mission_model.yaml +++ /dev/null @@ -1,37 +0,0 @@ -table: - name: view_to_mission_model - schema: ui -configuration: - custom_name: "view_to_mission_model" -object_relationships: - - name: mission_model - using: - foreign_key_constraint_on: mission_model_id - - name: view - using: - foreign_key_constraint_on: view_id -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 -insert_permissions: - - role: aerie_admin - permission: - columns: "*" - check: {} -delete_permissions: - - role: aerie_admin - permission: - filter: {} diff --git a/deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql index e400445618..1762b65d4d 100644 --- a/deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql +++ b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/down.sql @@ -1,5 +1,4 @@ -drop trigger set_timestamp on view_to_mission_model; - -drop table view_to_mission_model; +alter table merlin.mission_model + drop column default_view_id; call migrations.mark_migration_rolled_back('4'); diff --git a/deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql index a316484806..742977bf58 100644 --- a/deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql +++ b/deployment/hasura/migrations/Aerie/4_mission_model_default_view/up.sql @@ -1,41 +1,11 @@ -create table ui.view_to_mission_model ( - created_at timestamptz not null default now(), - id integer generated always as identity, - mission_model_id integer not null, - updated_at timestamptz not null default now(), - view_id integer not null, +alter table merlin.mission_model + add column default_view_id integer default null, - constraint view_to_mission_model_primary_key - primary key (id), - - constraint one_view_per_mission_model - unique (mission_model_id, view_id), - - foreign key (mission_model_id) - references merlin.mission_model (id) - on delete cascade, - - foreign key (view_id) + add foreign key (default_view_id) references ui.view (id) - on delete cascade -); - -comment on table ui.view_to_mission_model is e'' - 'Default views set for a given mission model.'; -comment on column ui.view_to_mission_model.created_at is e'' - 'The time the default view was set.'; -comment on column ui.view_to_mission_model.id is e'' - 'Integer primary key of the view to mission model mapping.'; -comment on column ui.view_to_mission_model.mission_model_id is e'' - 'The mission model id that the view is mapped to.'; -comment on column ui.view_to_mission_model.updated_at is e'' - 'The time the mission model to view mapping was last updated at.'; -comment on column ui.view_to_mission_model.view_id is e'' - 'The view id that the mission model is mapped to.'; + on delete set null; -create trigger set_timestamp - before update on ui.view_to_mission_model - for each row -execute function util_functions.set_updated_at(); +comment on column merlin.mission_model.default_view_id is e'' + 'The ID of an option default view for the mission model.'; call migrations.mark_migration_applied('4'); diff --git a/deployment/postgres-init-db/sql/init.sql b/deployment/postgres-init-db/sql/init.sql index 175c0ffba7..a42a30c46b 100644 --- a/deployment/postgres-init-db/sql/init.sql +++ b/deployment/postgres-init-db/sql/init.sql @@ -24,6 +24,9 @@ begin; \ir tables/tags/tags.sql \ir functions/tags/get_tags.sql + -- UI + \ir init_ui.sql + -- Merlin \ir init_merlin.sql @@ -33,9 +36,6 @@ begin; -- Sequencing \ir init_sequencing.sql - -- UI - \ir init_ui.sql - -- Tags \ir init_tags.sql diff --git a/deployment/postgres-init-db/sql/init_ui.sql b/deployment/postgres-init-db/sql/init_ui.sql index ceab256f8d..2acbb28845 100644 --- a/deployment/postgres-init-db/sql/init_ui.sql +++ b/deployment/postgres-init-db/sql/init_ui.sql @@ -10,5 +10,4 @@ begin; \ir tables/ui/extensions.sql \ir tables/ui/extension_roles.sql \ir tables/ui/view.sql - \ir tables/ui/view_to_mission_model.sql end; diff --git a/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql b/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql index 34b936e84f..3165a714a7 100644 --- a/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql +++ b/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql @@ -6,6 +6,7 @@ create table merlin.mission_model ( name text not null, version text not null, description text not null default '', + default_view_id integer default null, owner text, jar_id integer not null, @@ -24,6 +25,9 @@ create table merlin.mission_model ( constraint mission_model_owner_exists foreign key (owner) references permissions.users on update cascade + on delete set null, + foreign key (default_view_id) + references ui.view on delete set null ); @@ -48,6 +52,8 @@ comment on column merlin.mission_model.created_at is e'' 'The time this mission model was uploaded into Aerie.'; comment on column merlin.mission_model.description is e'' 'A human-meaningful description of the mission model.'; +comment on column merlin.mission_model.default_view_id is e'' + 'The ID of an option default view for the mission model.'; create trigger increment_revision_mission_model_update before update on merlin.mission_model diff --git a/deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql b/deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql deleted file mode 100644 index 5220f2ccc7..0000000000 --- a/deployment/postgres-init-db/sql/tables/ui/view_to_mission_model.sql +++ /dev/null @@ -1,39 +0,0 @@ -create table ui.view_to_mission_model ( - created_at timestamptz not null default now(), - id integer generated always as identity, - mission_model_id integer not null, - updated_at timestamptz not null default now(), - view_id integer not null, - - constraint view_to_mission_model_primary_key - primary key (id), - - constraint one_view_per_mission_model - unique (mission_model_id, view_id), - - foreign key (mission_model_id) - references merlin.mission_model (id) - on delete cascade, - - foreign key (view_id) - references ui.view (id) - on delete cascade -); - -comment on table ui.view_to_mission_model is e'' - 'Default views set for a given mission model.'; -comment on column ui.view_to_mission_model.created_at is e'' - 'The time the default view was set.'; -comment on column ui.view_to_mission_model.id is e'' - 'Integer primary key of the view to mission model mapping.'; -comment on column ui.view_to_mission_model.mission_model_id is e'' - 'The mission model id that the view is mapped to.'; -comment on column ui.view_to_mission_model.updated_at is e'' - 'The time the mission model to view mapping was last updated at.'; -comment on column ui.view_to_mission_model.view_id is e'' - 'The view id that the mission model is mapped to.'; - -create trigger set_timestamp - before update on ui.view_to_mission_model - for each row -execute function util_functions.set_updated_at(); From 2d17e09d5793c1c8013e823e4b131229ccf962f2 Mon Sep 17 00:00:00 2001 From: Cody Hansen Date: Thu, 6 Jun 2024 11:40:55 -1000 Subject: [PATCH 3/3] Fixed a typo and added the new column to the permissions list --- .../metadata/databases/tables/merlin/mission_model.yaml | 4 ++-- .../postgres-init-db/sql/tables/merlin/mission_model.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml b/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml index 78c7b4be1f..fe689dc6bf 100644 --- a/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml +++ b/deployment/hasura/metadata/databases/tables/merlin/mission_model.yaml @@ -103,14 +103,14 @@ select_permissions: insert_permissions: - role: aerie_admin permission: - columns: [mission, name, version, description, jar_id] + columns: [mission, name, version, description, jar_id, default_view_id] check: {} set: owner: "x-hasura-user-id" update_permissions: - role: aerie_admin permission: - columns: [mission, name, version, description, owner] + columns: [mission, name, version, description, owner, default_view_id] filter: {} delete_permissions: - role: aerie_admin diff --git a/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql b/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql index 3165a714a7..5e6108fc9b 100644 --- a/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql +++ b/deployment/postgres-init-db/sql/tables/merlin/mission_model.sql @@ -53,7 +53,7 @@ comment on column merlin.mission_model.created_at is e'' comment on column merlin.mission_model.description is e'' 'A human-meaningful description of the mission model.'; comment on column merlin.mission_model.default_view_id is e'' - 'The ID of an option default view for the mission model.'; + 'The ID of an optional default view for the mission model.'; create trigger increment_revision_mission_model_update before update on merlin.mission_model