-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seen sources now reflects what the plan owners/contributors have acknowledged as having been added to derivation groups associated with the plan in question.
- Loading branch information
1 parent
03d8eaf
commit bd71c4a
Showing
4 changed files
with
120 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 31 additions & 20 deletions
51
deployment/postgres-init-db/sql/tables/ui/seen_sources.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
create table ui.seen_sources | ||
( | ||
username text not null, | ||
external_source_name text not null, | ||
derivation_group text not null, | ||
external_source_type text not null, -- included for ease of filtering in the UI | ||
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 (username, external_source_name, derivation_group), | ||
constraint seen_sources_references_user | ||
foreign key (username) | ||
references permissions.users (username) match simple | ||
on delete cascade, | ||
constraint seen_sources_references_external_source | ||
foreign key (external_source_name, derivation_group) | ||
references merlin.external_source (key, derivation_group_name) match simple | ||
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 the external sources either acknowledged by each user.'; | ||
'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.username is e'' | ||
'The username of the user that has seen the given source referenced by this entry.\n' | ||
'A foreign key referencing the permissions.users table.'; | ||
comment on column ui.seen_sources.external_source_name is e'' | ||
'The name of the external_source that the user is being marked as having seen in this entry.'; | ||
comment on column ui.seen_sources.external_source_type is e'' | ||
'The external_source_type of the external_source that the user is being marked as having seen in this entry.'; | ||
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(); |