quivr/scripts/20231116102600_add_get_user_email_by_user_id.sql
Zineb El Bachiri 18946ad329
fix: delete brain on users click in brains management (#1638)
# Description

Fix subscription routes on get users
Revert changes deleting the function to get user email from its id in
SQL


https://www.loom.com/share/46534965a83f4296898495ac370b3451?sid=7f582838-32f6-4812-960e-c80d71517a6d
2023-11-16 12:49:10 +01:00

18 lines
468 B
PL/PgSQL

CREATE OR REPLACE FUNCTION public.get_user_email_by_user_id(user_id uuid)
RETURNS TABLE (email text)
SECURITY definer
AS $$
BEGIN
RETURN QUERY SELECT au.email::text FROM auth.users au WHERE au.id = user_id;
END;
$$ LANGUAGE plpgsql;
-- Update migrations table
INSERT INTO migrations (name)
SELECT '20231116102600_add_get_user_email_by_user_id'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20231116102600_add_get_user_email_by_user_id'
);
COMMIT;