#!/usr/bin/env bash
# Run ON gex44 (read-only SELECT): OMG briefs built with a library pack -> JSON on stdout. tools/usage_pull.sh calls it over ssh.
docker exec forge-corp-factory-pg sh -c "psql -U \$POSTGRES_USER -d forge_corp_factory -At -c \"select coalesce(json_agg(x),'[]'::json) from (select a.id brief_id, a.submitted_at ts, a.meta->>'title' title, a.status, a.meta->'game_library'->'releases' releases, (select json_agg(json_build_object('slug',r.project_slug,'deploy_url',r.deploy_url,'status',r.status) order by r.started_at) from pipeline_runs r where r.brief_id=a.id) runs from app_briefs a where a.meta::text like '%game_library%' order by a.submitted_at) x;\""
