10000 Fix migration down · coder/coder@aba62bf · GitHub
[go: up one dir, main page]

Skip to content

Commit aba62bf

Browse files
committed
Fix migration down
1 parent 5a5ca80 commit aba62bf

File tree

1 file changed

+67
-99
lines changed

1 file changed

+67
-99
lines changed

coderd/database/migrations/000330_workspace_with_correct_owner_names.down.sql

Lines changed: 67 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
1-
-- Recreate `template_version_with_user` as described in dump.sql
21
DROP VIEW template_version_with_user;
32

4-
CREATE VIEW template_version_with_user AS
5-
SELECT
6-
template_versions.id,
7-
template_versions.template_id,
8-
template_versions.organization_id,
9-
template_versions.created_at,
10-
template_versions.updated_at,
11-
template_versions.name,
12-
template_versions.readme,
13-
template_versions.job_id,
14-
template_versions.created_by,
15-
template_versions.external_auth_providers,
16-
template_versions.message,
17-
template_versions.archived,
18-
template_versions.source_example_id,
19-
COALESCE(
20-
visible_users.avatar_url,
21-
''::text
22-
) AS created_by_avatar_url,
23-
COALESCE(
24-
visible_users.username,
25-
''::text
26-
) AS created_by_username
27-
FROM (
28-
template_versions
29-
LEFT JOIN visible_users ON (
30-
template_versions.created_by = visible_users.id
31-
)
32-
);
3+
DROP VIEW workspace_build_with_user;
334

34-
COMMENT ON VIEW template_version_with_user IS 'Joins in the username + avatar url of the created by user.';
5+
DROP VIEW template_with_names;
6+
7+
DROP VIEW workspaces_expanded;
8+
9+
DROP VIEW visible_users;
10+
11+
-- Recreate `visible_users` as described in dump.sql
12+
13+
CREATE VIEW visible_users AS
14+
SELECT users.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.';
3518

3619
-- Recreate `workspace_build_with_user` as described in dump.sql
37-
DROP VIEW workspace_build_with_user;
3820

3921
CREATE VIEW workspace_build_with_user AS
4022
SELECT
@@ -72,64 +54,7 @@ FROM (
7254

7355
COMMENT ON VIEW workspace_build_with_user IS 'Joins in the username + avatar url of the initiated by user.';
7456

75-
-- Recreate `workspaces_expanded` as described in dump.sql
76-
DROP VIEW workspaces_expanded;
77-
78-
CREATE VIEW workspaces_expanded AS
79-
SELECT
80-
workspaces.id,
81-
workspaces.created_at,
82-
workspaces.updated_at,
83-
workspaces.owner_id,
84-
workspaces.organization_id,
85-
workspaces.template_id,
86-
workspaces.deleted,
87-
workspaces.name,
88-
workspaces.autostart_schedule,
89-
workspaces.ttl,
90-
workspaces.last_used_at,
91-
workspaces.dormant_at,
92-
workspaces.deleting_at,
93-
workspaces.automatic_updates,
94-
workspaces.favorite,
95-
workspaces.next_start_at,
96-
visible_users.avatar_url AS owner_avatar_url,
97-
visible_users.username AS owner_username,
98-
organizations.name AS organization_name,
99-
organizations.display_name AS organization_display_name,
100-
organizations.icon AS organization_icon,
101-
organizations.description AS organization_description,
102-
templates.name AS template_name,
103-
templates.display_name AS template_display_name,
104-
templates.icon AS template_icon,
105-
templates.description AS template_description
106-
FROM (
107-
(
108-
(
109-
workspaces
110-
JOIN visible_users ON (
111-
(
112-
workspaces.owner_id = visible_users.id
113-
)
114-
)
115-
)
116-
JOIN organizations ON (
117-
(
118-
workspaces.organization_id = organizations.id
119-
)
120-
)
121-
)
122-
JOIN templates ON (
123-
(
124-
workspaces.template_id = templates.id
125-
)
126-
)
127-
);
128-
129-
COMMENT ON VIEW workspaces_expanded IS 'Joins in the display name information such as username, avatar, and organization name.';
130-
13157
-- Recreate `template_with_names` as described in dump.sql
132-
DROP VIEW template_with_names;
13358

13459
CREATE VIEW template_with_names AS
13560
SELECT
@@ -195,7 +120,6 @@ FROM (
195120
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';
196121

197122
-- Recreate `template_version_with_user` as described in dump.sql
198-
DROP VIEW template_version_with_user;
199123

200124
CREATE VIEW template_version_with_user AS
201125
SELECT
@@ -223,19 +147,63 @@ SELECT
223147
FROM (
224148
template_versions
225149
LEFT JOIN visible_users ON (
226-
(
227-
template_versions.created_by = visible_users.id
228-
)
150+
template_versions.created_by = visible_users.id
229151
)
230152
);
231153

232154
COMMENT ON VIEW template_version_with_user IS 'Joins in the username + avatar url of the created by user.';
233155

234-
-- Recreate `visible_users` as described in dump.sql
235-
DROP VIEW visible_users;
156+
-- Recreate `workspaces_expanded` as described in dump.sql
236157

237-
CREATE VIEW visible_users AS
238-
SELECT users.id, users.username, users.avatar_url
239-
FROM users;
158+
CREATE VIEW workspaces_expanded AS
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_url AS owner_avatar_url,
177+
visible_users.username AS owner_username,
178+
organizations.name AS organization_name,
179+
organizations.display_name AS organization_display_name,
180+
organizations.icon AS organization_icon,
181+
organizations.description AS organization_description,
182+
templates.name AS template_name,
183+
templates.display_name AS template_display_name,
184+
templates.icon AS template_icon,
185+
templates.description AS template_description
186+
FROM (
187+
(
188+
(
189+
workspaces
190+
JOIN visible_users ON (
191+
(
192+
workspaces.owner_id = visible_users.id
193+
)
194+
)
195+
)
196+
JOIN organizations ON (
197+
(
198+
workspaces.organization_id = organizations.id
199+
)
200+
)
201+
)
202+
JOIN templates ON (
203+
(
204+
workspaces.template_id = templates.id
205+
)
206+
)
207+
);
240208

241-
COMMENT ON VIEW visible_users IS 'Visible fields of users are allowed to be joined with other tables for including context of other resources.';
209+
COMMENT ON VIEW workspaces_expanded IS 'Joins in the display name information such as username, avatar, and organization name.';

0 commit comments

Comments
 (0)
0