feat: add 20230717164900_add_get_user_email_by_user_id (#675)

This commit is contained in:
Mamadou DICKO 2023-07-17 17:24:31 +02:00 committed by GitHub
parent f63136350b
commit f8fce33191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -0,0 +1,17 @@
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 '20230717164900_add_get_user_email_by_user_id'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20230717164900_add_get_user_email_by_user_id'
);
COMMIT;

View File

@ -166,13 +166,22 @@ CREATE TABLE IF NOT EXISTS brain_subscription_invitations (
FOREIGN KEY (brain_id) REFERENCES brains (brain_id)
);
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;
CREATE TABLE IF NOT EXISTS migrations (
name VARCHAR(255) PRIMARY KEY,
executed_at TIMESTAMPTZ DEFAULT current_timestamp
);
INSERT INTO migrations (name)
SELECT '202307111517031_change_vectors_id_type'
SELECT '20230717164900_add_get_user_email_by_user_id'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '202307111517031_change_vectors_id_type'
SELECT 1 FROM migrations WHERE name = '20230717164900_add_get_user_email_by_user_id'
);