Files
rust-discovery/migrations/0025_enrollment_membership_scope.sql
T

15 lines
585 B
SQL

-- Migration 24 could not see FORCE ROW LEVEL SECURITY memberships without a
-- tenant context, even when run by the table owner. Use each tenant's policy.
DO $$
DECLARE
current_tenant uuid;
BEGIN
FOR current_tenant IN SELECT tenant_id FROM tenants LOOP
PERFORM set_config('app.tenant_id', current_tenant::text, true);
UPDATE memberships SET permissions = array_append(permissions, 'devices:enroll')
WHERE tenant_id = current_tenant AND 'devices:revoke' = ANY(permissions)
AND NOT ('devices:enroll' = ANY(permissions));
END LOOP;
END;
$$;