1 -- Remove any un-used, non-permanent, non-manually-created scopes.
2 DELETE FROM scope WHERE scope_id
NOT IN (
3 SELECT scope_id
FROM scope s
4 INNER JOIN profile_scope ps
USING (scope_id
)
6 SELECT scope_id
FROM scope s
7 INNER JOIN token_scope ts
USING (scope_id
)
8 ) AND NOT (is_permanent
OR is_manually_added
)