fix: keep one active email OTP per account
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
lock table identity.verifications in share row exclusive mode;
|
||||
|
||||
with ranked as (
|
||||
select
|
||||
id,
|
||||
row_number() over (
|
||||
partition by identifier
|
||||
order by created_at desc, id desc
|
||||
) as position
|
||||
from identity.verifications
|
||||
)
|
||||
delete from identity.verifications verification
|
||||
using ranked
|
||||
where verification.id = ranked.id
|
||||
and ranked.position > 1;
|
||||
|
||||
create unique index if not exists identity_verifications_identifier_key
|
||||
on identity.verifications (identifier);
|
||||
Reference in New Issue
Block a user