Search code examples
postgresqlheroku

Copying a PostgreSQL table to GitHub


Using the Heroku CLI and following these instructions, I am trying to save the DB tables as CSVs.

I can see the tables on the CLI and when I use the copy command I see:

baer-faxt-prod::DATABASE-> \COPY artists TO 'artists_export.csv' WITH (FORMAT csv, DELIMITER ',',  HEADER true);
COPY 1010

It seems to have been successful, but I don't see it on GitHub.

I know very little about using this CLI and Heroku in general. Someone had set this up for us a while back and we need to move the DB.

If not GitHub, where does the file go?


Solution

  • This certainly won't end up on GitHub. Heroku's GitHub integration works in one direction only: from GitHub to Heroku. It is used for deployment, not for bidirectional syncing.

    The PostgreSQL \COPY command doesn't know anything about Git. When used in the format you show above:

    \COPY artists TO 'artists_export.csv' WITH (FORMAT csv, DELIMITER ',',  HEADER true);
    

    it saves to a file called artists_export.csv in whatever directory you are in on your local machine when you run the command.

    That might be something like C:\Users\Rebecca\ if you're on Windows, /Users/Rebecca/ if you're on macOS, /home/rebecca/ if you're on Linux. Or, it could be your project directory, for example if you did something like cd some/project/directory/ before connecting to your database.

    Disconnect from Postgres, e.g. by typing

    \quit
    

    and then look in whatever directory you're in for a file called artists_export.csv.