Getting out of Heroku and Migrating a Django project from PostgreSQL to MySQL Pt. 1

June 9, 2015

While examining our hosting costs, I discovered that we were hosting one customer on Heroku and it cost us a lot of money. The customer we were hosting was a medium-sized CMS site and we had a (relatively) twelve-factor compatible internal hosting environment that the site could be deployed to. You can read about twelve-factor here.

It turned out that the site would be easy to migrate to our production cluster, except for one small thing - our default database is MySQL and this expensive to host CMS site was running in PostgreSQL.

I now had the unenviable task of migrating a site from PostgreSQL to MySQL. It turns out that there were plenty of tutorials for going the other direction (from MySQL to the much more capable PostgreSQL), but none that were specific to getting a site away from Heroku.

This blog post provided an excellent framework and starting point, though the specifics of my task were a bit more complicated.

The Migration

To actually migrate our customer's whole site, we had to get a copy of their postgres database, load the database locally, export all the fixtures as JSON, reload all the fixtures locally into a MySQL database, export the MySQL database, and finally re-import the MySQL compatible dump into our production cluster.

It would be concievable to spin up a PostgreSQL database in production, but our goal was to reduce hosting costs so it was better to use the infrastructure we had rather than to add even more boxes and arrows to the chart.