fix bugs associated with mysql migration to postgres