Expanded the logic a bit in the upgradeDatabase function