Skip to content

Commit 7cac913

Browse files
committed
Fix people without user_id
Signed-off-by: Bryan Frimin <[email protected]>
1 parent 196f4bc commit 7cac913

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
INSERT INTO peoples (
2+
id,
3+
organization_id,
4+
full_name,
5+
primary_email_address,
6+
additional_email_addresses,
7+
user_id,
8+
kind,
9+
created_at,
10+
updated_at
11+
)
12+
SELECT
13+
generate_gid(decode_base64_unpadded(o.tenant_id), 8),
14+
o.id,
15+
u.fullname,
16+
u.email_address,
17+
ARRAY[]::TEXT[],
18+
u.id,
19+
'CONTRACTOR',
20+
NOW(),
21+
NOW()
22+
FROM users u
23+
JOIN users_organizations uo ON u.id = uo.user_id
24+
JOIN organizations o ON uo.organization_id = o.id
25+
LEFT JOIN peoples p ON u.id = p.user_id
26+
WHERE p.id IS NULL;
27+
28+
UPDATE peoples p
29+
SET user_id = u.id
30+
FROM users u
31+
WHERE p.user_id IS NULL
32+
AND p.primary_email_address = u.email_address;

0 commit comments

Comments
 (0)