Thursday, 19 September 2013

MySQL table structure for task manager app with task dependencies

MySQL table structure for task manager app with task dependencies

I need to design a 'task manager' table structure where task can be
dependent on other tasks. For example I can have following tasks:
TASK A: independent
TASK B: independent
TASK C: can not start before TASK B is finished
TASK D: independenet
TESK E: can not start before TASK C and TASK E are finished
Each task has standard properties (started_by, assigned_to, due_date,
description, status). I want to have a table structure that would allow me
to do this query easily:
Select all user's open tasks, but select only those who can already be
started (meaning in above scenario TASK C and E can not be selected here
until dependency tasks are completed).
Currently my solution is to have 2 tables:
tasks: table that hold tasks records
task_dependencies: table that holds task to task dependencies (id,
task_id, dependent_task_id)
My current query for above scenario and my current table structure goes
like this:
SELECT description, from_unixtime( date_due )
FROM tasks
WHERE
assigned_user_id = 751
AND status_id = 'Q'
AND id NOT
IN (
SELECT TD.task_id
FROM task_dependencies TD
INNER JOIN tasks T ON TD.dependent_task_id = T.id
AND T.status_id = 'Q')
ORDER BY date_due
-- status 'Q' = new uncompleted task
This get's me the right result, but is this the right way to go or should
I make better table structure and/or query?
Here is also SQL fiddle for above scenario.

No comments:

Post a Comment