Skip to content

Commit

Permalink
Add new Plan Snapshot metadata
Browse files Browse the repository at this point in the history
- add description column
- add association table "plan_snapshot_tags"
  • Loading branch information
Mythicaeda committed Sep 19, 2023
1 parent b050479 commit a52dd6b
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"}}}]}}}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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');
1 change: 1 addition & 0 deletions merlin-server/sql/merlin/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions merlin-server/sql/merlin/tables/metadata/plan_snapshot_tags.sql
Original file line number Diff line number Diff line change
@@ -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.';
3 changes: 3 additions & 0 deletions merlin-server/sql/merlin/tables/plan_snapshot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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''
Expand Down

0 comments on commit a52dd6b

Please sign in to comment.