From 1747f293bc6140285ceaf69b96778358a806cdae Mon Sep 17 00:00:00 2001 From: Paul Cioanca Date: Fri, 6 Sep 2024 15:16:42 +0300 Subject: [PATCH 1/2] fix: continue running migrations when auth.uid/auth.role/auth.email are missing in database --- .../migrations/20211124212715_update-auth-owner.sql | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/migrations/db/migrations/20211124212715_update-auth-owner.sql b/migrations/db/migrations/20211124212715_update-auth-owner.sql index d40609c53..fa35b9f0a 100644 --- a/migrations/db/migrations/20211124212715_update-auth-owner.sql +++ b/migrations/db/migrations/20211124212715_update-auth-owner.sql @@ -1,8 +1,12 @@ -- migrate:up -- update owner for auth.uid, auth.role and auth.email functions -ALTER FUNCTION auth.uid owner to supabase_auth_admin; -ALTER FUNCTION auth.role owner to supabase_auth_admin; -ALTER FUNCTION auth.email owner to supabase_auth_admin; - +DO $$ +BEGIN + ALTER FUNCTION auth.uid owner to supabase_auth_admin; + ALTER FUNCTION auth.role owner to supabase_auth_admin; + ALTER FUNCTION auth.email owner to supabase_auth_admin; +EXCEPTION WHEN OTHERS THEN + RAISE WARNING 'Error encountered when changing owner of auth.uid, auth.role or auth.email to supabase_auth_admin'; +END $$; -- migrate:down From 57c9aa9931ed7d5c8e68e4974f569dc87dbe3dc0 Mon Sep 17 00:00:00 2001 From: Paul Cioanca Date: Mon, 9 Sep 2024 11:22:27 +0300 Subject: [PATCH 2/2] chore: catch grant exceptions per-function --- .../20211124212715_update-auth-owner.sql | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/migrations/db/migrations/20211124212715_update-auth-owner.sql b/migrations/db/migrations/20211124212715_update-auth-owner.sql index fa35b9f0a..2bce808b0 100644 --- a/migrations/db/migrations/20211124212715_update-auth-owner.sql +++ b/migrations/db/migrations/20211124212715_update-auth-owner.sql @@ -4,9 +4,21 @@ DO $$ BEGIN ALTER FUNCTION auth.uid owner to supabase_auth_admin; +EXCEPTION WHEN OTHERS THEN + RAISE WARNING 'Error encountered when changing owner of auth.uid to supabase_auth_admin'; +END $$; + +DO $$ +BEGIN ALTER FUNCTION auth.role owner to supabase_auth_admin; +EXCEPTION WHEN OTHERS THEN + RAISE WARNING 'Error encountered when changing owner of auth.role to supabase_auth_admin'; +END $$; + +DO $$ +BEGIN ALTER FUNCTION auth.email owner to supabase_auth_admin; EXCEPTION WHEN OTHERS THEN - RAISE WARNING 'Error encountered when changing owner of auth.uid, auth.role or auth.email to supabase_auth_admin'; + RAISE WARNING 'Error encountered when changing owner of auth.email to supabase_auth_admin'; END $$; -- migrate:down