Fix bugs in database bootstrap