mirror of
https://github.com/StanGirard/quivr.git
synced 2024-09-11 13:15:41 +03:00
feat: add 20230717164900_add_get_user_email_by_user_id
This commit is contained in:
parent
f63136350b
commit
e22839f9e6
17
scripts/20230717164900_add_get_user_email_by_user_id.sql
Normal file
17
scripts/20230717164900_add_get_user_email_by_user_id.sql
Normal 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;
|
@ -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'
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user