mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
2132c53f28
Creates migration 000409 with the database foundation for pausing and resuming task workspaces. The task_snapshots table stores conversation history (AgentAPI messages) so users can view task logs even when the workspace is stopped. Each task gets one snapshot, overwritten on each pause. Three new build_reason values (task_auto_pause, task_manual_pause, task_resume) let us distinguish task lifecycle events in telemetry and audit logs from regular workspace operations. Uses a regular table rather than UNLOGGED for snapshots. While UNLOGGED would be faster, losing snapshots on database crash creates user confusion (logs disappear until next pause). We can switch to UNLOGGED post-GA if write performance becomes a problem. Closes coder/internal#1250
20 lines
1.2 KiB
SQL
20 lines
1.2 KiB
SQL
-- Create task_snapshots table for storing log snapshots when tasks are paused.
|
|
-- This table holds the conversation history from AgentAPI, allowing users to view
|
|
-- task logs even when the workspace is stopped.
|
|
CREATE TABLE task_snapshots (
|
|
task_id UUID NOT NULL PRIMARY KEY REFERENCES tasks (id) ON DELETE CASCADE,
|
|
log_snapshot JSONB NOT NULL,
|
|
log_snapshot_created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
COMMENT ON TABLE task_snapshots IS 'Stores snapshots of task state when paused, currently limited to conversation history.';
|
|
COMMENT ON COLUMN task_snapshots.task_id IS 'The task this snapshot belongs to.';
|
|
COMMENT ON COLUMN task_snapshots.log_snapshot IS 'Task conversation history in JSON format, allowing users to view logs when the workspace is stopped.';
|
|
COMMENT ON COLUMN task_snapshots.log_snapshot_created_at IS 'When this log snapshot was captured.';
|
|
|
|
-- Add build reasons for task lifecycle events.
|
|
-- These distinguish task pause/resume operations from regular workspace lifecycle events.
|
|
ALTER TYPE build_reason ADD VALUE IF NOT EXISTS 'task_auto_pause';
|
|
ALTER TYPE build_reason ADD VALUE IF NOT EXISTS 'task_manual_pause';
|
|
ALTER TYPE build_reason ADD VALUE IF NOT EXISTS 'task_resume';
|