I’m not actually sure what raw_old is for at the moment, but you just need to use the raw field and it will replace the entire post. So, in your code you would fetch the post you want to edit, add your line to the top, then update the post using the raw field.
It might be helpful to see how Discourse does it by editing a post live on your site and inspecting the browser calls: