INSERT INTO organization_memberships (
    id,
    organization_id,
    user_id,
    role_id,
    status,
    invited_by_user_id,
    created_at,
    updated_at
)
SELECT
    gen_random_uuid(),
    org.id,
    u.id,
    CASE
        WHEN u.platform_role IN ('platform_admin', 'platform_recovery_admin') THEN 'org_owner'
        ELSE 'org_member'
    END,
    'active',
    NULL,
    NOW(),
    NOW()
FROM users u
CROSS JOIN organizations org
LEFT JOIN organization_memberships om
    ON om.organization_id = org.id
   AND om.user_id = u.id
WHERE org.slug = 'default'
  AND om.id IS NULL;
