Replies: 1 comment
|
Short version: yes, a plain 1. Replacing keeps the same function OID, so the trigger on The same page also says every other property is reset to whatever the new command says or implies. So if the current function is I reproduced this on Postgres 17 with a non-superuser owner and a trigger on a table owned by a separate auth role:
The safest way to write the migration is to start from the live definition, change only the body, and keep everything else as it is: select pg_get_functiondef('public.handle_new_user()'::regprocedure);Other things fail loudly rather than silently, which helps: a non-owner gets 2. Transactions, concurrency and Supabase-managed changes
3. Additional locking Not needed, as explained above. If you want a guard between deployers anyway, use a transaction-scoped advisory lock. Any role can take one, it needs no catalog privileges, and it is released automatically at commit or rollback: set lock_timeout = '5s';
select pg_advisory_xact_lock(hashtext('public.handle_new_user'));
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = '' -- copy exactly from pg_get_functiondef
as $$
begin
-- new body
return new;
end;
$$;Don't try Pre/post checks Run this before and after, and compare the output: select p.oid, p.proowner::regrole, p.proacl, p.prosecdef, p.proconfig, p.provolatile,
md5(p.prosrc) as body_md5,
t.tgname, t.tgenabled, t.tgfoid = p.oid as trigger_points_here
from pg_proc p
left join pg_trigger t on t.tgfoid = p.oid and not t.tgisinternal
where p.oid = 'public.handle_new_user()'::regprocedure;Everything except |
Uh oh!
There was an error while loading. Please reload this page.
We need to update the body of a custom PL/pgSQL trigger function called by an AFTER INSERT trigger on auth.users.
The change should preserve the function’s signature, ownership, privileges, and existing trigger binding. It should not modify existing accounts or roles.
Environment and checks:
We intend to use a reviewed, versioned migration through the Supabase CLI, after checking the existing migration history and preparing a backup.
Questions:
We are looking for the standard supported procedure, not a guarantee against every possible platform operation.
All reactions