clearing rails app database on heroku production site
Asked Answered
M

13

27

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!

Misreckon answered 2/8, 2011 at 2:38 Comment(0)
B
55

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.

Boner answered 2/8, 2011 at 4:5 Comment(2)
on the cedar stack, you can also run any command directly via heroku run, so: heroku run rake db:resetHame
This answer is out of date for 2013. Please see my answer below.Subclass
D
10
heroku pg:reset DATABASE --confirm {app-name}

heroku run rake db:migrate

heroku run rake db:seed
Duplicature answered 19/5, 2014 at 6:0 Comment(1)
Thank you this was helpful for me to get my DB reset and recreate easily.Superfetation
A
9

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.

Ashlieashlin answered 16/10, 2012 at 10:39 Comment(0)
S
7

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.

Subclass answered 14/6, 2013 at 16:23 Comment(0)
P
4

The current way is:

heroku pg:reset DATABASE_URL --confirm <APP_NAME>
Pontine answered 10/6, 2013 at 9:25 Comment(0)
K
2

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.

Kirchner answered 28/6, 2012 at 20:3 Comment(0)
P
2

To reset your database

run like bellow

heroku pg:reset SHARED_DATABASE --confirm APP_NAME

this works very well for my

Passant answered 4/7, 2012 at 20:23 Comment(0)
F
1

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.

Forbidden answered 2/8, 2011 at 3:27 Comment(2)
I'm curious... I'm currently on my mac (localhost). Am I correct in the following assumption: If I run rake db:reset (on my localhost/staging db), would it clear all the data without clearing the tables and schema? If so, would I then just push that database to heroku with the heroku db:push command? Would that work too?Misreckon
If you want to completely drop and recreate the db you could do: rake db:drop rake db:migrateForbidden
F
1

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!

Fulminous answered 25/3, 2014 at 15:34 Comment(0)
H
0

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

House answered 25/3, 2018 at 10:5 Comment(0)
R
0

Databases can be reset from the web dashboard as well:

Find your database and click on the link: enter image description here

On the database page click on "Settings" enter image description here

Then click on, "Reset Database" and follow the instructions to confirm. enter image description here

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

Replace answered 30/5, 2019 at 21:43 Comment(0)
C
0

To reset the database

It will ask you to confirm after you run this:

heroku pg:reset DATABASE_URL

To reset all in one line

I don't use this method just in case I make a mistake (I prefer the above method asking me to confirm). Replace myherokuapp with the name of your app:

heroku pg:reset DATABASE_URL --confirm myherokuapp

To reset and reseed

Like the previous, be careful as this will completely delete your current database and re seed it from seeds.rb. Replace myherokuapp with the name of your app in the following:

heroku pg:reset DATABASE_URL --confirm myherokuapp
heroku run rake db:migrate db:seed
Complexion answered 14/9, 2020 at 16:58 Comment(0)
B
0

Use this command in the project directory. Adding DISABLE_DATABASE_ENVIRONMENT_CHECK=1 allows the production environment to operate like a development environment.

heroku run db:reset DISABLE_DATABASE_ENVIRONMENT_CHECK=1
Benedetta answered 15/12, 2020 at 1:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.