clearing rails app database on heroku production site

有些话、适合烂在心里 提交于 2019-12-02 16:56:33

You can use heroku pg:reset DATABASE command to reset the entire database. The command will simply drop and create the database.

You have to use heroku rake db:migrate to create the tables then.

Alternatively you can use rake db:reset command locally and then run heroku db:push to update the production db.

Jigar Bhatt
heroku pg:reset DATABASE --confirm {app-name}

heroku run rake db:migrate

heroku run rake db:seed
Taimoor Changaiz

Login on Heroku through terminal and then run one of following commands:

heroku rake db:reset
//or:    
heroku run rake db:reset

The first one is an old one and the second is latest.

The 2013 way to do this is:

Enter heroku pg:reset DATABASE in your console and then enter in your app name when prompted. This will drop the entire database -- tables, rows, columns, all of its data, everything.

Then, enter heroku run rake db:migrate. This will create the same table, rows, and columns, but without any object data.

The current way is:

heroku pg:reset DATABASE_URL --confirm <APP_NAME>

The current Cedar stack's proper syntax for shared databases is:

heroku pg:reset SHARED_DATABASE my-database-name-1294

(Replace "my-database-name-1294" with whatever is before the .herokuapp.com in your URL)

It'll then ask you this:

----> Resetting SHARED_DATABASE (DATABASE_URL)

 !    WARNING: Potentially Destructive Action
 !    This command will affect the app: my-database-name-1294
 !    To proceed, type "my-database-name-1294" or re-run this command with --confirm my-database-name-1294

Just retype "my-database-name-1294" there and it'll reset everything.

To reset your database

run like bellow

heroku pg:reset SHARED_DATABASE --confirm APP_NAME

this works very well for my

Yes, you can either use SQL methods to do it or perhaps just use the Rails Console to do it from the command line and call the @users.destroy_all method. This article explains how to use the console from Heroku.

If you have two servers - production and staging, and you want to add the database from production to staging

heroku pg:reset DATABASE --remote staging
heroku pgbackups:restore DATABASE URL_OF_DATABASE --remote staging
heroku run rake db:migrate --remote staging

URL_TO_DATABASE - an aws or dropbox url for the dump.

This worked for me!

Heroku provides a visual tool to do this. Go to Resources > Heroku Postgres :: Database Drop database manualy

If you want to migrate your tables use rake db:migrate To launch your seeds rake db:seed

Databases can be reset from the web dashboard as well:

Find your database and click on the link:

On the database page click on "Settings"

Then click on, "Reset Database" and follow the instructions to confirm.

You'll of course need to use rake to migrate to get your tables back.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!