CREATE TABLE task_element_links ( task_id uuid NOT NULL REFERENCES tasks (id), element_id uuid NOT NULL REFERENCES elements (id), created_by uuid NOT NULL REFERENCES auth_accounts (id), created_at timestamptz NOT NULL DEFAULT now(), PRIMARY KEY (task_id, element_id) ); CREATE TABLE task_dependencies ( task_id uuid NOT NULL REFERENCES tasks (id), depends_on_task_id uuid NOT NULL REFERENCES tasks (id), created_by uuid NOT NULL REFERENCES auth_accounts (id), created_at timestamptz NOT NULL DEFAULT now(), PRIMARY KEY (task_id, depends_on_task_id), CONSTRAINT task_dependencies_not_self CHECK (task_id <> depends_on_task_id) );