-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3627c2
commit 7d31689
Showing
20 changed files
with
83 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
begin ; | ||
|
||
-- Delete all rows from the resources table | ||
delete from resource; | ||
|
||
-- Delete all rows from the workspaces table | ||
delete from workspace; | ||
|
||
commit ; |
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,30 +1,24 @@ | ||
begin; | ||
|
||
create extension if not exists "uuid-ossp"; | ||
create extension if not exists "pgcrypto"; | ||
|
||
create type resource_type as enum ('D', 'F'); | ||
|
||
create table if not exists workspaces ( | ||
create table if not exists workspace ( | ||
id char(12) primary key default encode(gen_random_bytes(8), 'base64'), | ||
name text not null, | ||
created_at timestamp not null default now(), | ||
updated_at timestamp not null default now() | ||
); | ||
|
||
create table if not exists resources ( | ||
create table if not exists resource ( | ||
id char(12) primary key default encode(gen_random_bytes(8), 'base64'), | ||
workspace varchar not null references workspaces(id) on delete cascade, | ||
workspace varchar not null references workspace(id) on delete cascade, | ||
name text not null, | ||
type resource_type not null, | ||
created_at timestamp not null default now(), | ||
updated_at timestamp not null default now() | ||
); | ||
|
||
create table if not exists resources_children ( | ||
parent char(12) not null references resources(id) on delete cascade, | ||
child char(12) not null references resources(id) on delete cascade, | ||
primary key (parent, child) | ||
updated_at timestamp not null default now(), | ||
children char(12)[] not null default '{}', | ||
parent char(12) references resource(id) on delete cascade | ||
); | ||
|
||
commit; |
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,11 +1,7 @@ | ||
begin ; | ||
|
||
drop table if exists resources cascade ; | ||
|
||
drop table if exists workspaces cascade ; | ||
|
||
drop table if exists resources_children cascade ; | ||
|
||
drop type if exists resource_type cascade ; | ||
drop table if exists resource cascade; | ||
drop table if exists workspace cascade; | ||
drop type if exists resource_type cascade; | ||
|
||
commit ; |
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,15 +1,26 @@ | ||
begin ; | ||
|
||
-- Create the trigger function | ||
create or replace function delete_resource_on_child_delete() returns trigger as $$ | ||
begin | ||
delete from resource where id = old.child; | ||
return old; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create trigger delete_resource_trigger | ||
after delete on resource_child | ||
for each row execute function delete_resource_on_child_delete(); | ||
-- create or replace trigger delete_resource_trigger | ||
-- after delete on resource_child | ||
-- for each row execute function delete_resource_on_child_delete(); | ||
|
||
create or replace function create_root_resource_on_workspace_create() returns trigger as $$ | ||
begin | ||
insert into resource (id, name, type, parent, workspace) | ||
values (new.id, 'root', 'F', null, new.id); | ||
return new; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create or replace trigger create_root_resource_trigger | ||
after insert on workspace | ||
for each row execute function create_root_resource_on_workspace_create(); | ||
|
||
commit ; |
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
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
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
Oops, something went wrong.