mirror of
https://github.com/coder/coder.git
synced 2026-06-04 05:28:20 +00:00
82f525baf3
This PR adds the backend implementation for modifying task prompts. Part of https://github.com/coder/internal/issues/1084 ## Changes - New `UpdateTaskPrompt` database query to update task prompts - New PATCH `/api/v2/tasks/{task}/prompt` endpoint ## Notes This is part 1 of a 2-part PR stack. The frontend UI will be added in a follow-up PR based on this branch (https://github.com/coder/coder/pull/20812). --- 🤖 PR was written by Claude Sonnet 4.5 Thinking using [Coder Mux](https://github.com/coder/cmux) and reviewed by a human 👩
78 lines
1.9 KiB
SQL
78 lines
1.9 KiB
SQL
-- name: InsertTask :one
|
|
INSERT INTO tasks
|
|
(id, organization_id, owner_id, name, workspace_id, template_version_id, template_parameters, prompt, created_at)
|
|
VALUES
|
|
($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
RETURNING *;
|
|
|
|
-- name: UpdateTaskWorkspaceID :one
|
|
UPDATE
|
|
tasks
|
|
SET
|
|
workspace_id = $2
|
|
FROM
|
|
workspaces w
|
|
JOIN
|
|
template_versions tv
|
|
ON
|
|
tv.template_id = w.template_id
|
|
WHERE
|
|
tasks.id = $1
|
|
AND tasks.workspace_id IS NULL
|
|
AND w.id = $2
|
|
AND tv.id = tasks.template_version_id
|
|
RETURNING
|
|
tasks.*;
|
|
|
|
-- name: UpsertTaskWorkspaceApp :one
|
|
INSERT INTO task_workspace_apps
|
|
(task_id, workspace_build_number, workspace_agent_id, workspace_app_id)
|
|
VALUES
|
|
($1, $2, $3, $4)
|
|
ON CONFLICT (task_id, workspace_build_number)
|
|
DO UPDATE SET
|
|
workspace_agent_id = EXCLUDED.workspace_agent_id,
|
|
workspace_app_id = EXCLUDED.workspace_app_id
|
|
RETURNING *;
|
|
|
|
-- name: GetTaskByID :one
|
|
SELECT * FROM tasks_with_status WHERE id = @id::uuid;
|
|
|
|
-- name: GetTaskByWorkspaceID :one
|
|
SELECT * FROM tasks_with_status WHERE workspace_id = @workspace_id::uuid;
|
|
|
|
-- name: GetTaskByOwnerIDAndName :one
|
|
SELECT * FROM tasks_with_status
|
|
WHERE
|
|
owner_id = @owner_id::uuid
|
|
AND deleted_at IS NULL
|
|
AND LOWER(name) = LOWER(@name::text);
|
|
|
|
-- name: ListTasks :many
|
|
SELECT * FROM tasks_with_status tws
|
|
WHERE tws.deleted_at IS NULL
|
|
AND CASE WHEN @owner_id::UUID != '00000000-0000-0000-0000-000000000000' THEN tws.owner_id = @owner_id::UUID ELSE TRUE END
|
|
AND CASE WHEN @organization_id::UUID != '00000000-0000-0000-0000-000000000000' THEN tws.organization_id = @organization_id::UUID ELSE TRUE END
|
|
AND CASE WHEN @status::text != '' THEN tws.status = @status::task_status ELSE TRUE END
|
|
ORDER BY tws.created_at DESC;
|
|
|
|
-- name: DeleteTask :one
|
|
UPDATE tasks
|
|
SET
|
|
deleted_at = @deleted_at::timestamptz
|
|
WHERE
|
|
id = @id::uuid
|
|
AND deleted_at IS NULL
|
|
RETURNING *;
|
|
|
|
|
|
-- name: UpdateTaskPrompt :one
|
|
UPDATE
|
|
tasks
|
|
SET
|
|
prompt = @prompt::text
|
|
WHERE
|
|
id = @id::uuid
|
|
AND deleted_at IS NULL
|
|
RETURNING *;
|