Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: activity.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const countSquadMemberHandoffsSince = `-- name: CountSquadMemberHandoffsSince :one
SELECT count(*) FROM activity_log
WHERE issue_id = $1
AND action = 'squad_handoff'
AND details->>'kind' = 'member'
AND created_at > $2
`
type CountSquadMemberHandoffsSinceParams struct {
IssueID pgtype.UUID `json:"issue_id"`
Since pgtype.Timestamptz `json:"since"`
}
func (q *Queries) CountSquadMemberHandoffsSince(ctx context.Context, arg CountSquadMemberHandoffsSinceParams) (int64, error) {
row := q.db.QueryRow(ctx, countSquadMemberHandoffsSince, arg.IssueID, arg.Since)
var count int64
err := row.Scan(&count)
return count, err
}
const createActivity = `-- name: CreateActivity :one
INSERT INTO activity_log (
workspace_id, issue_id, actor_type, actor_id, action, details, id
) VALUES ($1, $2, $3, $4, $5, $6, COALESCE($7::uuid, gen_random_uuid()))
RETURNING id, workspace_id, issue_id, actor_type, actor_id, action, details, created_at
`
type CreateActivityParams struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
IssueID pgtype.UUID `json:"issue_id"`
ActorType pgtype.Text `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
Action string `json:"action"`
Details []byte `json:"details"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) CreateActivity(ctx context.Context, arg CreateActivityParams) (ActivityLog, error) {
row := q.db.QueryRow(ctx, createActivity,
arg.WorkspaceID,
arg.IssueID,
arg.ActorType,
arg.ActorID,
arg.Action,
arg.Details,
arg.ID,
)
var i ActivityLog
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.IssueID,
&i.ActorType,
&i.ActorID,
&i.Action,
&i.Details,
&i.CreatedAt,
)
return i, err
}
const getActivity = `-- name: GetActivity :one
SELECT id, workspace_id, issue_id, actor_type, actor_id, action, details, created_at FROM activity_log
WHERE id = $1
`
func (q *Queries) GetActivity(ctx context.Context, id pgtype.UUID) (ActivityLog, error) {
row := q.db.QueryRow(ctx, getActivity, id)
var i ActivityLog
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.IssueID,
&i.ActorType,
&i.ActorID,
&i.Action,
&i.Details,
&i.CreatedAt,
)
return i, err
}
const getLastIssueStatusChange = `-- name: GetLastIssueStatusChange :one
SELECT actor_type, actor_id FROM activity_log
WHERE issue_id = $1 AND action = 'status_changed'
ORDER BY created_at DESC, id DESC
LIMIT 1
`
type GetLastIssueStatusChangeRow struct {
ActorType pgtype.Text `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
}
// Who last changed an issue's status, and to what: names the mover when an
// agent's status change is refused because the issue left its step (MUL-7420).
func (q *Queries) GetLastIssueStatusChange(ctx context.Context, issueID pgtype.UUID) (GetLastIssueStatusChangeRow, error) {
row := q.db.QueryRow(ctx, getLastIssueStatusChange, issueID)
var i GetLastIssueStatusChangeRow
err := row.Scan(&i.ActorType, &i.ActorID)
return i, err
}
const hasSquadLeaderNoActionEvaluationForTask = `-- name: HasSquadLeaderNoActionEvaluationForTask :one
SELECT EXISTS (
SELECT 1
FROM activity_log
WHERE issue_id = $1
AND actor_type = 'agent'
AND actor_id = $2
AND action = 'squad_leader_evaluated'
AND details->>'outcome' = 'no_action'
AND details->>'task_id' = $3::text
) AS exists
`
type HasSquadLeaderNoActionEvaluationForTaskParams struct {
IssueID pgtype.UUID `json:"issue_id"`
AgentID pgtype.UUID `json:"agent_id"`
TaskID string `json:"task_id"`
}
func (q *Queries) HasSquadLeaderNoActionEvaluationForTask(ctx context.Context, arg HasSquadLeaderNoActionEvaluationForTaskParams) (bool, error) {
row := q.db.QueryRow(ctx, hasSquadLeaderNoActionEvaluationForTask, arg.IssueID, arg.AgentID, arg.TaskID)
var exists bool
err := row.Scan(&exists)
return exists, err
}
const listActivitiesForIssue = `-- name: ListActivitiesForIssue :many
SELECT id, workspace_id, issue_id, actor_type, actor_id, action, details, created_at FROM (
SELECT id, workspace_id, issue_id, actor_type, actor_id, action, details, created_at FROM activity_log
WHERE issue_id = $1
ORDER BY created_at DESC, id DESC
LIMIT $2
) AS recent
ORDER BY created_at ASC, id ASC
`
type ListActivitiesForIssueParams struct {
IssueID pgtype.UUID `json:"issue_id"`
Limit int32 `json:"limit"`
}
// The NEWEST $2 activities for an issue, returned in chronological order.
//
// The cap has to bite at the OLD end, not the new one. The inner query takes
// the window with the keyset ordering (created_at DESC, id DESC), which
// idx_activity_log_issue_keyset (migration 068) satisfies without a sort step —
// it is not an index-only scan, since the index does not cover the columns
// SELECT * needs, so the heap is still read for the rows in the window. The
// outer query re-sorts ascending so every caller keeps the chronological
// contract it already had.
//
// Capping with ORDER BY created_at ASC instead discards the newest rows, which
// made a busy issue's timeline appear to stop at some point in the past with no
// indication anything was missing. Activity is machine-paced (description
// autosave, every agent run, status/assignee changes), so this was reachable in
// normal use, not only on pathological issues (MUL-5492).
func (q *Queries) ListActivitiesForIssue(ctx context.Context, arg ListActivitiesForIssueParams) ([]ActivityLog, error) {
rows, err := q.db.Query(ctx, listActivitiesForIssue, arg.IssueID, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ActivityLog{}
for rows.Next() {
var i ActivityLog
if err := rows.Scan(
&i.ID,
&i.WorkspaceID,
&i.IssueID,
&i.ActorType,
&i.ActorID,
&i.Action,
&i.Details,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listRecentSquadHandoffs = `-- name: ListRecentSquadHandoffs :many
SELECT id, workspace_id, issue_id, actor_type, actor_id, action, details, created_at FROM activity_log
WHERE issue_id = $1
AND action = 'squad_handoff'
ORDER BY created_at DESC, id DESC
LIMIT $2
`
type ListRecentSquadHandoffsParams struct {
IssueID pgtype.UUID `json:"issue_id"`
RowLimit int32 `json:"row_limit"`
}
// The newest squad handoff records on one issue, newest first. Served by
// idx_activity_log_issue_keyset; the action filter is applied to that window.
func (q *Queries) ListRecentSquadHandoffs(ctx context.Context, arg ListRecentSquadHandoffsParams) ([]ActivityLog, error) {
rows, err := q.db.Query(ctx, listRecentSquadHandoffs, arg.IssueID, arg.RowLimit)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ActivityLog{}
for rows.Next() {
var i ActivityLog
if err := rows.Scan(
&i.ID,
&i.WorkspaceID,
&i.IssueID,
&i.ActorType,
&i.ActorID,
&i.Action,
&i.Details,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}