I needed to populate a local SQLite database to do some development testing for a client. Her web app has a lot of moving parts and left something to be desired in terms of testing. Most of these steps were adapted from this wonderful post.
Long story short: I needed to recreate an issue discovered in production, but didn’t have any data with which to write tests or even recreate the issue manually. The whole thing is a huge pain in the butt, so I dumped the production database from Heroku and attempted a brute-force reconstruction of the issue. The Heroku instructions produced a file called
I like using Docker for this kind of stuff. I don’t even run any databases on my host machine anymore.
From the Docker PostgreSQL documentation…
This is where the dumped data gets written to the Dockerized PostgreSQL database.
There are a couple of ways to find the database name. Either log in as follows, or go to the Heroku database dashboard. The password was set to secret when the container was created. It’s good idea to login anyway, if only to make sure the database is actually there.
I didn’t want to mess with the previous developer’s setup, so I took the wussy way out and used the existing SQLite configuration to run the app locally. This requires creating an SQLite DB with the PostgreSQL data dump. This command dumps that data:
Again, these steps were adapted from this post.
My favourite editor is
vim. I used it to modify
It’ll look something like this:
Get rid of it all.
The post that I’m plagiarizing says these autoincrement IDs. SQLite doesn’t need this. Find and remove everything that looks like this (i.e., everything with a call to
Anything that looks like this:
Needs to look like this:
If you don’t do this, the import will take forever. At the top of the file put
and at the very bottom of the file put
Finally, after all that hard work:
The app was already set up to work with the
development.sqlite database. There were a couple of error messages when creating it, but they didn’t seem to impact the app. Everything worked fine, and I found a nifty new way to use Docker.