mirror of
https://github.com/StanGirard/quivr.git
synced 2024-11-28 13:42:41 +03:00
0477cce971
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)
31 lines
951 B
PL/PgSQL
31 lines
951 B
PL/PgSQL
|
|
-- 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'
|
|
);
|