How to drop a single Postgres table in a Ruby on Rails Heroku app?

sergserg picture sergserg · Jan 2, 2013 · Viewed 10.7k times · Source

Similar question here, but none of the answers actually answer the question. The accepted answer just shows how to log in to console and destroy all records. This is not what I need in this case.

I need to completely scrap a single table (it has no associations) and recreate it with an existing migration.

Is there something like?

heroku pg:destroy_table "Products"

I would then run my migration again and it would create the table with the new schema:

heroku run rake db:migrate

Answer

Yves Senn picture Yves Senn · Jan 2, 2013

You could try to use heroku pg:psql. This should open a console to your database where you can execute arbitrary SQL:

DROP TABLE products;

You can find more about pg:psql in the heroku docs: https://devcenter.heroku.com/articles/heroku-postgresql#pgpsql

PostgreSQL docs for the same: http://www.postgresql.org/docs/9.1/static/sql-droptable.html