|
| 1 | +-- Determines if a coder_ai_task resource was included in a |
| 2 | +-- workspace build. |
| 3 | +ALTERTABLE |
| 4 | + workspace_builds |
| 5 | +ADD |
| 6 | + COLUMN has_ai_taskBOOLEANNOT NULL DEFAULT FALSE; |
| 7 | + |
| 8 | +-- The app that is displayed in the ai tasks sidebar. |
| 9 | +ALTERTABLE |
| 10 | + workspace_builds |
| 11 | +ADD |
| 12 | + COLUMN ai_tasks_sidebar_app_id UUID DEFAULTNULL; |
| 13 | + |
| 14 | +ALTERTABLE |
| 15 | + workspace_builds |
| 16 | +ADD |
| 17 | +CONSTRAINT workspace_builds_ai_tasks_sidebar_app_id_fkeyFOREIGN KEY (ai_tasks_sidebar_app_id)REFERENCES workspace_apps(id); |
| 18 | + |
| 19 | +-- Determines if a coder_ai_task resource is defined in a template version. |
| 20 | +ALTERTABLE |
| 21 | + template_versions |
| 22 | +ADD |
| 23 | + COLUMN has_ai_taskBOOLEANNOT NULL DEFAULT FALSE; |
| 24 | + |
| 25 | +-- The Tasks tab will be rendered in the UI only if there's at least one template version with has_ai_task set to true. |
| 26 | +-- The query to determine this will be run on every UI render, and this index speeds it up. |
| 27 | +-- SELECT EXISTS (SELECT 1 FROM template_versions WHERE has_ai_task = TRUE); |
| 28 | +CREATEINDEXidx_template_versions_has_ai_taskON template_versions USING btree (has_ai_task); |
| 29 | + |
| 30 | +DROPVIEW workspace_build_with_user; |
| 31 | + |
| 32 | +-- We're adding the has_ai_task and ai_tasks_sidebar_app_id columns. |
| 33 | +CREATEVIEWworkspace_build_with_userAS |
| 34 | +SELECT |
| 35 | +workspace_builds.id, |
| 36 | +workspace_builds.created_at, |
| 37 | +workspace_builds.updated_at, |
| 38 | +workspace_builds.workspace_id, |
| 39 | +workspace_builds.template_version_id, |
| 40 | +workspace_builds.build_number, |
| 41 | +workspace_builds.transition, |
| 42 | +workspace_builds.initiator_id, |
| 43 | +workspace_builds.provisioner_state, |
| 44 | +workspace_builds.job_id, |
| 45 | +workspace_builds.deadline, |
| 46 | +workspace_builds.reason, |
| 47 | +workspace_builds.daily_cost, |
| 48 | +workspace_builds.max_deadline, |
| 49 | +workspace_builds.template_version_preset_id, |
| 50 | +workspace_builds.has_ai_task, |
| 51 | +workspace_builds.ai_tasks_sidebar_app_id, |
| 52 | + COALESCE( |
| 53 | +visible_users.avatar_url, |
| 54 | +'' ::text |
| 55 | + )AS initiator_by_avatar_url, |
| 56 | + COALESCE( |
| 57 | +visible_users.username, |
| 58 | +'' ::text |
| 59 | + )AS initiator_by_username, |
| 60 | + COALESCE(visible_users.name,'' ::text)AS initiator_by_name |
| 61 | +FROM |
| 62 | + ( |
| 63 | + workspace_builds |
| 64 | +LEFT JOIN visible_usersON ( |
| 65 | + ( |
| 66 | +workspace_builds.initiator_id=visible_users.id |
| 67 | + ) |
| 68 | + ) |
| 69 | + ); |
| 70 | + |
| 71 | +COMMENT ON VIEW workspace_build_with_user IS'Joins in the username + avatar url of the initiated by user.'; |
| 72 | + |
| 73 | +DROPVIEW template_version_with_user; |
| 74 | + |
| 75 | +-- We're adding the has_ai_task column. |
| 76 | +CREATEVIEWtemplate_version_with_userAS |
| 77 | +SELECT |
| 78 | +template_versions.id, |
| 79 | +template_versions.template_id, |
| 80 | +template_versions.organization_id, |
| 81 | +template_versions.created_at, |
| 82 | +template_versions.updated_at, |
| 83 | +template_versions.name, |
| 84 | +template_versions.readme, |
| 85 | +template_versions.job_id, |
| 86 | +template_versions.created_by, |
| 87 | +template_versions.external_auth_providers, |
| 88 | +template_versions.message, |
| 89 | +template_versions.archived, |
| 90 | +template_versions.source_example_id, |
| 91 | +template_versions.has_ai_task, |
| 92 | + COALESCE(visible_users.avatar_url,'' ::text)AS created_by_avatar_url, |
| 93 | + COALESCE(visible_users.username,'' ::text)AS created_by_username, |
| 94 | + COALESCE(visible_users.name,'' ::text)AS created_by_name |
| 95 | +FROM |
| 96 | + ( |
| 97 | + template_versions |
| 98 | +LEFT JOIN visible_usersON ( |
| 99 | + (template_versions.created_by=visible_users.id) |
| 100 | + ) |
| 101 | + ); |
| 102 | + |
| 103 | +COMMENT ON VIEW template_version_with_user IS'Joins in the username + avatar url of the created by user.'; |