clearing rails app database on heroku production s

2019-03-08 08:07发布

So I'm new to ROR and Heroku and need a little help. I've created an app and have deployed it; however, I'd like to clear out the database associated with it. Meaning I'd like to clear any users (and their attached data) that have been created thus far.

I've basically created several phony accounts to test out whether the database on the production site works, but now i'd like to clear this out, and start with a fresh database.

Is this possible without deleting the database entirely?

Any help would be sincerely appreciated. Thank you very much for your time!

10条回答
Emotional °昔
2楼-- · 2019-03-08 08:39

To reset your database

run like bellow

heroku pg:reset SHARED_DATABASE --confirm APP_NAME

this works very well for my

查看更多
SAY GOODBYE
3楼-- · 2019-03-08 08:39

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!

查看更多
霸刀☆藐视天下
4楼-- · 2019-03-08 08:41

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.

查看更多
Root(大扎)
5楼-- · 2019-03-08 08:46

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

查看更多
闹够了就滚
6楼-- · 2019-03-08 08:48

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.

查看更多
forever°为你锁心
7楼-- · 2019-03-08 08:51

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.

查看更多
登录 后发表回答