From c0cd272c2977cf62f6207238e74a697f2d1c33af Mon Sep 17 00:00:00 2001 From: Guilherme_F Date: Wed, 26 Jun 2024 11:03:30 +0100 Subject: [PATCH] Fixes --- code/client/src/domain/editor/fugue/FugueTree.ts | 4 ++-- code/server/sql/create_tables.sql | 15 ++++++++++++++- code/server/sql/triggers/resource_delete.sql | 5 ----- code/server/sql/triggers/resource_insert.sql | 4 ---- code/server/sql/triggers/resource_update.sql | 4 ---- code/server/sql/triggers/workspace_insert.sql | 5 ----- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/code/client/src/domain/editor/fugue/FugueTree.ts b/code/client/src/domain/editor/fugue/FugueTree.ts index d9ca0ad0..d4a584cc 100644 --- a/code/client/src/domain/editor/fugue/FugueTree.ts +++ b/code/client/src/domain/editor/fugue/FugueTree.ts @@ -36,7 +36,7 @@ export class FugueTree { // create node const node: Node = treeNode(id, value, parent, side, 0, styles as InlineStyle[]); if (value === '\n') { - this._root.value.splice(line, 0, node); // TODO: check if this is correct + this._root.value.splice(line, 0, node); } this._addNode(node); } @@ -85,7 +85,7 @@ export class FugueTree { if (!node.isDeleted) node.isDeleted = true; if (node.value === '\n') { const idx = this._root.value.findIndex(n => n.id === id); - this._root.value.splice(idx, 1); // TODO: check if this is correct + this._root.value.splice(idx, 1); } } diff --git a/code/server/sql/create_tables.sql b/code/server/sql/create_tables.sql index 9719bfaf..43351390 100644 --- a/code/server/sql/create_tables.sql +++ b/code/server/sql/create_tables.sql @@ -12,7 +12,7 @@ begin; members text[] not null default '{}'::text[] -- references "user"(email) ); - create table if not exists resource ( + create table if not exists resource( id char(16) primary key default encode(gen_random_bytes(8), 'hex'), workspace char(16) not null references workspace(id) on delete cascade, name text not null, @@ -30,4 +30,17 @@ begin; created_at timestamp not null default now() ); + -- Triggers + create or replace trigger on_workspace_insert_trigger + after insert on workspace + for each row execute function add_root_resource(); + + create or replace trigger on_resource_delete_trigger + after delete on resource + for each row execute function on_child_removed(); + + create or replace trigger on_resource_update_trigger + after update on resource + for each row execute function on_child_updated(); + commit; \ No newline at end of file diff --git a/code/server/sql/triggers/resource_delete.sql b/code/server/sql/triggers/resource_delete.sql index 0931aa2b..9a050f62 100644 --- a/code/server/sql/triggers/resource_delete.sql +++ b/code/server/sql/triggers/resource_delete.sql @@ -12,9 +12,4 @@ begin; return old; end; $$ language plpgsql; - - create or replace trigger on_resource_delete_trigger - after delete on resource - for each row execute function on_child_removed(); - commit; \ No newline at end of file diff --git a/code/server/sql/triggers/resource_insert.sql b/code/server/sql/triggers/resource_insert.sql index d02120c6..1a450c60 100644 --- a/code/server/sql/triggers/resource_insert.sql +++ b/code/server/sql/triggers/resource_insert.sql @@ -30,8 +30,4 @@ begin; end if; end; $$ language plpgsql; - - create or replace trigger on_resource_insert_trigger - after insert on resource - for each row execute function on_new_resource_created(); commit; \ No newline at end of file diff --git a/code/server/sql/triggers/resource_update.sql b/code/server/sql/triggers/resource_update.sql index 98188c0e..e02a3102 100644 --- a/code/server/sql/triggers/resource_update.sql +++ b/code/server/sql/triggers/resource_update.sql @@ -20,8 +20,4 @@ begin; return new; end; $$ language plpgsql; - - create or replace trigger on_resource_update_trigger - after update on resource - for each row execute function on_child_updated(); commit ; \ No newline at end of file diff --git a/code/server/sql/triggers/workspace_insert.sql b/code/server/sql/triggers/workspace_insert.sql index 466ea371..9ec47e93 100644 --- a/code/server/sql/triggers/workspace_insert.sql +++ b/code/server/sql/triggers/workspace_insert.sql @@ -8,9 +8,4 @@ begin; return new; end; $$ language plpgsql; - - create or replace trigger on_workspace_insert_trigger - after insert on workspace - for each row execute function add_root_resource(); - commit; \ No newline at end of file