Implement merge-db function