From b0504791e05571e7c1bba14aa6ed37969ee0dd03 Mon Sep 17 00:00:00 2001 From: Theresa Kamerman Date: Thu, 14 Sep 2023 15:21:02 -0700 Subject: [PATCH 1/2] Add description to plans --- .../metadata/databases/AerieMerlin/tables/public_plan.yaml | 4 ++-- .../AerieMerlin/27_snapshot_tags_description/down.sql | 3 +++ .../AerieMerlin/27_snapshot_tags_description/up.sql | 6 ++++++ merlin-server/sql/merlin/applied_migrations.sql | 1 + merlin-server/sql/merlin/tables/plan.sql | 3 +++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql create mode 100644 deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/up.sql diff --git a/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan.yaml b/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan.yaml index 984874689d..0ccc303630 100644 --- a/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan.yaml +++ b/deployment/hasura/metadata/databases/AerieMerlin/tables/public_plan.yaml @@ -111,13 +111,13 @@ insert_permissions: update_permissions: - role: aerie_admin permission: - columns: [name, owner, duration, model_id, parent_id, start_time] + columns: [name, owner, duration, model_id, parent_id, start_time, description] filter: {} set: updated_by: "x-hasura-user-id" - role: user permission: - columns: [name, owner] + columns: [name, owner, description] filter: {"owner":{"_eq":"X-Hasura-User-Id"}} set: updated_by: "x-hasura-user-id" diff --git a/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql b/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql new file mode 100644 index 0000000000..cf6def7d9c --- /dev/null +++ b/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/down.sql @@ -0,0 +1,3 @@ +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 new file mode 100644 index 0000000000..7d3655f058 --- /dev/null +++ b/deployment/hasura/migrations/AerieMerlin/27_snapshot_tags_description/up.sql @@ -0,0 +1,6 @@ +alter table plan + add column description text; +comment on column plan.description is e'' + 'A human-readable description for this plan and its contents.'; + +call migrations.mark_migration_applied('27'); diff --git a/merlin-server/sql/merlin/applied_migrations.sql b/merlin-server/sql/merlin/applied_migrations.sql index ca39d215ef..63c2754eaa 100644 --- a/merlin-server/sql/merlin/applied_migrations.sql +++ b/merlin-server/sql/merlin/applied_migrations.sql @@ -29,3 +29,4 @@ call migrations.mark_migration_applied('23'); call migrations.mark_migration_applied('24'); call migrations.mark_migration_applied('25'); call migrations.mark_migration_applied('26'); +call migrations.mark_migration_applied('27'); diff --git a/merlin-server/sql/merlin/tables/plan.sql b/merlin-server/sql/merlin/tables/plan.sql index 448efb553b..67f84cff07 100644 --- a/merlin-server/sql/merlin/tables/plan.sql +++ b/merlin-server/sql/merlin/tables/plan.sql @@ -18,6 +18,7 @@ create table plan ( owner text, updated_by text, + description text, constraint plan_synthetic_key primary key (id), @@ -72,6 +73,8 @@ comment on column plan.owner is e'' 'The user who owns the plan.'; comment on column plan.updated_by is e'' 'The user who last updated the plan.'; +comment on column plan.description is e'' + 'A human-readable description for this plan and its contents.'; create function increment_revision_on_update_plan() From a52dd6b509a7ea4aa1f5bbcf3c63ebd902b635d4 Mon Sep 17 00:00:00 2001 From: Theresa Kamerman Date: Thu, 14 Sep 2023 15:22:14 -0700 Subject: [PATCH 2/2] 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''