Files
Jyotisha/frontend/db/migrations/20260810024500_unique_verification_identifiers.sql
T
Jesse_Chen 8696eca022
Staging Backend Quality Gate / validate (push) Successful in 12m39s
Staging Backend Quality Gate / publish (push) Successful in 12m9s
fix: keep one active email OTP per account
2026-08-10 10:49:25 +08:00

19 lines
479 B
SQL

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);