diff --git a/deployment/hasura/metadata/databases/tables/merlin/plan_derivation_group.yaml b/deployment/hasura/metadata/databases/tables/merlin/plan_derivation_group.yaml index 893b28defa..b52619afe0 100644 --- a/deployment/hasura/metadata/databases/tables/merlin/plan_derivation_group.yaml +++ b/deployment/hasura/metadata/databases/tables/merlin/plan_derivation_group.yaml @@ -29,25 +29,58 @@ select_permissions: insert_permissions: - role: aerie_admin permission: - columns: [plan_id, derivation_group_name] + columns: [plan_id, derivation_group_name, last_acknowledged_at] check: {} - role: user permission: - columns: [plan_id, derivation_group_name] - check: {} + columns: [plan_id, derivation_group_name, last_acknowledged_at] + check: { + "plan": { + "_or": [ + { + "owner": { "_eq": "X-Hasura-User-Id" } + }, + { + "collaborators": { "collaborator": { "_eq": "X-Hasura-User-Id" } } + } + ] + } + } update_permissions: - role: aerie_admin permission: - columns: [plan_id, derivation_group_name] + columns: [ last_acknowledged_at ] filter: {} - role: user permission: - columns: [] - filter: {} + columns: [ last_acknowledged_at ] + filter: { + "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: {} + filter: { + "plan": { + "_or": [ + { + "owner": { "_eq": "X-Hasura-User-Id" } + }, + { + "collaborators": { "collaborator": { "_eq": "X-Hasura-User-Id" } } + } + ] + } + } diff --git a/deployment/hasura/metadata/databases/tables/tables.yaml b/deployment/hasura/metadata/databases/tables/tables.yaml index 14c73dc7cf..1275d9a4b2 100644 --- a/deployment/hasura/metadata/databases/tables/tables.yaml +++ b/deployment/hasura/metadata/databases/tables/tables.yaml @@ -176,5 +176,4 @@ - "!include ui/extension_roles.yaml" - "!include ui/extensions.yaml" - "!include ui/view.yaml" -- "!include ui/seen_sources.yaml" - "!include ui/derivation_group_comp.yaml" diff --git a/deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml b/deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml deleted file mode 100644 index 9fab4f5e4f..0000000000 --- a/deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml +++ /dev/null @@ -1,58 +0,0 @@ -table: - name: seen_sources - schema: ui -configuration: - custom_name: "seen_sources" -object_relationships: - - name: plan_derivation_group - using: - foreign_key_constraint_on: - - plan_id - - derivation_group_name -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: {} -update_permissions: - - role: aerie_admin - permission: - columns: [last_acknowledged_at] - filter: {} - - role: user - permission: - columns: [last_acknowledged_at] - filter: { - "plan_derivation_group": { - "plan":{ - "_or":[ - { - "owner":{"_eq":"X-Hasura-User-Id" } - }, - { - "collaborators":{"collaborator":{"_eq":"X-Hasura-User-Id"}} - } - ] - } - } - } -delete_permissions: - - role: aerie_admin - permission: - filter: {} diff --git a/deployment/postgres-init-db/sql/init.sql b/deployment/postgres-init-db/sql/init.sql index 093a2c68ff..7b535a53cd 100644 --- a/deployment/postgres-init-db/sql/init.sql +++ b/deployment/postgres-init-db/sql/init.sql @@ -32,7 +32,6 @@ begin; -- UI views that depend on Merlin schema \ir views/ui/derivation_group_comp.sql - \ir tables/ui/seen_sources.sql -- Scheduling \ir init_scheduler.sql diff --git a/deployment/postgres-init-db/sql/tables/merlin/external_events/plan_derivation_group.sql b/deployment/postgres-init-db/sql/tables/merlin/external_events/plan_derivation_group.sql index 67fd74749f..dfe80bd878 100644 --- a/deployment/postgres-init-db/sql/tables/merlin/external_events/plan_derivation_group.sql +++ b/deployment/postgres-init-db/sql/tables/merlin/external_events/plan_derivation_group.sql @@ -1,6 +1,7 @@ create table merlin.plan_derivation_group ( plan_id integer not null, derivation_group_name text not null, + last_acknowledged_at timestamp with time zone default now() not null, constraint plan_derivation_group_pkey primary key (plan_id, derivation_group_name), @@ -13,12 +14,15 @@ create table merlin.plan_derivation_group ( ); comment on table merlin.plan_derivation_group is e'' - 'Links externally imported event sources & plans.'; + 'Links externally imported event sources & plans.\n' + 'Additionally, tracks the last time a plan owner/contributor(s) have acknowledged additions to the derivation group.\n'; comment on column merlin.plan_derivation_group.plan_id is e'' 'The plan with which the derivation group is associated.'; comment on column merlin.plan_derivation_group.derivation_group_name is e'' 'The derivation group being associated with the plan.'; +comment on column merlin.plan_derivation_group.last_acknowledged_at is e'' + 'The time at which changes to the derivation group were last acknowledged.'; -- if an external source is linked to a plan it cannot be deleted create function merlin.external_source_pdg_association_delete() diff --git a/deployment/postgres-init-db/sql/tables/ui/seen_sources.sql b/deployment/postgres-init-db/sql/tables/ui/seen_sources.sql deleted file mode 100644 index 57881e0ee8..0000000000 --- a/deployment/postgres-init-db/sql/tables/ui/seen_sources.sql +++ /dev/null @@ -1,40 +0,0 @@ -create table ui.seen_sources -( - plan_id integer not null, - derivation_group_name text not null, - last_acknowledged_at timestamp with time zone default now() not null, - - constraint seen_sources_pkey - primary key (plan_id, derivation_group_name), - constraint seen_sources_references_plan_derivation_group - foreign key (plan_id, derivation_group_name) - references merlin.plan_derivation_group (plan_id, derivation_group_name) - on delete cascade -); - -comment on table ui.seen_sources is e'' - 'Tracks whether a plan (specifically any of its contributors/owners) has acknowledged that a source is now associated with a plan by virtue of being a member of an associated derivation group.\n' - 'Membership indicates that the new source has been acknowledged and is now understood to be a member.\n' - 'A source in external_source that is part of a derivation group associated with this plan but not in this table is unacknowledged.\n' - 'Acknowledgements are performed in the UI, and upon doing so new entries are appended to this table.'; - -comment on column ui.seen_sources.plan_id is e'' - 'The plan that any new source is now associated with by virtue of being a member of the named derivation group.'; -comment on column ui.seen_sources.derivation_group_name is e'' - 'The derivation group of the plan is associated with.'; -comment on column ui.seen_sources.last_acknowledged_at is e'' - 'The time at which changes to the derivation group were last acknowledged.'; - --- add a trigger that adds to seen sources whenever an association is made -create function ui.add_seen_source_on_assoc() - returns trigger - language plpgsql as $$ -begin - insert into ui.seen_sources values (new.plan_id, new.derivation_group_name); - return new; -end; -$$; - -create trigger add_seen_source_on_assoc -after insert on merlin.plan_derivation_group - for each row execute function ui.add_seen_source_on_assoc();