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