fix(workflow): resolve definitions in the owning org

This commit is contained in:
sam committed 2026-10-08 20:41:08 +11:00
1 parent 5ec332ac19
commit ee5e052c9f
13 files changed
+630 -29

No files matched your search

@@ -897,24 +897,25 @@ func (q *Queries) ListSources(ctx context.Context) ([]Source, error) {
const listUndispatchedCaptures = `-- name: ListUndispatchedCaptures :many
SELECT c.id, c.source, c.remote_addr, c.content_type, c.headers, c.body, c.authenticated, c.received_at, c.unsigned, c.event_type, c.org_id, c.workspace_id, c.delivery
FROM captures c
WHERE c.source = ANY($1::text[])
WHERE c.org_id = $1 AND c.source = ANY($2::text[])
AND c.event_type <> ''
AND EXISTS (
SELECT 1 FROM bindings b JOIN mappings m ON m.id = b.mapping
WHERE b.source = c.source AND b.status = 'armed' AND m.event_type = c.event_type
WHERE b.org_id = c.org_id AND b.source = c.source AND b.status = 'armed' AND m.event_type = c.event_type
AND NOT EXISTS (SELECT 1 FROM binding_dispatches d WHERE d.binding = b.id AND d.delivery = c.delivery)
)
ORDER BY c.received_at DESC
LIMIT $2
LIMIT $3
`
type ListUndispatchedCapturesParams struct {
OrgID string
Sources []string
EntryLimit int32
}
func (q *Queries) ListUndispatchedCaptures(ctx context.Context, arg ListUndispatchedCapturesParams) ([]Capture, error) {
rows, err := q.db.Query(ctx, listUndispatchedCaptures, arg.Sources, arg.EntryLimit)
rows, err := q.db.Query(ctx, listUndispatchedCaptures, arg.OrgID, arg.Sources, arg.EntryLimit)
if err != nil {
return nil, err
}
@@ -106,6 +106,37 @@ func (q *Queries) InsertResourceHistory(ctx context.Context, arg InsertResourceH
return i, err
}
const listResources = `-- name: ListResources :many
SELECT kind, value, version, updated_at, org_id FROM resources
ORDER BY org_id, kind
`
func (q *Queries) ListResources(ctx context.Context) ([]Resource, error) {
rows, err := q.db.Query(ctx, listResources)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Resource
for rows.Next() {
var i Resource
if err := rows.Scan(
&i.Kind,
&i.Value,
&i.Version,
&i.UpdatedAt,
&i.OrgID,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const lockResourceWrite = `-- name: LockResourceWrite :exec
SELECT pg_advisory_xact_lock(hashtextextended($1::text || '/' || $2::text, 0))
`