|
38 | 38 | GROUP BY wpb.template_version_id, wpb.transition)
|
39 | 39 | SELECT t.template_id,
|
40 | 40 | t.template_version_id,
|
41 |
| - t.using_active_version AS is_active, |
42 |
| - CAST(COALESCE(MAX(CASE WHEN p.template_version_id = t.template_version_id THEN p.ids END), |
43 |
| - '') AS TEXT) AS running_prebuild_ids, |
44 |
| - CAST(COALESCE(MAX(CASE WHEN t.using_active_version THEN p.count ELSE 0 END), |
45 |
| - 0) AS INT) AS actual, -- running prebuilds for active version |
46 |
| - CAST(COALESCE(MAX(CASE WHEN t.using_active_version THEN t.desired_instances ELSE 0 END), |
47 |
| - 0) AS INT) AS desired, -- we only care about the active version's desired instances |
48 |
| - CAST(COALESCE(MAX(CASE |
49 |
| - WHEN p.template_version_id = t.template_version_id AND t.using_active_version = false |
50 |
| - THEN p.count END), |
51 |
| - 0) AS INT) AS extraneous, -- running prebuilds for inactive version |
52 |
| - CAST(COALESCE(MAX(CASE WHEN pip.transition = 'start'::workspace_transition THEN pip.count ELSE 0 END), |
53 |
| - 0) AS INT) AS starting, |
54 |
| - CAST(COALESCE(MAX(CASE WHEN pip.transition = 'stop'::workspace_transition THEN pip.count ELSE 0 END), |
55 |
| - 0) AS INT) AS stopping, -- not strictly needed, since prebuilds should never be left if a "stopped" state, but useful to know |
56 |
| - CAST(COALESCE(MAX(CASE WHEN pip.transition = 'delete'::workspace_transition THEN pip.count ELSE 0 END), |
57 |
| - 0) AS INT) AS deleting, |
58 |
| - t.deleted AS template_deleted, |
59 |
| - t.deprecated AS template_deprecated |
| 41 | + t.using_active_version AS is_active, |
| 42 | + COALESCE(MAX(CASE WHEN p.template_version_id = t.template_version_id THEN p.ids END), |
| 43 | + '')::text AS running_prebuild_ids, |
| 44 | + COALESCE(MAX(CASE WHEN t.using_active_version THEN p.count ELSE 0 END), |
| 45 | + 0)::int AS actual, -- running prebuilds for active version |
| 46 | + COALESCE(MAX(CASE WHEN t.using_active_version THEN t.desired_instances ELSE 0 END), |
| 47 | + 0)::int AS desired, -- we only care about the active version's desired instances |
| 48 | + COALESCE(MAX(CASE |
| 49 | + WHEN p.template_version_id = t.template_version_id AND t.using_active_version = false |
| 50 | + THEN p.count END), |
| 51 | + 0)::int AS extraneous, -- running prebuilds for inactive version |
| 52 | + COALESCE(MAX(CASE WHEN pip.transition = 'start'::workspace_transition THEN pip.count ELSE 0 END), |
| 53 | + 0)::int AS starting, |
| 54 | + COALESCE(MAX(CASE WHEN pip.transition = 'stop'::workspace_transition THEN pip.count ELSE 0 END), |
| 55 | + 0)::int AS stopping, -- not strictly needed, since prebuilds should never be left if a "stopped" state, but useful to know |
| 56 | + COALESCE(MAX(CASE WHEN pip.transition = 'delete'::workspace_transition THEN pip.count ELSE 0 END), |
| 57 | + 0)::int AS deleting, |
| 58 | + t.deleted AS template_deleted, |
| 59 | + t.deprecated AS template_deprecated |
60 | 60 | FROM templates_with_prebuilds t
|
61 | 61 | LEFT JOIN running_prebuilds p ON p.template_version_id = t.template_version_id
|
62 | 62 | LEFT JOIN prebuilds_in_progress pip ON pip.template_version_id = t.template_version_id
|
|
0 commit comments