8 lines
370 B
SQL
8 lines
370 B
SQL
INSERT INTO public.user_memberships (id, user_id, tenant_id, role)
|
|
SELECT gen_random_uuid(), u.id, t.tenant_id, 'admin'
|
|
FROM public.users AS u
|
|
JOIN public.tenants AS t ON t.slug = 'admin'
|
|
LEFT JOIN public.user_memberships AS um ON um.user_id = u.id AND um.tenant_id = t.tenant_id
|
|
WHERE u.username = 'admin' AND um.id IS NULL
|
|
ON CONFLICT (user_id, tenant_id) DO NOTHING;
|