[#62053520] Fixed plpgsql query to use CTE in the update and insert call. Fixed encoding that was breaking rails migrations. Tidy up quotas_copy_worker and sanitizing params