Skip to content

Instantly share code, notes, and snippets.

@Mardiniii
Last active February 23, 2024 09:19
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Mardiniii/fa747a15356594279c5dc3cde1a4475d to your computer and use it in GitHub Desktop.
Save Mardiniii/fa747a15356594279c5dc3cde1a4475d to your computer and use it in GitHub Desktop.
Pull and push DATABASE with Heroku

# Some tips to pull and push a database with Heroku

Some tips to improve test flow dealing with database on local and production environments.

I. Pull database from Heroku

It is really usefull if you want to fill your local database with real data from production environment.

1. Drop Local Database

rake db:drop

2. Pull Database

General Command

heroku pg:pull DATABASE_URL local_database_name --app app_name

For QuincenaMe use the line below:

heroku pg:pull DATABASE_URL quincename_development --app quincename

Setup test database locally

rake db:test:prepare

HINT: If you want to setup some alias in the terminal, you can type the commands below:

$ alias get_production_database="heroku pg:pull DATABASE_URL quincename_development --app quincename; rake db:test:prepare"

Now you can run get_production_database in the terminal and magic will happen.

II. Push database to Heroku

I use this specially when I want to fill a temporary app within the pipeline in order to test feature or fixes with real data.

1. Reset Database

heroku pg:reset DATABASE_URL --app pipeline_app_name

2. Push Database

You must to consider if you want to push a database to a heroku application you will need the database locally and reset the database in the production environment:

heroku pg:push database_name DATABASE_URL --app pipeline_app_name

I build the post based on this Heroku documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment