chore(coderd/database): add tasks data model (#19749)

Part of https://github.com/coder/internal/issues/948

Adds the initial part of the tasks data model as per the RFC.
This commit is contained in:
Danielle Maywood
2025-09-10 10:01:50 +01:00
committed by GitHub
parent 4bf63b4068
commit 4cd0ada0bb
7 changed files with 116 additions and 0 deletions
+47
View File
@@ -1539,6 +1539,26 @@ CREATE TABLE tailnet_tunnels (
updated_at timestamp with time zone NOT NULL
);
CREATE TABLE task_workspace_apps (
task_id uuid NOT NULL,
workspace_build_id uuid NOT NULL,
workspace_agent_id uuid NOT NULL,
workspace_app_id uuid NOT NULL
);
CREATE TABLE tasks (
id uuid NOT NULL,
organization_id uuid NOT NULL,
owner_id uuid NOT NULL,
name text NOT NULL,
workspace_id uuid,
template_version_id uuid NOT NULL,
template_parameters jsonb DEFAULT '{}'::jsonb NOT NULL,
prompt text NOT NULL,
created_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);
CREATE TABLE telemetry_items (
key text NOT NULL,
value text NOT NULL,
@@ -2717,6 +2737,9 @@ ALTER TABLE ONLY tailnet_peers
ALTER TABLE ONLY tailnet_tunnels
ADD CONSTRAINT tailnet_tunnels_pkey PRIMARY KEY (coordinator_id, src_id, dst_id);
ALTER TABLE ONLY tasks
ADD CONSTRAINT tasks_pkey PRIMARY KEY (id);
ALTER TABLE ONLY telemetry_items
ADD CONSTRAINT telemetry_items_pkey PRIMARY KEY (key);
@@ -3230,6 +3253,30 @@ ALTER TABLE ONLY tailnet_peers
ALTER TABLE ONLY tailnet_tunnels
ADD CONSTRAINT tailnet_tunnels_coordinator_id_fkey FOREIGN KEY (coordinator_id) REFERENCES tailnet_coordinators(id) ON DELETE CASCADE;
ALTER TABLE ONLY task_workspace_apps
ADD CONSTRAINT task_workspace_apps_task_id_fkey FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE;
ALTER TABLE ONLY task_workspace_apps
ADD CONSTRAINT task_workspace_apps_workspace_agent_id_fkey FOREIGN KEY (workspace_agent_id) REFERENCES workspace_agents(id) ON DELETE CASCADE;
ALTER TABLE ONLY task_workspace_apps
ADD CONSTRAINT task_workspace_apps_workspace_app_id_fkey FOREIGN KEY (workspace_app_id) REFERENCES workspace_apps(id) ON DELETE CASCADE;
ALTER TABLE ONLY task_workspace_apps
ADD CONSTRAINT task_workspace_apps_workspace_build_id_fkey FOREIGN KEY (workspace_build_id) REFERENCES workspace_builds(id) ON DELETE CASCADE;
ALTER TABLE ONLY tasks
ADD CONSTRAINT tasks_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE;
ALTER TABLE ONLY tasks
ADD CONSTRAINT tasks_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY tasks
ADD CONSTRAINT tasks_template_version_id_fkey FOREIGN KEY (template_version_id) REFERENCES template_versions(id) ON DELETE CASCADE;
ALTER TABLE ONLY tasks
ADD CONSTRAINT tasks_workspace_id_fkey FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY template_version_parameters
ADD CONSTRAINT template_version_parameters_template_version_id_fkey FOREIGN KEY (template_version_id) REFERENCES template_versions(id) ON DELETE CASCADE;