X-Git-Url: http://git.squeep.com/?p=squeep-indie-auther;a=blobdiff_plain;f=src%2Fdb%2Fpostgres%2Fsql%2Fscope-in-use.sql;fp=src%2Fdb%2Fpostgres%2Fsql%2Fscope-in-use.sql;h=a09c540ab53849592ddbe1bcf8bb2f936dfd4151;hp=0000000000000000000000000000000000000000;hb=b0103b0d496262c438b40bc20304081dbfe41e73;hpb=8ed81748bce7cea7904cac7225b20a60cafdfc16 diff --git a/src/db/postgres/sql/scope-in-use.sql b/src/db/postgres/sql/scope-in-use.sql new file mode 100644 index 0000000..a09c540 --- /dev/null +++ b/src/db/postgres/sql/scope-in-use.sql @@ -0,0 +1,13 @@ +-- return whether a scope is currently in use, either a profile setting or on a token +SELECT EXISTS ( + SELECT 1 FROM scope s + INNER JOIN profile_scope ps USING (scope_id) + WHERE s.scope = $(scope) + UNION All + SELECT 1 FROM scope s + INNER JOIN token_scope ts USING (scope_id) + WHERE s.scope = $(scope) + UNION All + SELECT 1 FROM scope s + WHERE s.scope = $(scope) AND s.is_permanent +) AS in_use