Skip to content

Commit e26bc20

Browse files
authored
fix: actually fix template version created by migration (#4850)
1 parent a672ae8 commit e26bc20

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
BEGIN;
22

3-
UPDATE template_versions SET created_by = '00000000-0000-0000-0000-000000000000'::uuid WHERE created_by IS NULL;
3+
UPDATE
4+
template_versions
5+
SET
6+
created_by = COALESCE(
7+
-- Best effort to convert all unowned template versions to the first owner.
8+
(SELECT id FROM users WHERE rbac_roles @> '{owner}' AND deleted = 'f' ORDER BY created_at ASC LIMIT 1),
9+
-- If there are no owners, assign to the first user.
10+
(SELECT id FROM users WHERE deleted = 'f' ORDER BY created_at ASC LIMIT 1)
11+
-- If you have no users I'm not sure what else to tell you.
12+
)
13+
WHERE
14+
created_by IS NULL;
15+
416
ALTER TABLE template_versions ALTER COLUMN created_by SET NOT NULL;
517

618
COMMIT;

0 commit comments

Comments
 (0)