Make sure versions are dumped in order

There is not any guarantees that versions comes in the same order they
are inserted without ordering them explicitely.