120e3d6a9675392584580b726ef1b91d1183288c
[squeep-indie-auther] / src / db / postgres / sql / scope-cleanup.sql
1 -- Remove any un-used, non-permament, 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)
5 UNION All
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)