mirror of
https://github.com/AppFlowy-IO/AppFlowy-Cloud.git
synced 2025-04-19 03:24:42 -04:00
fix: use foreign key cascade delete for user cleanup (#188)
This commit is contained in:
parent
0e2ec381df
commit
63e970caa2
2 changed files with 21 additions and 0 deletions
21
migrations/20231130150000_user_id_foreign_key.sql
Normal file
21
migrations/20231130150000_user_id_foreign_key.sql
Normal file
|
@ -0,0 +1,21 @@
|
|||
-- Revert the last migration
|
||||
REVOKE SELECT, INSERT, UPDATE, DELETE ON public.af_user FROM supabase_auth_admin;
|
||||
DROP TRIGGER delete_user_trigger ON auth.users;
|
||||
DROP TRIGGER update_af_user_deleted_at_trigger ON auth.users;
|
||||
DROP FUNCTION public.delete_user();
|
||||
DROP FUNCTION public.update_af_user_deleted_at();
|
||||
|
||||
-- Delete all users from public.af_user table that are not in auth.users table
|
||||
DELETE FROM public.af_user
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM auth.users
|
||||
WHERE af_user.uuid = users.id
|
||||
);
|
||||
|
||||
-- Add foreign key constraint to public.af_user table
|
||||
ALTER TABLE public.af_user
|
||||
ADD CONSTRAINT af_user_email_foreign_key
|
||||
FOREIGN KEY (uuid)
|
||||
REFERENCES auth.users(id)
|
||||
ON DELETE CASCADE;
|
0
tem
0
tem
Loading…
Add table
Reference in a new issue