public function getLeafNodes($app = null)
    {
        $leaves = [];

        foreach ($this->nodes as $appName => $nodes) {
            if (!is_null($app) && $app != $appName) {
                continue;
            }
            foreach ($nodes as $name => $migration) {
                // get the nodes  children
                $children = $this->getNodeFamilyTree(
                    $appName,
                    $name
                )->children;

                // if no children exist this must be the latest migration
                // or if it has children and none of them is for app we are
                // checking then this is the latest migrations
                $isLatest = true;
                foreach ($children as $child) {
                    if ($child->appName == $appName) {
                        $isLatest = false;
                    }
                }

                if ($isLatest) {
                    if (!is_null($app)) {
                        $leaves[] = $name;
                    } else {
                        $leaves[$appName][] = $name;
                    }
                }
            }
        }

        return $leaves;
    }