Skip to content

Commit

Permalink
feat: add project_attachment table
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepehr-Sobhani committed May 12, 2023
1 parent f4a1a0f commit 5ed430b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
42 changes: 42 additions & 0 deletions schema/deploy/tables/project_attachment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- Deploy cif:tables/project_attachment to pg
-- requires: tables/project
-- requires: tables/attachment

begin;

create table cif.project_attachment
(
id integer primary key generated always as identity,
project_id integer not null references cif.project(id),
attachment_id integer not null references cif.attachment(id)
);

select cif_private.upsert_timestamp_columns('cif', 'project_attachment');

create unique index project_attachment_project_id_attachment_id_unique_index
on cif.project_attachment (project_id, attachment_id)
where archived_at is null;

do
$grant$
begin

-- Grant cif_internal permissions
perform cif_private.grant_permissions('select', 'project_attachment', 'cif_internal');
perform cif_private.grant_permissions('insert', 'project_attachment', 'cif_internal');
perform cif_private.grant_permissions('update', 'project_attachment', 'cif_internal');

-- Grant cif_admin permissions
perform cif_private.grant_permissions('select', 'project_attachment', 'cif_admin');
perform cif_private.grant_permissions('insert', 'project_attachment', 'cif_admin');
perform cif_private.grant_permissions('update', 'project_attachment', 'cif_admin');

end
$grant$;

comment on table cif.project_attachment is 'Join table to track assignment of attachments to projects';
comment on column cif.project_attachment.id is 'Unique ID for the project attachment record';
comment on column cif.project_attachment.project_id is 'Foreign key to the project';
comment on column cif.project_attachment.attachment_id is 'Foreign key to the attachment';

commit;
7 changes: 7 additions & 0 deletions schema/revert/tables/project_attachment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert cif:tables/project_attachment from pg

begin;

drop table cif.project_attachment;

commit;
1 change: 1 addition & 0 deletions schema/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,4 @@ mutations/commit_project_revision [mutations/[email protected]] 2023
@1.7.3 2023-05-02T23:54:44Z Sepehr Sobhani <[email protected]> # release v1.7.3
computed_columns/form_change_rank 2023-05-01T17:39:07Z Brianna Cerkiewicz <briannacerkiewicz@pop-os> # Add form_change_rank computed column to replace project_revision_rank
computed_columns/project_revision_rank [computed_columns/[email protected]] 2023-05-01T22:38:14Z Brianna Cerkiewicz <briannacerkiewicz@pop-os> # Remove project_revision_rank
tables/project_attachment [tables/project tables/attachment] 2023-04-25T22:08:32Z Sepehr Sobhani <[email protected]> # Join table to hold the relation between attachment and project table
17 changes: 17 additions & 0 deletions schema/verify/tables/project_attachment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Verify cif:tables/project_attachment on pg

begin;

select pg_catalog.has_table_privilege('cif.project_attachment', 'select');

-- cif_internal Grants
select cif_private.verify_grant('select', 'project_attachment', 'cif_internal');
select cif_private.verify_grant('insert', 'project_attachment', 'cif_internal');
select cif_private.verify_grant('update', 'project_attachment', 'cif_internal');

-- cif_admin Grants
select cif_private.verify_grant('select', 'project_attachment', 'cif_admin');
select cif_private.verify_grant('insert', 'project_attachment', 'cif_admin');
select cif_private.verify_grant('update', 'project_attachment', 'cif_admin');

rollback;

0 comments on commit 5ed430b

Please sign in to comment.