|
| 1 | +DROPVIEW template_version_with_user; |
| 2 | + |
| 3 | +DROPVIEW workspace_build_with_user; |
| 4 | + |
| 5 | +DROPVIEW template_with_names; |
| 6 | + |
| 7 | +DROPVIEW workspaces_expanded; |
| 8 | + |
| 9 | +DROPVIEW visible_users; |
| 10 | + |
| 11 | +-- Recreate `visible_users` as described in dump.sql |
| 12 | + |
| 13 | +CREATEVIEWvisible_usersAS |
| 14 | +SELECTusers.id,users.username,users.avatar_url |
| 15 | +FROM users; |
| 16 | + |
| 17 | +COMMENT ON VIEW visible_users IS'Visible fields of users are allowed to be joined with other tables for including context of other resources.'; |
| 18 | + |
| 19 | +-- Recreate `workspace_build_with_user` as described in dump.sql |
| 20 | + |
| 21 | +CREATEVIEWworkspace_build_with_userAS |
| 22 | +SELECT |
| 23 | +workspace_builds.id, |
| 24 | +workspace_builds.created_at, |
| 25 | +workspace_builds.updated_at, |
| 26 | +workspace_builds.workspace_id, |
| 27 | +workspace_builds.template_version_id, |
| 28 | +workspace_builds.build_number, |
| 29 | +workspace_builds.transition, |
| 30 | +workspace_builds.initiator_id, |
| 31 | +workspace_builds.provisioner_state, |
| 32 | +workspace_builds.job_id, |
| 33 | +workspace_builds.deadline, |
| 34 | +workspace_builds.reason, |
| 35 | +workspace_builds.daily_cost, |
| 36 | +workspace_builds.max_deadline, |
| 37 | +workspace_builds.template_version_preset_id, |
| 38 | + COALESCE( |
| 39 | +visible_users.avatar_url, |
| 40 | +''::text |
| 41 | + )AS initiator_by_avatar_url, |
| 42 | + COALESCE( |
| 43 | +visible_users.username, |
| 44 | +''::text |
| 45 | + )AS initiator_by_username |
| 46 | +FROM ( |
| 47 | + workspace_builds |
| 48 | +LEFT JOIN visible_usersON ( |
| 49 | + ( |
| 50 | +workspace_builds.initiator_id=visible_users.id |
| 51 | + ) |
| 52 | + ) |
| 53 | + ); |
| 54 | + |
| 55 | +COMMENT ON VIEW workspace_build_with_user IS'Joins in the username + avatar url of the initiated by user.'; |
| 56 | + |
| 57 | +-- Recreate `template_with_names` as described in dump.sql |
| 58 | + |
| 59 | +CREATEVIEWtemplate_with_namesAS |
| 60 | +SELECT |
| 61 | +templates.id, |
| 62 | +templates.created_at, |
| 63 | +templates.updated_at, |
| 64 | +templates.organization_id, |
| 65 | +templates.deleted, |
| 66 | +templates.name, |
| 67 | +templates.provisioner, |
| 68 | +templates.active_version_id, |
| 69 | +templates.description, |
| 70 | +templates.default_ttl, |
| 71 | +templates.created_by, |
| 72 | +templates.icon, |
| 73 | +templates.user_acl, |
| 74 | +templates.group_acl, |
| 75 | +templates.display_name, |
| 76 | +templates.allow_user_cancel_workspace_jobs, |
| 77 | +templates.allow_user_autostart, |
| 78 | +templates.allow_user_autostop, |
| 79 | +templates.failure_ttl, |
| 80 | +templates.time_til_dormant, |
| 81 | +templates.time_til_dormant_autodelete, |
| 82 | +templates.autostop_requirement_days_of_week, |
| 83 | +templates.autostop_requirement_weeks, |
| 84 | +templates.autostart_block_days_of_week, |
| 85 | +templates.require_active_version, |
| 86 | +templates.deprecated, |
| 87 | +templates.activity_bump, |
| 88 | +templates.max_port_sharing_level, |
| 89 | +templates.use_classic_parameter_flow, |
| 90 | + COALESCE( |
| 91 | +visible_users.avatar_url, |
| 92 | +''::text |
| 93 | + )AS created_by_avatar_url, |
| 94 | + COALESCE( |
| 95 | +visible_users.username, |
| 96 | +''::text |
| 97 | + )AS created_by_username, |
| 98 | + COALESCE(organizations.name,''::text)AS organization_name, |
| 99 | + COALESCE( |
| 100 | +organizations.display_name, |
| 101 | +''::text |
| 102 | + )AS organization_display_name, |
| 103 | + COALESCE(organizations.icon,''::text)AS organization_icon |
| 104 | +FROM ( |
| 105 | + ( |
| 106 | + templates |
| 107 | +LEFT JOIN visible_usersON ( |
| 108 | + ( |
| 109 | +templates.created_by=visible_users.id |
| 110 | + ) |
| 111 | + ) |
| 112 | + ) |
| 113 | +LEFT JOIN organizationsON ( |
| 114 | + ( |
| 115 | +templates.organization_id=organizations.id |
| 116 | + ) |
| 117 | + ) |
| 118 | + ); |
| 119 | + |
| 120 | +COMMENT ON VIEW template_with_names IS'Joins in the display name information such as username, avatar, and organization name.'; |
| 121 | + |
| 122 | +-- Recreate `template_version_with_user` as described in dump.sql |
| 123 | + |
| 124 | +CREATEVIEWtemplate_version_with_userAS |
| 125 | +SELECT |
| 126 | +template_versions.id, |
| 127 | +template_versions.template_id, |
| 128 | +template_versions.organization_id, |
| 129 | +template_versions.created_at, |
| 130 | +template_versions.updated_at, |
| 131 | +template_versions.name, |
| 132 | +template_versions.readme, |
| 133 | +template_versions.job_id, |
| 134 | +template_versions.created_by, |
| 135 | +template_versions.external_auth_providers, |
| 136 | +template_versions.message, |
| 137 | +template_versions.archived, |
| 138 | +template_versions.source_example_id, |
| 139 | + COALESCE( |
| 140 | +visible_users.avatar_url, |
| 141 | +''::text |
| 142 | + )AS created_by_avatar_url, |
| 143 | + COALESCE( |
| 144 | +visible_users.username, |
| 145 | +''::text |
| 146 | + )AS created_by_username |
| 147 | +FROM ( |
| 148 | + template_versions |
| 149 | +LEFT JOIN visible_usersON ( |
| 150 | +template_versions.created_by=visible_users.id |
| 151 | + ) |
| 152 | + ); |
| 153 | + |
| 154 | +COMMENT ON VIEW template_version_with_user IS'Joins in the username + avatar url of the created by user.'; |
| 155 | + |
| 156 | +-- Recreate `workspaces_expanded` as described in dump.sql |
| 157 | + |
| 158 | +CREATEVIEWworkspaces_expandedAS |
| 159 | +SELECT |
| 160 | +workspaces.id, |
| 161 | +workspaces.created_at, |
| 162 | +workspaces.updated_at, |
| 163 | +workspaces.owner_id, |
| 164 | +workspaces.organization_id, |
| 165 | +workspaces.template_id, |
| 166 | +workspaces.deleted, |
| 167 | +workspaces.name, |
| 168 | +workspaces.autostart_schedule, |
| 169 | +workspaces.ttl, |
| 170 | +workspaces.last_used_at, |
| 171 | +workspaces.dormant_at, |
| 172 | +workspaces.deleting_at, |
| 173 | +workspaces.automatic_updates, |
| 174 | +workspaces.favorite, |
| 175 | +workspaces.next_start_at, |
| 176 | +visible_users.avatar_urlAS owner_avatar_url, |
| 177 | +visible_users.usernameAS owner_username, |
| 178 | +organizations.nameAS organization_name, |
| 179 | +organizations.display_nameAS organization_display_name, |
| 180 | +organizations.iconAS organization_icon, |
| 181 | +organizations.descriptionAS organization_description, |
| 182 | +templates.nameAS template_name, |
| 183 | +templates.display_nameAS template_display_name, |
| 184 | +templates.iconAS template_icon, |
| 185 | +templates.descriptionAS template_description |
| 186 | +FROM ( |
| 187 | + ( |
| 188 | + ( |
| 189 | + workspaces |
| 190 | +JOIN visible_usersON ( |
| 191 | + ( |
| 192 | +workspaces.owner_id=visible_users.id |
| 193 | + ) |
| 194 | + ) |
| 195 | + ) |
| 196 | +JOIN organizationsON ( |
| 197 | + ( |
| 198 | +workspaces.organization_id=organizations.id |
| 199 | + ) |
| 200 | + ) |
| 201 | + ) |
| 202 | +JOIN templatesON ( |
| 203 | + ( |
| 204 | +workspaces.template_id=templates.id |
| 205 | + ) |
| 206 | + ) |
| 207 | + ); |
| 208 | + |
| 209 | +COMMENT ON VIEW workspaces_expanded IS'Joins in the display name information such as username, avatar, and organization name.'; |