-- Deploy numerus:find_user_role to pg
-- requires: schema_auth
-- requires: user
-- requires: email

begin;

set search_path to auth, numerus, public;

create or replace function find_user_role(email email, password text) returns name
as
$$
declare
	found_role name;
begin
	select role
	into found_role
	from auth."user"
	where "user".email = find_user_role.email
	and "user".password = crypt(find_user_role.password, "user".password);

	return found_role;
end;
$$
language plpgsql;

comment on function find_user_role(email, text) is
'Return the database role assigned to the user with the given email and password';

commit;
