Skip to content

Export Import DB for Testing

Kevin Pannell edited this page Feb 14, 2019 · 3 revisions

1. Spool up Postgres

There is many ways to do this. For this document we will use a GUI.

Mac

Download Postgres.app

Startup Postgres.app and boom you now have a postgresQL server running with these values:

Host	localhost
Port	5432
User	your system user name
Database	same as user
Password	none
Connection URL	postgresql://localhost

Windows

This guide looks decent, haven' tested.

Install Postgresql

2. Grab Latest Dump

Download heroku-cli here

Once installed login by running

heroku login

Grab the latest backup. (Note: this will create a latest.dump file in your current working directory):

heroku pg:backups:capture
heroku pg:backups:download --app grepthink

3. Restore dump into your running Postgres db

The following command assumes you're in the same working directory as latest.dump: (Note: replace 'myuser' with your local user, and 'mydb' with your postgres database name.

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump

If successful you should see messages regarding each table being restored.

4. Edit .env

Add the following to your .env file:

USE_POSTGRES_LOCAL=True
POSTGRES_DATABASE_URL=postgres://username:password@localhost/mydb

Thats it, you should be good to go. If you want to return to sqlite3 just toggle USE_LOCAL_POSTGRES to False.