14 lines
1.1 KiB
SQL
14 lines
1.1 KiB
SQL
do $migration$
|
|
declare
|
|
definition text;
|
|
old_block text := E' else\n update auth.users\n set encrypted_password = extensions.crypt(v_pw, extensions.gen_salt(''bf'')),\n updated_at = now()\n where id = v_uid;\n delete from auth.sessions where user_id = v_uid;\n end if;';
|
|
new_block text := E' else\n perform 1 from auth.users where id = v_uid for update;\n if exists (\n select 1 from auth.users\n where id = v_uid\n and encrypted_password is distinct from extensions.crypt(v_pw, encrypted_password)\n ) then\n update auth.users\n set encrypted_password = extensions.crypt(v_pw, extensions.gen_salt(''bf'')),\n updated_at = now()\n where id = v_uid;\n delete from auth.sessions where user_id = v_uid;\n end if;\n end if;';
|
|
begin
|
|
select pg_get_functiondef('public._ensure_auth_user(text,text,text)'::regprocedure) into definition;
|
|
if strpos(definition, old_block) = 0 then
|
|
raise exception 'Unexpected _ensure_auth_user password update block';
|
|
end if;
|
|
execute replace(definition, old_block, new_block);
|
|
end;
|
|
$migration$;
|