X-Git-Url: http://git.squeep.com/?p=squeep-indie-auther;a=blobdiff_plain;f=src%2Fdb%2Fpostgres%2Fsql%2Fscope-cleanup.sql;fp=src%2Fdb%2Fpostgres%2Fsql%2Fscope-cleanup.sql;h=120e3d6a9675392584580b726ef1b91d1183288c;hp=0000000000000000000000000000000000000000;hb=b0103b0d496262c438b40bc20304081dbfe41e73;hpb=8ed81748bce7cea7904cac7225b20a60cafdfc16 diff --git a/src/db/postgres/sql/scope-cleanup.sql b/src/db/postgres/sql/scope-cleanup.sql new file mode 100644 index 0000000..120e3d6 --- /dev/null +++ b/src/db/postgres/sql/scope-cleanup.sql @@ -0,0 +1,8 @@ +-- Remove any un-used, non-permament, non-manually-created scopes. +DELETE FROM scope WHERE scope_id NOT IN ( + SELECT scope_id FROM scope s + INNER JOIN profile_scope ps USING (scope_id) + UNION All + SELECT scope_id FROM scope s + INNER JOIN token_scope ts USING (scope_id) +) AND NOT (is_permanent OR is_manually_added)