diff --git a/database.sql b/database.sql index 3cf77b4..099cbb3 100644 --- a/database.sql +++ b/database.sql @@ -16,5 +16,6 @@ BEGIN; -- Task management and task dependencies \i database/tasks-functions.sql \i database/task-dependencies.sql +\i database/tasks-view.sql COMMIT; diff --git a/database/tasks-functions.sql b/database/tasks-functions.sql index d31994a..fdf4d93 100644 --- a/database/tasks-functions.sql +++ b/database/tasks-functions.sql @@ -78,44 +78,3 @@ END; $update_task$ LANGUAGE plpgsql; - --- --- Task list view --- --- This view contains all fields used to display task lists. --- - -DROP VIEW IF EXISTS tasks_list; -CREATE VIEW tasks_list - AS SELECT t.task_id AS id, t.item_id AS item, t.task_title AS title, - t.task_description AS description, t.task_added AS added_at, - u1.user_view_name AS added_by, - ct.completed_task_time AS completed_at, - u2.user_view_name AS completed_by , - t.task_priority AS priority , - bd.bad_deps AS missing_dependencies , - mtd.trans_missing AS total_missing_dependencies - FROM tasks t - INNER JOIN users_view u1 ON u1.user_id = t.user_id - LEFT OUTER JOIN completed_tasks ct ON ct.task_id = t.task_id - LEFT OUTER JOIN users_view u2 ON u2.user_id = ct.user_id - LEFT OUTER JOIN ( - SELECT td.task_id , COUNT(*) AS bad_deps - FROM task_dependencies td - LEFT OUTER JOIN completed_tasks dct - ON dct.task_id = td.task_id_depends - WHERE dct.task_id IS NULL - GROUP BY td.task_id - ) AS bd ON bd.task_id = t.task_id - LEFT OUTER JOIN ( - SELECT tdn.task_id , COUNT( DISTINCT task_id_copyof ) AS trans_missing - FROM taskdep_nodes tdn - LEFT OUTER JOIN completed_tasks ct - ON ct.task_id = task_id_copyof - WHERE NOT tnode_reverse AND ct.task_id IS NULL - AND tdn.task_id <> tdn.task_id_copyof - GROUP BY tdn.task_id - ) AS mtd ON mtd.task_id = t.task_id; - -GRANT SELECT ON tasks_list TO :webapp_user; - diff --git a/database/tasks-view.sql b/database/tasks-view.sql new file mode 100644 index 0000000..7f1f0e7 --- /dev/null +++ b/database/tasks-view.sql @@ -0,0 +1,41 @@ +-- +-- Task list view +-- +-- This view contains all fields used to display task lists. +-- + +DROP VIEW IF EXISTS tasks_list; +CREATE VIEW tasks_list + AS SELECT t.task_id AS id, t.item_id AS item, t.task_title AS title, + t.task_description AS description, t.task_added AS added_at, + u1.user_view_name AS added_by, + ct.completed_task_time AS completed_at, + u2.user_view_name AS completed_by , + t.task_priority AS priority , + bd.bad_deps AS missing_dependencies , + mtd.trans_missing AS total_missing_dependencies + FROM tasks t + INNER JOIN users_view u1 ON u1.user_id = t.user_id + LEFT OUTER JOIN completed_tasks ct ON ct.task_id = t.task_id + LEFT OUTER JOIN users_view u2 ON u2.user_id = ct.user_id + LEFT OUTER JOIN ( + SELECT td.task_id , COUNT(*) AS bad_deps + FROM task_dependencies td + LEFT OUTER JOIN completed_tasks dct + ON dct.task_id = td.task_id_depends + WHERE dct.task_id IS NULL + GROUP BY td.task_id + ) AS bd ON bd.task_id = t.task_id + LEFT OUTER JOIN ( + SELECT tdn.task_id , COUNT( DISTINCT task_id_copyof ) AS trans_missing + FROM taskdep_nodes tdn + LEFT OUTER JOIN completed_tasks ct + ON ct.task_id = task_id_copyof + WHERE NOT tnode_reverse AND ct.task_id IS NULL + AND tdn.task_id <> tdn.task_id_copyof + GROUP BY tdn.task_id + ) AS mtd ON mtd.task_id = t.task_id; + +GRANT SELECT ON tasks_list TO :webapp_user; + +