Better upgrade logic for sqlite db - previously some entries were updated incorrectly