$date = CAST(CurrentUtcTimestamp() AS double) / 1000000;
$systems = ('arcanum', '');

$files = (
SELECT
    system,
    repository,
    commit,
    file
FROM
    hahn.`home/devtools/watchdog_prod/manifests/manifest`
WHERE
    system IN $systems
    AND String::ToLower(file) LIKE '%readme.md'
    AND NOT(file LIKE 'junk%')
);

$requered_commits_table  = (
SELECT
    system,
    repository,
    MAX_BY(commit, commit_date) as commit
FROM
    hahn.`home/devtools/watchdog_prod/manifests/repositories`
WHERE
    commit_date <= $date
    AND system IN $systems
GROUP BY
    repository, system
);


SELECT
    requered_commits.repository || files.file AS full_path,
    files.file as path
FROM
    $files as files
INNER JOIN
    $requered_commits_table AS requered_commits
ON
    files.system = requered_commits.system
    AND files.repository = requered_commits.repository
    AND files.commit = requered_commits.commit
