From a52dd6b509a7ea4aa1f5bbcf3c63ebd902b635d4 Mon Sep 17 00:00:00 2001 From: Theresa Kamerman Date: Thu, 14 Sep 2023 15:22:14 -0700 Subject: [PATCH] Add new Plan Snapshot metadata - add description column - add association table "plan_snapshot_tags" --- .../tables/metadata/plan_snapshot_tags.yaml | 48 +++++++++++++++++++ .../tables/public_plan_snapshot.yaml | 26 ++++++++++ .../databases/AerieMerlin/tables/tables.yaml | 1 + .../27_snapshot_tags_description/down.sql | 2 + .../27_snapshot_tags_description/up.sql | 18 +++++++ merlin-server/sql/merlin/init.sql | 1 + .../tables/metadata/plan_snapshot_tags.sql | 13 +++++ .../sql/merlin/tables/plan_snapshot.sql | 3 ++ 8 files changed, 112 insertions(+) create mode 100644 deployment/hasura/metadata/databases/AerieMerlin/tables/metadata/plan_snapshot_tags.yaml create mode 100644 merlin-server/sql/merlin/tables/metadata/plan_snapshot_tags.sql diff --git a/deployment/hasura/metadata/databases/AerieMerlin/tables/metadata/plan_snapshot_tags.yaml b/deployment/hasura/metadata/databases/AerieMerlin/tables/metadata/plan_snapshot_tags.yaml new file mode 100644 index 0000000000..71588a9e73 --- /dev/null +++ b/deployment/hasura/metadata/databases/AerieMerlin/tables/metadata/plan_snapshot_tags.yaml @@ -0,0 +1,48 @@ +table: + name: plan_snapshot_tags + schema: metadata +configuration: + custom_name: "plan_snapshot_tags" +object_relationships: + - name: plan_snapshot + using: + foreign_key_constraint_on: snapshot_id + - name: tag + using: + foreign_key_constraint_on: tag_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: [snapshot_id, tag_id] + check: {} + - role: user + permission: + columns: [snapshot_id, tag_id] + check: {"plan_snapshot":{"plan":{"_or":[ + {"owner":{"_eq":"X-Hasura-User-Id"}}, + {"collaborators":{"collaborator":{"_eq":"X-Hasura-User-Id"}}}]}}} +delete_permissions: + - role: aerie_admin + permission: + filter: {} + - role: user + permission: + filter: {"plan_snapshot":{"plan":{"_or":[ + {"owner":{"_eq":"X-Hasura-User-Id"}}, + {"collaborators":{"collaborator":{"_eq":"X-Hasura-User-Id"}}}]}}} diff --git a/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan_snapshot.yaml b/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan_snapshot.yaml index 796a58f2ae..9ac1b2213c 100644 --- a/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan_snapshot.yaml +++ b/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan_snapshot.yaml @@ -11,6 +11,21 @@ object_relationships: remote_table: name: plan schema: public +array_relationships: + - name: activities + using: + foreign_key_constraint_on: + column: snapshot_id + table: + name: plan_snapshot_activities + schema: public + - name: tags + using: + foreign_key_constraint_on: + column: snapshot_id + table: + name: plan_snapshot_tags + schema: metadata select_permissions: - role: aerie_admin permission: @@ -27,6 +42,17 @@ select_permissions: columns: '*' filter: {} allow_aggregations: true +update_permissions: + - role: aerie_admin + permission: + columns: [description, taken_by] + filter: {} + - role: user + permission: + columns: [description] + filter: {"plan":{"_or":[ + {"owner":{"_eq":"X-Hasura-User-Id"}}, + {"collaborators":{"collaborator":{"_eq":"X-Hasura-User-Id"}}}]}} delete_permissions: - role: aerie_admin permission: diff --git a/deployment/hasura/metadata/databases/AerieMerlin/tables/tables.yaml b/deployment/hasura/metadata/databases/AerieMerlin/tables/tables.yaml index 059bf78aa8..86c854428e 100644 --- a/deployment/hasura/metadata/databases/AerieMerlin/tables/tables.yaml +++ b/deployment/hasura/metadata/databases/AerieMerlin/tables/tables.yaml @@ -52,6 +52,7 @@ - "!include metadata/tags.yaml" - "!include metadata/activity_directive_tags.yaml" - "!include metadata/constraint_tags.yaml" +- "!include metadata/plan_snapshot_tags.yaml" - "!include metadata/plan_tags.yaml" - "!include metadata/snapshot_activity_tags.yaml" - "!include metadata/users_allowed_roles.yaml" diff --git a/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql b/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql index cf6def7d9c..fa7f249889 100644 --- a/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql +++ b/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql @@ -1,3 +1,5 @@ +drop table metadata.plan_snapshot_tags; +alter table plan_snapshot drop column description; alter table plan drop column description; call migrations.mark_migration_rolled_back('27'); diff --git a/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/up.sql b/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/up.sql index 7d3655f058..f5024777eb 100644 --- a/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/up.sql +++ b/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/up.sql @@ -3,4 +3,22 @@ alter table plan comment on column plan.description is e'' 'A human-readable description for this plan and its contents.'; +alter table plan_snapshot + add column description text; +comment on column plan_snapshot.description is e'' + 'A human-readable description of the snapshot and its contents.'; + +create table metadata.plan_snapshot_tags( + snapshot_id integer not null references public.plan_snapshot + on update cascade + on delete cascade, + tag_id integer not null references metadata.tags + on update cascade + on delete cascade, + primary key (snapshot_id, tag_id) +); +comment on table metadata.plan_snapshot_tags is e'' + 'The tags associated with a specific. Note: these tags will not be compared in a merge ' + 'and will not be applied to the plan if the snapshot is restored.'; + call migrations.mark_migration_applied('27'); diff --git a/merlin-server/sql/merlin/init.sql b/merlin-server/sql/merlin/init.sql index 29a0a652d1..bd2a17fc57 100644 --- a/merlin-server/sql/merlin/init.sql +++ b/merlin-server/sql/merlin/init.sql @@ -83,6 +83,7 @@ begin; -- Table-specific Metadata \ir tables/metadata/activity_directive_tags.sql \ir tables/metadata/constraint_tags.sql + \ir tables/metadata/plan_snapshot_tags.sql \ir tables/metadata/plan_tags.sql \ir tables/metadata/snapshot_activity_tags.sql diff --git a/merlin-server/sql/merlin/tables/metadata/plan_snapshot_tags.sql b/merlin-server/sql/merlin/tables/metadata/plan_snapshot_tags.sql new file mode 100644 index 0000000000..65980e07ca --- /dev/null +++ b/merlin-server/sql/merlin/tables/metadata/plan_snapshot_tags.sql @@ -0,0 +1,13 @@ +create table metadata.plan_snapshot_tags( + snapshot_id integer not null references public.plan_snapshot + on update cascade + on delete cascade, + tag_id integer not null references metadata.tags + on update cascade + on delete cascade, + primary key (snapshot_id, tag_id) +); + +comment on table metadata.plan_snapshot_tags is e'' + 'The tags associated with a specific. Note: these tags will not be compared in a merge ' + 'and will not be applied to the plan if the snapshot is restored.'; diff --git a/merlin-server/sql/merlin/tables/plan_snapshot.sql b/merlin-server/sql/merlin/tables/plan_snapshot.sql index 65be5cfb00..c521ae427c 100644 --- a/merlin-server/sql/merlin/tables/plan_snapshot.sql +++ b/merlin-server/sql/merlin/tables/plan_snapshot.sql @@ -11,6 +11,7 @@ create table plan_snapshot( revision integer not null, snapshot_name text, + description text, taken_by text, taken_at timestamptz not null default now(), constraint snapshot_name_unique_per_plan @@ -27,6 +28,8 @@ comment on column plan_snapshot.revision is e'' 'The revision of the plan at the time the snapshot was taken.'; comment on column plan_snapshot.snapshot_name is e'' 'A human-readable name for the snapshot.'; +comment on column plan_snapshot.description is e'' + 'A human-readable description of the snapshot and its contents.'; comment on column plan_snapshot.taken_by is e'' 'The user who took the snapshot.'; comment on column plan_snapshot.taken_at is e''