Switch from db unique constraint to custom logic