Search code examples
rubyruby-on-rails-3excelexport-to-excel

How to export table from heroku production database locally to excel from console using Ruby?


I know how to export table in Rails to formated Excel file: http://railscasts.com/episodes/362-exporting-csv-and-excel

But how to do that from console.


Solution

  • There's a couple of option here.

    Firstly, you could wrap up some ruby code into a rake task that creates the Excel spreadsheet and then spits it onto S3 for you to pick up later. This would be run via the CLI:

    heroku run rake export_data
    

    OR

    You could spin up a Postgres console heroku pg:psql and export your data to a CSV locally directly with a query such as those discussed here: http://ru05team.blogspot.co.uk/2011/03/export-postgresql-into-csv.html

    Note: pg:psql gives you a full interactive PSQL session with your production database as if it were local. Be careful when messing direct with a production database.