From a9035d5be62e22ee42980f2e21534697e9b1d10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 2 Jan 2016 10:47:36 +0100 Subject: [PATCH] Fixed Move to grandparent/sibling Moving a subtask to its grandparent, or making a task a sub-task of one of its siblings, didn't work as expected. While the icons were being updated correctly, the task didn't appear in the right location. That was because, while the cached structure was being updated, the task itself wasn't. --- database/task-containers.sql | 29 +++++++++++++++ ...a6b99068cbf1dd4148d6bd5cb60e926162cfe1.sql | 37 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 database/upgrade/from-bca6b99068cbf1dd4148d6bd5cb60e926162cfe1.sql diff --git a/database/task-containers.sql b/database/task-containers.sql index edb44ad..7403d2c 100644 --- a/database/task-containers.sql +++ b/database/task-containers.sql @@ -139,3 +139,32 @@ REVOKE EXECUTE CREATE TRIGGER tasks_item_au AFTER UPDATE OF item_id ON tasks FOR EACH ROW EXECUTE PROCEDURE tasks_item_au( ); + + +/* + * After an update on some task's logical container, set the task's parent ID. + */ +DROP FUNCTION IF EXISTS tasks_item_au( ) CASCADE; +CREATE FUNCTION tasks_ltc_au( ) + RETURNS TRIGGER + LANGUAGE PLPGSQL + SECURITY DEFINER + AS $tasks_ltc_au$ +BEGIN + UPDATE tasks + SET task_id_parent = ( + SELECT task_id + FROM logical_task_containers + WHERE ltc_id = NEW.ltc_id ) + WHERE task_id = NEW.task_id; + RETURN NEW; +END; +$tasks_ltc_au$; + +REVOKE EXECUTE + ON FUNCTION tasks_ltc_au( ) + FROM PUBLIC; + +CREATE TRIGGER tasks_ltc_au + AFTER UPDATE OF ltc_id ON tasks + FOR EACH ROW EXECUTE PROCEDURE tasks_ltc_au( ); diff --git a/database/upgrade/from-bca6b99068cbf1dd4148d6bd5cb60e926162cfe1.sql b/database/upgrade/from-bca6b99068cbf1dd4148d6bd5cb60e926162cfe1.sql new file mode 100644 index 0000000..b44ea05 --- /dev/null +++ b/database/upgrade/from-bca6b99068cbf1dd4148d6bd5cb60e926162cfe1.sql @@ -0,0 +1,37 @@ +-- +-- Upgrade the database from commit ID bca6b99068cbf1dd4148d6bd5cb60e926162cfe1 +-- +-- Run this from the top-level directory +-- + + +\i database/config.sql +\c :db_name + +BEGIN; + + DROP FUNCTION IF EXISTS tasks_item_au( ) CASCADE; + CREATE FUNCTION tasks_ltc_au( ) + RETURNS TRIGGER + LANGUAGE PLPGSQL + SECURITY DEFINER + AS $tasks_ltc_au$ + BEGIN + UPDATE tasks + SET task_id_parent = ( + SELECT task_id + FROM logical_task_containers + WHERE ltc_id = NEW.ltc_id ) + WHERE task_id = NEW.task_id; + RETURN NEW; + END; + $tasks_ltc_au$; + + REVOKE EXECUTE + ON FUNCTION tasks_ltc_au( ) + FROM PUBLIC; + + CREATE TRIGGER tasks_ltc_au + AFTER UPDATE OF ltc_id ON tasks + FOR EACH ROW EXECUTE PROCEDURE tasks_ltc_au( ); +COMMIT;