mirror of
https://github.com/StanGirard/quivr.git
synced 2024-10-27 06:20:11 +03:00
feat: add create_user_onboarding_function (#1383)
https://github.com/StanGirard/quivr/issues/1375 ![Screenshot 2023-10-10 at 16 28 04](https://github.com/StanGirard/quivr/assets/63923024/07b8838f-74bc-408a-86ce-481e1224a8e4)
This commit is contained in:
parent
58ea481910
commit
0477cce971
@ -0,0 +1,30 @@
|
||||
|
||||
-- Create the function to add user_id to the onboardings table
|
||||
CREATE OR REPLACE FUNCTION public.create_user_onboarding() RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
INSERT INTO public.onboardings (user_id)
|
||||
VALUES (NEW.id);
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql SECURITY definer;
|
||||
|
||||
-- Revoke all on function handle_new_user_onboarding() from PUBLIC;
|
||||
REVOKE ALL ON FUNCTION create_user_onboarding() FROM PUBLIC;
|
||||
|
||||
-- Drop the trigger if it exists
|
||||
DROP TRIGGER IF EXISTS create_user_onboarding_trigger ON auth.users;
|
||||
|
||||
-- Create the trigger on the insert into the auth.users table
|
||||
CREATE TRIGGER create_user_onboarding_trigger
|
||||
AFTER INSERT ON auth.users
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION public.create_user_onboarding();
|
||||
|
||||
-- Update migrations table
|
||||
INSERT INTO migrations (name)
|
||||
SELECT '20231010120000_add_create_user_onboarding_function'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM migrations
|
||||
WHERE name = '20231010120000_add_create_user_onboarding_function'
|
||||
);
|
@ -255,6 +255,26 @@ CREATE TABLE IF NOT EXISTS knowledge_vectors (
|
||||
PRIMARY KEY (knowledge_id, vector_id, embedding_model)
|
||||
);
|
||||
|
||||
-- Create the function to add user_id to the onboardings table
|
||||
CREATE OR REPLACE FUNCTION public.create_user_onboarding() RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
INSERT INTO public.onboardings (user_id)
|
||||
VALUES (NEW.id);
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql SECURITY definer;
|
||||
|
||||
-- Revoke all on function handle_new_user_onboarding() from PUBLIC;
|
||||
REVOKE ALL ON FUNCTION create_user_onboarding() FROM PUBLIC;
|
||||
|
||||
-- Drop the trigger if it exists
|
||||
DROP TRIGGER IF EXISTS create_user_onboarding_trigger ON auth.users;
|
||||
|
||||
-- Create the trigger on the insert into the auth.users table
|
||||
CREATE TRIGGER create_user_onboarding_trigger
|
||||
AFTER INSERT ON auth.users
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION public.create_user_onboarding();
|
||||
|
||||
-- Create the onboarding table
|
||||
CREATE TABLE IF NOT EXISTS onboardings (
|
||||
@ -280,9 +300,9 @@ CREATE POLICY "Access Quivr Storage 1jccrwz_2" ON storage.objects FOR UPDATE TO
|
||||
CREATE POLICY "Access Quivr Storage 1jccrwz_3" ON storage.objects FOR DELETE TO anon USING (bucket_id = 'quivr');
|
||||
|
||||
INSERT INTO migrations (name)
|
||||
SELECT '20231005170000_add_onboarding_a_to_onboarding_table'
|
||||
SELECT '20231010120000_add_create_user_onboarding_function'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM migrations WHERE name = '20231005170000_add_onboarding_a_to_onboarding_table'
|
||||
SELECT 1 FROM migrations WHERE name = '20231010120000_add_create_user_onboarding_function'
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user