Skip to content

Commit

Permalink
Merge pull request #1526 from NASA-AMMOS/feature/sequence-workspaces
Browse files Browse the repository at this point in the history
Added the backend for sequencing workspaces
  • Loading branch information
cohansen authored Aug 30, 2024
2 parents 2186764 + a4c2b18 commit a2352ae
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ object_relationships:
- name: parcel
using:
foreign_key_constraint_on: parcel_id
- name: workspace
using:
foreign_key_constraint_on: workspace_id
select_permissions:
- role: aerie_admin
permission:
Expand All @@ -26,24 +29,24 @@ select_permissions:
insert_permissions:
- role: aerie_admin
permission:
columns: [definition, seq_json, name, parcel_id]
columns: [definition, seq_json, name, owner, parcel_id, workspace_id]
check: {}
set:
owner: "x-hasura-user-id"
- role: user
permission:
columns: [definition,seq_json, name, parcel_id]
columns: [definition, seq_json, name, owner, parcel_id, workspace_id]
check: {}
set:
owner: "x-hasura-user-id"
update_permissions:
- role: aerie_admin
permission:
columns: [definition,seq_json, name, owner, parcel_id]
columns: [definition, seq_json, name, owner, parcel_id, workspace_id]
filter: {}
- role: user
permission:
columns: [definition,seq_json, name, owner, parcel_id]
columns: [definition, seq_json, name, owner, parcel_id, workspace_id]
filter: { "owner": { "_eq": "x-hasura-user-id" } }
delete_permissions:
- role: aerie_admin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
table:
name: workspace
schema: sequencing
configuration:
custom_name: "workspace"
array_relationships:
- name: user_sequences
using:
foreign_key_constraint_on:
column: workspace_id
table:
name: user_sequence
schema: sequencing
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: [name, owner]
check: {}
set:
owner: "x-hasura-user-id"
updated_by: "x-hasura-user-id"
- role: user
permission:
columns: [name, owner]
check: {}
set:
owner: "x-hasura-user-id"
updated_by: "x-hasura-user-id"
update_permissions:
- role: aerie_admin
permission:
columns: [name, owner]
filter: {}
set:
updated_by: "x-hasura-user-id"
- role: user
permission:
columns: [name, owner]
filter: { "owner": { "_eq": "x-hasura-user-id" } }
set:
updated_by: "x-hasura-user-id"
delete_permissions:
- role: aerie_admin
permission:
filter: {}
- role: user
permission:
filter: {"owner":{"_eq":"x-hasura-user-id"}}
1 change: 1 addition & 0 deletions deployment/hasura/metadata/databases/tables/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
- "!include sequencing/sequence_adaptation.yaml"
- "!include sequencing/sequence_to_simulated_activity.yaml"
- "!include sequencing/user_sequence.yaml"
- "!include sequencing/workspace.yaml"

############
#### UI ####
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
alter table sequencing.user_sequence
drop constraint user_sequence_workspace_id_fkey,
drop column workspace_id;

drop trigger set_timestamp on sequencing.workspace;
drop table sequencing.workspace;

call migrations.mark_migration_rolled_back('9');
66 changes: 66 additions & 0 deletions deployment/hasura/migrations/Aerie/9_sequence_workspaces/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---- Add the new workspace table

create table sequencing.workspace (
id integer generated always as identity,

name text not null,

created_at timestamptz not null default now(),
owner text,
updated_at timestamptz not null default now(),
updated_by text,

constraint workspace_synthetic_key
primary key (id),
foreign key (owner)
references permissions.users
on update cascade
on delete set null,
foreign key (updated_by)
references permissions.users
on update cascade
on delete set null
);

comment on table sequencing.workspace is e''
'A container for multiple sequences.';
comment on column sequencing.workspace.name is e''
'The name of the workspace.';
comment on column sequencing.workspace.owner is e''
'The user responsible for this workspace.';
comment on column sequencing.workspace.created_at is e''
'Time the workspace was created at.';
comment on column sequencing.workspace.updated_at is e''
'Time the workspace was last updated.';
comment on column sequencing.workspace.updated_by is e''
'The user who last updated the workspace.';

create trigger set_timestamp
before update on sequencing.workspace
for each row
execute function util_functions.set_updated_at();

---- Add the new workspace_id column to the user_sequence table

alter table sequencing.user_sequence
add column workspace_id integer,

add foreign key (workspace_id)
references sequencing.parcel (id)
on delete cascade;

comment on column sequencing.user_sequence.workspace_id is e''
'The workspace the sequence is associated with.';

---- Populate the workspace table with a default workspace to contain existing sequences

insert into sequencing.workspace (name, owner)
values ('Workspace 1', 'Aerie Legacy');

update sequencing.user_sequence
set workspace_id = 1;

alter table sequencing.user_sequence
alter column workspace_id set not null;

call migrations.mark_migration_applied('9');
1 change: 1 addition & 0 deletions deployment/postgres-init-db/sql/applied_migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ call migrations.mark_migration_applied('5');
call migrations.mark_migration_applied('6');
call migrations.mark_migration_applied('7');
call migrations.mark_migration_applied('8');
call migrations.mark_migration_applied('9');
1 change: 1 addition & 0 deletions deployment/postgres-init-db/sql/init_sequencing.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ begin;
\ir tables/sequencing/sequence.sql
\ir tables/sequencing/sequence_to_simulated_activity.sql
\ir tables/sequencing/parcel_to_parameter_dictionary.sql
\ir tables/sequencing/workspace.sql
\ir tables/sequencing/user_sequence.sql
\ir tables/sequencing/expanded_sequences.sql

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ create table sequencing.user_sequence (
owner text,
parcel_id integer not null,
updated_at timestamptz not null default now(),
workspace_id integer not null,

constraint user_sequence_primary_key primary key (id),

Expand All @@ -16,6 +17,9 @@ create table sequencing.user_sequence (
foreign key (owner)
references permissions.users
on update cascade
on delete cascade,
foreign key (workspace_id)
references sequencing.workspace (id)
on delete cascade
);

Expand All @@ -35,6 +39,8 @@ comment on column sequencing.user_sequence.parcel_id is e''
'Parcel the user sequence was created with.';
comment on column sequencing.user_sequence.updated_at is e''
'Time the user sequence was last updated.';
comment on column sequencing.user_sequence.workspace_id is e''
'The workspace the sequence is associated with.';

create trigger set_timestamp
before update on sequencing.user_sequence
Expand Down
39 changes: 39 additions & 0 deletions deployment/postgres-init-db/sql/tables/sequencing/workspace.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
create table sequencing.workspace (
id integer generated always as identity,

name text not null,

created_at timestamptz not null default now(),
owner text,
updated_at timestamptz not null default now(),
updated_by text,

constraint workspace_synthetic_key
primary key (id),
foreign key (owner)
references permissions.users
on update cascade
on delete set null,
foreign key (updated_by)
references permissions.users
on update cascade
on delete set null
);

comment on table sequencing.workspace is e''
'A container for multiple sequences.';
comment on column sequencing.workspace.name is e''
'The name of the workspace.';
comment on column sequencing.workspace.owner is e''
'The user responsible for this workspace.';
comment on column sequencing.workspace.created_at is e''
'Time the workspace was created at.';
comment on column sequencing.workspace.updated_at is e''
'Time the workspace was last updated.';
comment on column sequencing.workspace.updated_by is e''
'The user who last updated the workspace.';

create trigger set_timestamp
before update on sequencing.workspace
for each row
execute function util_functions.set_updated_at();

0 comments on commit a2352ae

Please sign in to comment.